Remove over 500 unnecessary includes (including 54 of session.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 "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                 routes = other.routes;
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.routes == b.routes;
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 (RouteUISelection::iterator i = routes.begin(); i != routes.end(); ++i) {
75                 (*i)->set_selected (false);
76         }
77         routes.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 (RouteUI* r)
102 {
103         if (find (routes.begin(), routes.end(), r) == routes.end()) {
104                 if (routes.insert (r).second) {
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
120 void
121 RouteProcessorSelection::remove (RouteUI* r)
122 {
123         ENSURE_GUI_THREAD (*this, &RouteProcessorSelection::remove, r);
124
125         RouteUISelection::iterator i;
126         if ((i = find (routes.begin(), routes.end(), r)) != routes.end()) {
127                 routes.erase (i);
128                 (*i)->set_selected (false);
129                 if (!_no_route_change_signal) {
130                         RoutesChanged ();
131                 }
132         }
133 }
134
135 void
136 RouteProcessorSelection::set (RouteUI* r)
137 {
138         clear_routes ();
139         add (r);
140 }
141
142 bool
143 RouteProcessorSelection::selected (RouteUI* r)
144 {
145         return find (routes.begin(), routes.end(), r) != routes.end();
146 }
147
148 bool
149 RouteProcessorSelection::empty ()
150 {
151         return processors.empty () && routes.empty ();
152 }
153
154 void
155 RouteProcessorSelection::block_routes_changed (bool yn)
156 {
157         _no_route_change_signal = yn;
158 }