drastic overhaul of keyboard handling in mixer window. real bindings, key events...
[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 RouteRedirectSelection&
40 RouteRedirectSelection::operator= (const RouteRedirectSelection& other)
41 {
42         if (&other != this) {
43                 processors = other.processors;
44                 routes = other.routes;
45         }
46         return *this;
47 }
48
49 bool
50 operator== (const RouteRedirectSelection& a, const RouteRedirectSelection& b)
51 {
52         // XXX MUST TEST PROCESSORS SOMEHOW
53         return a.routes == b.routes;
54 }
55
56 void
57 RouteRedirectSelection::clear ()
58 {
59         clear_processors ();
60         clear_routes ();
61 }
62
63 void
64 RouteRedirectSelection::clear_processors ()
65 {
66         processors.clear ();
67         ProcessorsChanged ();
68 }
69
70 void
71 RouteRedirectSelection::clear_routes ()
72 {
73         for (RouteUISelection::iterator i = routes.begin(); i != routes.end(); ++i) {
74                 (*i)->set_selected (false);
75         }
76         routes.clear ();
77         drop_connections ();
78         RoutesChanged ();
79 }
80
81 void
82 RouteRedirectSelection::add (XMLNode* node)
83 {
84         // XXX check for duplicate
85         processors.add (node);
86         ProcessorsChanged();
87 }
88
89 void
90 RouteRedirectSelection::set (XMLNode* node)
91 {
92         clear_processors ();
93         processors.set (node);
94         ProcessorsChanged ();
95 }
96
97 void
98 RouteRedirectSelection::add (RouteUI* r)
99 {
100         if (find (routes.begin(), routes.end(), r) == routes.end()) {
101                 if (routes.insert (r).second) {
102                         r->set_selected (true);
103
104                         MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
105                         
106                         if (ms) {
107                                 ms->CatchDeletion.connect (*this, invalidator (*this), ui_bind (&RouteRedirectSelection::remove, this, _1), gui_context());
108                         }
109
110                         RoutesChanged();
111                 }
112         }
113 }
114
115 void
116 RouteRedirectSelection::remove (RouteUI* r)
117 {
118         ENSURE_GUI_THREAD (*this, &RouteRedirectSelection::remove, r);
119
120         RouteUISelection::iterator i;
121         if ((i = find (routes.begin(), routes.end(), r)) != routes.end()) {
122                 routes.erase (i);
123                 (*i)->set_selected (false);
124                 RoutesChanged ();
125         }
126 }
127
128 void
129 RouteRedirectSelection::set (RouteUI* r)
130 {
131         clear_routes ();
132         add (r);
133 }
134
135 bool
136 RouteRedirectSelection::selected (RouteUI* r)
137 {
138         return find (routes.begin(), routes.end(), r) != routes.end();
139 }
140
141 bool
142 RouteRedirectSelection::empty ()
143 {
144         return processors.empty () && routes.empty ();
145 }
146