ff452137d9a8193b32c919af2e3c948875948d3b
[ardour.git] / libs / ardour / session_rtevents.cc
1 /*
2     Copyright (C) 1999-2009 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 #include <boost/bind.hpp>
20
21 #include "pbd/error.h"
22 #include "pbd/compose.h"
23
24 #include "ardour/session.h"
25 #include "ardour/route.h"
26 #include "ardour/track.h"
27
28 #include "i18n.h"
29
30 using namespace std;
31 using namespace PBD;
32 using namespace ARDOUR;
33 using namespace Glib;
34
35 SessionEvent*
36 Session::get_rt_event (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override,  
37                        void (Session::*method) (boost::shared_ptr<RouteList>, bool, bool))
38 {
39         SessionEvent* ev = new SessionEvent (SessionEvent::RealTimeOperation, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0);
40         ev->rt_slot = boost::bind (method, this, rl, yn, group_override);
41         ev->rt_return = after;
42         ev->event_loop = EventLoop::get_event_loop_for_thread ();
43
44         return ev;
45 }
46
47 void
48 Session::set_solo (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
49 {
50         queue_event (get_rt_event (rl, yn, after, group_override, &Session::rt_set_solo));
51 }
52
53 void
54 Session::rt_set_solo (boost::shared_ptr<RouteList> rl, bool yn, bool /* group_override */)
55 {
56         for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
57                 if (!(*i)->is_hidden()) {
58                         (*i)->set_solo (yn, this);
59                 }
60         }
61
62         set_dirty();
63 }
64
65 void
66 Session::set_just_one_solo (boost::shared_ptr<Route> r, bool yn, SessionEvent::RTeventCallback after)
67 {
68         /* its a bit silly to have to do this, but it keeps the API for this public method sane (we're 
69            only going to solo one route) and keeps our ability to use get_rt_event() for the internal
70            private method.
71         */
72
73         boost::shared_ptr<RouteList> rl (new RouteList);
74         rl->push_back (r);
75
76         queue_event (get_rt_event (rl, yn, after, false, &Session::rt_set_just_one_solo));
77 }
78
79 void
80 Session::rt_set_just_one_solo (boost::shared_ptr<RouteList> just_one, bool yn, bool /*ignored*/)
81 {
82         boost::shared_ptr<RouteList> rl = routes.reader ();
83         boost::shared_ptr<Route> r = just_one->front();
84
85         for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
86                 if (!(*i)->is_hidden() && r != *i) {
87                         (*i)->set_solo (!yn, (*i)->route_group());
88                 }
89         }
90         
91         r->set_solo (yn, r->route_group());
92         
93         set_dirty();
94 }
95
96 void
97 Session::set_listen (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
98 {
99         queue_event (get_rt_event (rl, yn, after, group_override, &Session::rt_set_listen));
100 }
101
102 void
103 Session::rt_set_listen (boost::shared_ptr<RouteList> rl, bool yn, bool /*group_override*/ )
104 {
105         for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
106                 if (!(*i)->is_hidden()) {
107                         (*i)->set_listen (yn, this);
108                 }
109         }
110
111         set_dirty();
112 }
113
114 void
115 Session::set_mute (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
116 {
117         queue_event (get_rt_event (rl, yn, after, group_override, &Session::rt_set_mute));
118 }
119
120 void
121 Session::rt_set_mute (boost::shared_ptr<RouteList> rl, bool yn, bool /*group_override*/)
122 {
123         for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
124                 if (!(*i)->is_hidden()) {
125                         (*i)->set_mute (yn, this);
126                 }
127         }
128         
129         set_dirty();
130 }
131
132 void
133 Session::set_solo_isolated (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
134 {
135         queue_event (get_rt_event (rl, yn, after, group_override, &Session::rt_set_solo_isolated));
136 }
137
138 void
139 Session::rt_set_solo_isolated (boost::shared_ptr<RouteList> rl, bool yn, bool /*group_override*/)
140 {
141         for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
142                 if (!(*i)->is_master() && !(*i)->is_monitor() && !(*i)->is_hidden()) {
143                         (*i)->set_solo_isolated (yn, this);
144                 }
145         }
146         
147         set_dirty();
148 }
149
150 void
151 Session::set_record_enabled (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
152 {
153         if (!writable()) {
154                 return;
155         }
156         
157         queue_event (get_rt_event (rl, yn, after, group_override, &Session::rt_set_record_enabled));
158 }
159
160 void
161 Session::rt_set_record_enabled (boost::shared_ptr<RouteList> rl, bool yn, bool group_override)
162 {
163         for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
164                 if ((*i)->is_hidden()) {
165                         continue;
166                 }
167
168                 boost::shared_ptr<Track> t;
169
170                 if ((t = boost::dynamic_pointer_cast<Track>(*i)) != 0) {
171                         t->set_record_enabled (yn, (group_override ? (void*) t->route_group() : (void *) this));
172                 }
173         }
174
175         set_dirty ();
176 }
177
178 void
179 Session::process_rtop (SessionEvent* ev)
180 {
181         ev->rt_slot ();
182
183         if (ev->event_loop) {
184                 ev->event_loop->call_slot (MISSING_INVALIDATOR, boost::bind (ev->rt_return, ev));
185         } else {
186                 warning << string_compose ("programming error: %1", X_("Session RT event queued from thread without a UI - cleanup in RT thread!")) << endmsg;
187                 ev->rt_return (ev);
188         }
189 }