enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[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 RouteProcessorSelection::RouteProcessorSelection()
36         : _no_route_change_signal (false)
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         for (AxisViewSelection::iterator i = axes.begin(); i != axes.end(); ++i) {
75                 (*i)->set_selected (false);
76         }
77         axes.clear ();
78         drop_connections ();
79         if (!_no_route_change_signal) {
80                 RoutesChanged ();
81         }
82 }
83
84 void
85 RouteProcessorSelection::add (XMLNode* node)
86 {
87         // XXX check for duplicate
88         processors.add (node);
89         ProcessorsChanged();
90 }
91
92 void
93 RouteProcessorSelection::set (XMLNode* node)
94 {
95         clear_processors ();
96         processors.set (node);
97         ProcessorsChanged ();
98 }
99
100 void
101 RouteProcessorSelection::add (AxisView* r)
102 {
103         if (axes.insert (r).second) {
104
105                 r->set_selected (true);
106
107                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
108
109                 if (ms) {
110                         ms->CatchDeletion.connect (*this, invalidator (*this), boost::bind (&RouteProcessorSelection::remove, this, _1), gui_context());
111                 }
112
113                 if (!_no_route_change_signal) {
114                         RoutesChanged();
115                 }
116         }
117 }
118
119 void
120 RouteProcessorSelection::remove (AxisView* r)
121 {
122         ENSURE_GUI_THREAD (*this, &RouteProcessorSelection::remove, r);
123
124         AxisViewSelection::iterator i;
125         if ((i = find (axes.begin(), axes.end(), r)) != axes.end()) {
126                 (*i)->set_selected (false);
127                 axes.erase (i);
128                 if (!_no_route_change_signal) {
129                         RoutesChanged ();
130                 }
131         }
132 }
133
134 void
135 RouteProcessorSelection::set (AxisView* r)
136 {
137         clear_routes ();
138         add (r);
139 }
140
141 bool
142 RouteProcessorSelection::selected (AxisView* r)
143 {
144         return find (axes.begin(), axes.end(), r) != axes.end();
145 }
146
147 bool
148 RouteProcessorSelection::empty ()
149 {
150         return processors.empty () && axes.empty ();
151 }
152
153 void
154 RouteProcessorSelection::block_routes_changed (bool yn)
155 {
156         _no_route_change_signal = yn;
157 }