fix crash caused by thinko in 123fcf3cf
[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 #include "pbd/error.h"
23
24 #include "gui_thread.h"
25 #include "mixer_strip.h"
26 #include "route_processor_selection.h"
27 #include "route_ui.h"
28
29 #include "pbd/i18n.h"
30
31 using namespace std;
32 using namespace ARDOUR;
33 using namespace PBD;
34
35
36 RouteProcessorSelection::RouteProcessorSelection()
37 {
38 }
39
40 RouteProcessorSelection&
41 RouteProcessorSelection::operator= (const RouteProcessorSelection& other)
42 {
43         if (&other != this) {
44                 processors = other.processors;
45                 axes = other.axes;
46         }
47         return *this;
48 }
49
50 bool
51 operator== (const RouteProcessorSelection& a, const RouteProcessorSelection& b)
52 {
53         // XXX MUST TEST PROCESSORS SOMEHOW
54         return a.axes == b.axes;
55 }
56
57 void
58 RouteProcessorSelection::clear ()
59 {
60         clear_processors ();
61         clear_routes ();
62 }
63
64 void
65 RouteProcessorSelection::clear_processors ()
66 {
67         processors.clear ();
68         ProcessorsChanged ();
69 }
70
71 void
72 RouteProcessorSelection::clear_routes ()
73 {
74         PresentationInfo::ChangeSuspender cs;
75
76         for (AxisViewSelection::iterator i = axes.begin(); i != axes.end(); ++i) {
77                 (*i)->set_selected (false);
78         }
79         axes.clear ();
80         drop_connections ();
81 }
82
83 void
84 RouteProcessorSelection::add (XMLNode* node)
85 {
86         // XXX check for duplicate
87         processors.add (node);
88         ProcessorsChanged();
89 }
90
91 void
92 RouteProcessorSelection::set (XMLNode* node)
93 {
94         clear_processors ();
95         processors.set (node);
96         ProcessorsChanged ();
97 }
98
99 void
100 RouteProcessorSelection::add (AxisView* r)
101 {
102         if (axes.insert (r).second) {
103
104                 r->set_selected (true);
105
106                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
107
108                 if (ms) {
109                         ms->CatchDeletion.connect (*this, invalidator (*this), boost::bind (&RouteProcessorSelection::remove, this, _1), gui_context());
110                 }
111         }
112 }
113
114 void
115 RouteProcessorSelection::remove (AxisView* r)
116 {
117         ENSURE_GUI_THREAD (*this, &RouteProcessorSelection::remove, r);
118         PresentationInfo::ChangeSuspender cs;
119
120         AxisViewSelection::iterator i;
121         if ((i = find (axes.begin(), axes.end(), r)) != axes.end()) {
122                 AxisView* av = *i;
123                 axes.erase (i);
124                 av->set_selected (false);
125         }
126 }
127
128 void
129 RouteProcessorSelection::set (AxisView* r)
130 {
131         PresentationInfo::ChangeSuspender cs;
132         clear_routes ();
133         add (r);
134 }
135
136 bool
137 RouteProcessorSelection::selected (AxisView* r)
138 {
139         return find (axes.begin(), axes.end(), r) != axes.end();
140 }
141
142 bool
143 RouteProcessorSelection::empty ()
144 {
145         return processors.empty () && axes.empty ();
146 }