when a Route is removed, don't bother triggering a sync-presentation-info-from-treevi...
[ardour.git] / gtk2_ardour / route_processor_selection.cc
1 /*
2     Copyright (C) 2002 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <algorithm>
21 #include <sigc++/bind.h>
22
23 #include "pbd/error.h"
24 #include "pbd/i18n.h"
25
26 #include "ardour/selection.h"
27 #include "ardour/session.h"
28 #include "ardour/session_handle.h"
29
30 #include "axis_provider.h"
31 #include "gui_thread.h"
32 #include "mixer_strip.h"
33 #include "mixer_ui.h"
34 #include "route_processor_selection.h"
35 #include "route_ui.h"
36
37 using namespace std;
38 using namespace ARDOUR;
39 using namespace PBD;
40
41 RouteProcessorSelection::RouteProcessorSelection (SessionHandlePtr& s, AxisViewProvider& ap)
42         : shp (s), avp (ap)
43 {
44 }
45
46 RouteProcessorSelection&
47 RouteProcessorSelection::operator= (const RouteProcessorSelection& other)
48 {
49         if (&other != this) {
50                 (*((ProcessorSelection*) this)) = (*((ProcessorSelection const *) &other));
51                 axes = other.axes;
52         }
53         return *this;
54 }
55
56 bool
57 operator== (const RouteProcessorSelection& a, const RouteProcessorSelection& b)
58 {
59         // XXX MUST TEST PROCESSORS SOMEHOW
60         return a.axes == b.axes;
61 }
62
63 void
64 RouteProcessorSelection::clear ()
65 {
66         clear_processors ();
67         clear_routes ();
68 }
69
70 void
71 RouteProcessorSelection::clear_routes ()
72 {
73         if (shp.session()) {
74                 PresentationInfo::ChangeSuspender cs;
75                 shp.session()->selection().clear_stripables ();
76         }
77 }
78
79 void
80 RouteProcessorSelection::presentation_info_changed (PropertyChange const & what_changed)
81 {
82         Session* s = shp.session();
83
84         if (!s) {
85                 /* too early ... session handle provider doesn't know about the
86                    session yet.
87                 */
88                 return;
89         }
90
91         PropertyChange pc;
92         pc.add (Properties::selected);
93
94         CoreSelection::StripableAutomationControls sc;
95         s->selection().get_stripables (sc);
96
97         for (AxisViewSelection::iterator a = axes.begin(); a != axes.end(); ++a) {
98                 (*a)->set_selected (false);
99         }
100
101         axes.clear ();
102
103         for (CoreSelection::StripableAutomationControls::const_iterator i = sc.begin(); i != sc.end(); ++i) {
104                 AxisView* av = avp.axis_view_by_stripable ((*i).stripable);
105                 if (av) {
106                         axes.insert (av);
107                         av->set_selected (true);
108                 }
109         }
110 }
111
112 void
113 RouteProcessorSelection::add (AxisView* r)
114 {
115         if (!shp.session()) {
116                 return;
117         }
118
119         if (axes.insert (r).second) {
120
121                 shp.session()->selection().add (r->stripable(), boost::shared_ptr<AutomationControl>());
122
123                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
124
125                 if (ms) {
126                         ms->CatchDeletion.connect (*this, invalidator (*this), boost::bind (&RouteProcessorSelection::remove, this, _1), gui_context());
127                 }
128         }
129 }
130
131 void
132 RouteProcessorSelection::remove (AxisView* r)
133 {
134         if (!shp.session()) {
135                 return;
136         }
137         ENSURE_GUI_THREAD (*this, &RouteProcessorSelection::remove, r);
138         shp.session()->selection().remove (r->stripable(), boost::shared_ptr<AutomationControl>());
139 }
140
141 void
142 RouteProcessorSelection::set (AxisView* r)
143 {
144         if (!shp.session()) {
145                 return;
146         }
147         shp.session()->selection().set (r->stripable(), boost::shared_ptr<AutomationControl>());
148 }
149
150 bool
151 RouteProcessorSelection::selected (AxisView* r)
152 {
153         return find (axes.begin(), axes.end(), r) != axes.end();
154 }
155
156 bool
157 RouteProcessorSelection::empty ()
158 {
159         return processors.empty () && axes.empty ();
160 }