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