Split pretty much the entire GUI in 3. Audio and Midi "editor strips" and
[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         for (RedirectSelection::iterator i = redirects.begin(); i != redirects.end(); ) {
65                 RedirectSelection::iterator tmp;
66
67                 tmp = i;
68                 ++tmp;
69
70                 delete *i;
71
72                 i = tmp;
73         }
74
75         redirects.clear ();
76         RedirectsChanged ();
77 }
78
79 void
80 RouteRedirectSelection::clear_routes ()
81 {
82         routes.clear ();
83         RoutesChanged ();
84 }
85
86 void
87 RouteRedirectSelection::add (Redirect* r)
88 {
89         if (find (redirects.begin(), redirects.end(), r) == redirects.end()) {
90                 redirects.push_back (r);
91                 
92                 void (RouteRedirectSelection::*pmf)(Redirect*) = &RouteRedirectSelection::remove;
93                 r->GoingAway.connect (mem_fun(*this, pmf));
94
95                 RedirectsChanged();
96         }
97 }
98
99 void
100 RouteRedirectSelection::add (const vector<Redirect*>& rlist)
101 {
102         bool changed = false;
103
104         for (vector<Redirect*>::const_iterator i = rlist.begin(); i != rlist.end(); ++i) {
105                 if (find (redirects.begin(), redirects.end(), *i) == redirects.end()) {
106                         redirects.push_back (*i);
107                         
108                         void (RouteRedirectSelection::*pmf)(Redirect*) = &RouteRedirectSelection::remove;
109                         (*i)->GoingAway.connect (mem_fun(*this, pmf));
110                         changed = true;
111                 }
112         }
113
114         if (changed) {
115                 RedirectsChanged();
116         }
117 }
118
119 void
120 RouteRedirectSelection::remove (Redirect* r)
121 {
122         list<Redirect*>::iterator i;
123         if ((i = find (redirects.begin(), redirects.end(), r)) != redirects.end()) {
124                 redirects.erase (i);
125                 RedirectsChanged ();
126         }
127 }
128
129 void
130 RouteRedirectSelection::set (Redirect *r)
131 {
132         clear_redirects ();
133         add (r);
134 }
135
136 void
137 RouteRedirectSelection::set (const vector<Redirect*>& rlist)
138 {
139         clear_redirects ();
140         add (rlist);
141 }
142
143 void
144 RouteRedirectSelection::add (Route* r)
145 {
146         if (find (routes.begin(), routes.end(), r) == routes.end()) {
147                 routes.push_back (r);
148
149                 void (RouteRedirectSelection::*pmf)(Route*) = &RouteRedirectSelection::remove;
150                 r->GoingAway.connect (bind (mem_fun(*this, pmf), r));
151
152                 RoutesChanged();
153         }
154 }
155
156 void
157 RouteRedirectSelection::remove (Route* r)
158 {
159         list<Route*>::iterator i;
160         if ((i = find (routes.begin(), routes.end(), r)) != routes.end()) {
161                 routes.erase (i);
162                 RoutesChanged ();
163         }
164 }
165
166 void
167 RouteRedirectSelection::set (Route *r)
168 {
169         clear_routes ();
170         add (r);
171 }
172
173 bool
174 RouteRedirectSelection::selected (Route* ms)
175 {
176         return find (routes.begin(), routes.end(), ms) != routes.end();
177 }
178
179 bool
180 RouteRedirectSelection::empty ()
181 {
182         return redirects.empty () && routes.empty ();
183 }
184