various fixes to MidiRegionView selection handling, key handling, drawing of ghost...
[ardour2.git] / libs / ardour / session_rtevents.cc
blobce40c5ce9e5b4f787f8c77521411ba682cf4a34b
1 /*
2 Copyright (C) 1999-2009 Paul Davis
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.
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.
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.
19 #include <boost/bind.hpp>
21 #include "pbd/error.h"
22 #include "pbd/compose.h"
24 #include "ardour/session.h"
25 #include "ardour/route.h"
26 #include "ardour/track.h"
28 #include "i18n.h"
30 using namespace std;
31 using namespace PBD;
32 using namespace ARDOUR;
33 using namespace Glib;
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))
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 ();
44 return ev;
47 void
48 Session::set_solo (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
50 queue_event (get_rt_event (rl, yn, after, group_override, &Session::rt_set_solo));
53 void
54 Session::rt_set_solo (boost::shared_ptr<RouteList> rl, bool yn, bool /* group_override */)
56 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
57 if (!(*i)->is_hidden()) {
58 (*i)->set_solo (yn, this);
62 set_dirty();
65 void
66 Session::set_just_one_solo (boost::shared_ptr<Route> r, bool yn, SessionEvent::RTeventCallback after)
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.
73 boost::shared_ptr<RouteList> rl (new RouteList);
74 rl->push_back (r);
76 queue_event (get_rt_event (rl, yn, after, false, &Session::rt_set_just_one_solo));
79 void
80 Session::rt_set_just_one_solo (boost::shared_ptr<RouteList> just_one, bool yn, bool /*ignored*/)
82 boost::shared_ptr<RouteList> rl = routes.reader ();
83 boost::shared_ptr<Route> r = just_one->front();
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());
91 r->set_solo (yn, r->route_group());
93 set_dirty();
96 void
97 Session::set_listen (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
99 queue_event (get_rt_event (rl, yn, after, group_override, &Session::rt_set_listen));
102 void
103 Session::rt_set_listen (boost::shared_ptr<RouteList> rl, bool yn, bool /*group_override*/ )
105 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
106 if (!(*i)->is_hidden()) {
107 (*i)->set_listen (yn, this);
111 set_dirty();
114 void
115 Session::set_mute (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
117 queue_event (get_rt_event (rl, yn, after, group_override, &Session::rt_set_mute));
120 void
121 Session::rt_set_mute (boost::shared_ptr<RouteList> rl, bool yn, bool /*group_override*/)
123 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
124 if (!(*i)->is_hidden()) {
125 (*i)->set_mute (yn, this);
129 set_dirty();
132 void
133 Session::set_solo_isolated (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
135 queue_event (get_rt_event (rl, yn, after, group_override, &Session::rt_set_solo_isolated));
138 void
139 Session::rt_set_solo_isolated (boost::shared_ptr<RouteList> rl, bool yn, bool /*group_override*/)
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);
147 set_dirty();
150 void
151 Session::set_record_enabled (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
153 if (!writable()) {
154 return;
157 queue_event (get_rt_event (rl, yn, after, group_override, &Session::rt_set_record_enabled));
160 void
161 Session::rt_set_record_enabled (boost::shared_ptr<RouteList> rl, bool yn, bool group_override)
163 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
164 if ((*i)->is_hidden()) {
165 continue;
168 boost::shared_ptr<Track> t;
170 if ((t = boost::dynamic_pointer_cast<Track>(*i)) != 0) {
171 t->set_record_enabled (yn, (group_override ? (void*) t->route_group() : (void *) this));
175 set_dirty ();
178 void
179 Session::process_rtop (SessionEvent* ev)
181 ev->rt_slot ();
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);