Renamed Insert to Processor and Redirect to IOProcessor.
[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
30 #include "i18n.h"
31
32 using namespace ARDOUR;
33 using namespace PBD;
34 using namespace sigc;
35
36 RouteRedirectSelection&
37 RouteRedirectSelection::operator= (const RouteRedirectSelection& other)
38 {
39         if (&other != this) {
40                 processors = other.processors;
41                 routes = other.routes;
42         }
43         return *this;
44 }
45
46 bool
47 operator== (const RouteRedirectSelection& a, const RouteRedirectSelection& b)
48 {
49         return a.processors == b.processors &&
50                 a.routes == b.routes;
51 }
52
53 void
54 RouteRedirectSelection::clear ()
55 {
56         clear_processors ();
57         clear_routes ();
58 }
59
60 void
61 RouteRedirectSelection::clear_processors ()
62 {
63         processors.clear ();
64         ProcessorsChanged ();
65 }
66
67 void
68 RouteRedirectSelection::clear_routes ()
69 {
70         routes.clear ();
71         RoutesChanged ();
72 }
73
74 void
75 RouteRedirectSelection::add (boost::shared_ptr<Processor> r)
76 {
77         if (find (processors.begin(), processors.end(), r) == processors.end()) {
78                 processors.push_back (r);
79
80                 // XXX SHAREDPTR FIXME
81                 // void (RouteRedirectSelection::*pmf)(Redirect*) = &RouteRedirectSelection::remove;
82                 // r->GoingAway.connect (mem_fun(*this, pmf));
83
84                 ProcessorsChanged();
85         }
86 }
87
88 void
89 RouteRedirectSelection::add (const vector<boost::shared_ptr<Processor> >& rlist)
90 {
91         bool changed = false;
92
93         for (vector<boost::shared_ptr<Processor> >::const_iterator i = rlist.begin(); i != rlist.end(); ++i) {
94                 if (find (processors.begin(), processors.end(), *i) == processors.end()) {
95                         processors.push_back (*i);
96                         
97                         // XXX SHAREDPTR FIXME
98
99                         //void (RouteRedirectSelection::*pmf)(Redirect*) = &RouteRedirectSelection::remove;
100                         // (*i)->GoingAway.connect (mem_fun(*this, pmf));
101                         changed = true;
102                 }
103         }
104
105         if (changed) {
106                 ProcessorsChanged();
107         }
108 }
109
110 void
111 RouteRedirectSelection::remove (boost::shared_ptr<Processor> r)
112 {
113         list<boost::shared_ptr<Processor> >::iterator i;
114         if ((i = find (processors.begin(), processors.end(), r)) != processors.end()) {
115                 processors.erase (i);
116                 ProcessorsChanged ();
117         }
118 }
119
120 void
121 RouteRedirectSelection::set (boost::shared_ptr<Processor> r)
122 {
123         clear_processors ();
124         add (r);
125 }
126
127 void
128 RouteRedirectSelection::set (const vector<boost::shared_ptr<Processor> >& rlist)
129 {
130         clear_processors ();
131         add (rlist);
132 }
133
134 void
135 RouteRedirectSelection::add (boost::shared_ptr<Route> r)
136 {
137         if (find (routes.begin(), routes.end(), r) == routes.end()) {
138                 routes.push_back (r);
139
140                 // XXX SHAREDPTR FIXME
141                 // void (RouteRedirectSelection::*pmf)(Route*) = &RouteRedirectSelection::remove;
142                 // r->GoingAway.connect (bind (mem_fun(*this, pmf), r));
143
144                 RoutesChanged();
145         }
146 }
147
148 void
149 RouteRedirectSelection::remove (boost::shared_ptr<Route> r)
150 {
151         list<boost::shared_ptr<Route> >::iterator i;
152         if ((i = find (routes.begin(), routes.end(), r)) != routes.end()) {
153                 routes.erase (i);
154                 RoutesChanged ();
155         }
156 }
157
158 void
159 RouteRedirectSelection::set (boost::shared_ptr<Route> r)
160 {
161         clear_routes ();
162         add (r);
163 }
164
165 bool
166 RouteRedirectSelection::selected (boost::shared_ptr<Route> r)
167 {
168         return find (routes.begin(), routes.end(), r) != routes.end();
169 }
170
171 bool
172 RouteRedirectSelection::empty ()
173 {
174         return processors.empty () && routes.empty ();
175 }
176