switch to using boost::signals2 instead of sigc++, at least for libardour. not finish...
[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 "route_processor_selection.h"
29 #include "gui_thread.h"
30
31 #include "i18n.h"
32
33 using namespace std;
34 using namespace ARDOUR;
35 using namespace PBD;
36
37 RouteRedirectSelection&
38 RouteRedirectSelection::operator= (const RouteRedirectSelection& other)
39 {
40         if (&other != this) {
41                 processors = other.processors;
42                 routes = other.routes;
43         }
44         return *this;
45 }
46
47 bool
48 operator== (const RouteRedirectSelection& a, const RouteRedirectSelection& b)
49 {
50         // XXX MUST TEST PROCESSORS SOMEHOW
51         return a.routes == b.routes;
52 }
53
54 void
55 RouteRedirectSelection::clear ()
56 {
57         clear_processors ();
58         clear_routes ();
59 }
60
61 void
62 RouteRedirectSelection::clear_processors ()
63 {
64         processors.clear ();
65         ProcessorsChanged ();
66 }
67
68 void
69 RouteRedirectSelection::clear_routes ()
70 {
71         routes.clear ();
72         RoutesChanged ();
73 }
74
75 void
76 RouteRedirectSelection::add (XMLNode* node)
77 {
78         // XXX check for duplicate
79         processors.add (node);
80         ProcessorsChanged();
81 }
82
83 void
84 RouteRedirectSelection::set (XMLNode* node)
85 {
86         clear_processors ();
87         processors.set (node);
88         ProcessorsChanged ();
89 }
90
91 void
92 RouteRedirectSelection::add (boost::shared_ptr<Route> r)
93 {
94         if (find (routes.begin(), routes.end(), r) == routes.end()) {
95                 routes.push_back (r);
96                 r->GoingAway.connect (boost::bind (&RouteRedirectSelection::removed, this, boost::weak_ptr<Route>(r)));
97                 RoutesChanged();
98         }
99 }
100
101 void
102 RouteRedirectSelection::removed (boost::weak_ptr<Route> wr)
103 {
104         boost::shared_ptr<Route> r (wr.lock());
105
106         if (!r) {
107                 return;
108         }
109
110         remove (r);
111 }
112
113 void
114 RouteRedirectSelection::remove (boost::shared_ptr<Route> r)
115 {
116         ENSURE_GUI_THREAD (*this, &RouteRedirectSelection::remove, r);
117
118         list<boost::shared_ptr<Route> >::iterator i;
119         if ((i = find (routes.begin(), routes.end(), r)) != routes.end()) {
120                 routes.erase (i);
121                 RoutesChanged ();
122         }
123 }
124
125 void
126 RouteRedirectSelection::set (boost::shared_ptr<Route> r)
127 {
128         clear_routes ();
129         add (r);
130 }
131
132 bool
133 RouteRedirectSelection::selected (boost::shared_ptr<Route> r)
134 {
135         return find (routes.begin(), routes.end(), r) != routes.end();
136 }
137
138 bool
139 RouteRedirectSelection::empty ()
140 {
141         return processors.empty () && routes.empty ();
142 }
143