correct length for BBT "off" clock state; use bold font for nudge clock
[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 "ardour/playlist.h"
25 #include "ardour/processor.h"
26 #include "ardour/route.h"
27
28 #include "gui_thread.h"
29 #include "mixer_strip.h"
30 #include "route_processor_selection.h"
31 #include "route_ui.h"
32
33 #include "i18n.h"
34
35 using namespace std;
36 using namespace ARDOUR;
37 using namespace PBD;
38
39 RouteProcessorSelection::RouteProcessorSelection()
40         : _no_route_change_signal (false)
41 {
42 }
43
44 RouteProcessorSelection&
45 RouteProcessorSelection::operator= (const RouteProcessorSelection& other)
46 {
47         if (&other != this) {
48                 processors = other.processors;
49                 routes = other.routes;
50         }
51         return *this;
52 }
53
54 bool
55 operator== (const RouteProcessorSelection& a, const RouteProcessorSelection& b)
56 {
57         // XXX MUST TEST PROCESSORS SOMEHOW
58         return a.routes == b.routes;
59 }
60
61 void
62 RouteProcessorSelection::clear ()
63 {
64         clear_processors ();
65         clear_routes ();
66 }
67
68 void
69 RouteProcessorSelection::clear_processors ()
70 {
71         processors.clear ();
72         ProcessorsChanged ();
73 }
74
75 void
76 RouteProcessorSelection::clear_routes ()
77 {
78         for (RouteUISelection::iterator i = routes.begin(); i != routes.end(); ++i) {
79                 (*i)->set_selected (false);
80         }
81         routes.clear ();
82         drop_connections ();
83         if (!_no_route_change_signal) {
84                 RoutesChanged ();
85         }
86 }
87
88 void
89 RouteProcessorSelection::add (XMLNode* node)
90 {
91         // XXX check for duplicate
92         processors.add (node);
93         ProcessorsChanged();
94 }
95
96 void
97 RouteProcessorSelection::set (XMLNode* node)
98 {
99         clear_processors ();
100         processors.set (node);
101         ProcessorsChanged ();
102 }
103
104 void
105 RouteProcessorSelection::add (RouteUI* r)
106 {
107         if (find (routes.begin(), routes.end(), r) == routes.end()) {
108                 if (routes.insert (r).second) {
109                         r->set_selected (true);
110
111                         MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
112                         
113                         if (ms) {
114                                 ms->CatchDeletion.connect (*this, invalidator (*this), ui_bind (&RouteProcessorSelection::remove, this, _1), gui_context());
115                         }
116                         
117                         if (!_no_route_change_signal) {
118                                 RoutesChanged();
119                         }
120                 }
121         }
122 }
123
124 void
125 RouteProcessorSelection::remove (RouteUI* r)
126 {
127         ENSURE_GUI_THREAD (*this, &RouteProcessorSelection::remove, r);
128
129         RouteUISelection::iterator i;
130         if ((i = find (routes.begin(), routes.end(), r)) != routes.end()) {
131                 routes.erase (i);
132                 (*i)->set_selected (false);
133                 if (!_no_route_change_signal) {
134                         RoutesChanged ();
135                 }
136         }
137 }
138
139 void
140 RouteProcessorSelection::set (RouteUI* r)
141 {
142         clear_routes ();
143         add (r);
144 }
145
146 bool
147 RouteProcessorSelection::selected (RouteUI* r)
148 {
149         return find (routes.begin(), routes.end(), r) != routes.end();
150 }
151
152 bool
153 RouteProcessorSelection::empty ()
154 {
155         return processors.empty () && routes.empty ();
156 }
157
158 void
159 RouteProcessorSelection::block_routes_changed (bool yn)
160 {
161         _no_route_change_signal = yn;
162 }