fix processor -> reconfigure I/O || process concurrency
[ardour.git] / libs / ardour / session_rtevents.cc
index 6d3e7ce78caa0b78d73f1c43e1d2bfc6af64cbd3..6328607eec7dcc6148c5920e84a29783da7fdb40 100644 (file)
@@ -16,6 +16,8 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#include <boost/bind.hpp>
+
 #include "pbd/error.h"
 #include "pbd/compose.h"
 
@@ -30,29 +32,38 @@ using namespace PBD;
 using namespace ARDOUR;
 using namespace Glib;
 
-SessionEvent*
-Session::get_rt_event (boost::shared_ptr<RouteList> rl, bool yn, sigc::slot<void,SessionEvent*> after, bool group_override, 
-                      void (Session::*method) (boost::shared_ptr<RouteList>, bool, bool))
+void
+Session::set_monitoring (boost::shared_ptr<RouteList> rl, MonitorChoice mc, SessionEvent::RTeventCallback after, bool group_override)
 {
-       SessionEvent* ev = new SessionEvent (SessionEvent::RealTimeOperation, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0);
-       ev->rt_slot =   bind (sigc::mem_fun (*this, method), rl, yn, group_override);
-       ev->rt_return = after;
-       ev->ui = UICallback::get_ui_for_thread ();
+       queue_event (get_rt_event (rl, mc, after, group_override, &Session::rt_set_monitoring));
+}
 
-       return ev;
+void
+Session::rt_set_monitoring (boost::shared_ptr<RouteList> rl, MonitorChoice mc, bool /* group_override */)
+{
+       for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
+               if (!(*i)->is_auditioner()) {
+                       boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track> (*i);
+                       if (t) {
+                               t->set_monitoring (mc);
+                       }
+               }
+       }
+
+       set_dirty();
 }
 
 void
-Session::set_solo (boost::shared_ptr<RouteList> rl, bool yn, sigc::slot<void,SessionEvent*> after, bool group_override)
+Session::set_solo (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
 {
        queue_event (get_rt_event (rl, yn, after, group_override, &Session::rt_set_solo));
 }
 
 void
-Session::rt_set_solo (boost::shared_ptr<RouteList> rl, bool yn, bool group_override)
+Session::rt_set_solo (boost::shared_ptr<RouteList> rl, bool yn, bool /* group_override */)
 {
        for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
-               if (!(*i)->is_hidden()) {
+               if (!(*i)->is_auditioner()) {
                        (*i)->set_solo (yn, this);
                }
        }
@@ -61,9 +72,29 @@ Session::rt_set_solo (boost::shared_ptr<RouteList> rl, bool yn, bool group_overr
 }
 
 void
-Session::set_just_one_solo (boost::shared_ptr<Route> r, bool yn, sigc::slot<void,SessionEvent*> after)
+Session::cancel_solo_after_disconnect (boost::shared_ptr<Route> r, bool upstream, SessionEvent::RTeventCallback after)
+{
+       boost::shared_ptr<RouteList> rl (new RouteList);
+       rl->push_back (r);
+
+       queue_event (get_rt_event (rl, upstream, after, false, &Session::rt_cancel_solo_after_disconnect));
+}
+
+void
+Session::rt_cancel_solo_after_disconnect (boost::shared_ptr<RouteList> rl, bool upstream, bool /* group_override */)
 {
-       /* its a bit silly to have to do this, but it keeps the API for this public method sane (we're 
+       for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
+               if (!(*i)->is_auditioner()) {
+                       (*i)->cancel_solo_after_disconnect (upstream);
+               }
+       }
+       /* no need to call set-dirty - the disconnect will already have done that */
+}
+
+void
+Session::set_just_one_solo (boost::shared_ptr<Route> r, bool yn, SessionEvent::RTeventCallback after)
+{
+       /* its a bit silly to have to do this, but it keeps the API for this public method sane (we're
           only going to solo one route) and keeps our ability to use get_rt_event() for the internal
           private method.
        */
@@ -81,27 +112,27 @@ Session::rt_set_just_one_solo (boost::shared_ptr<RouteList> just_one, bool yn, b
        boost::shared_ptr<Route> r = just_one->front();
 
        for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
-               if (!(*i)->is_hidden() && r != *i) {
+               if (!(*i)->is_auditioner() && r != *i) {
                        (*i)->set_solo (!yn, (*i)->route_group());
                }
        }
-       
+
        r->set_solo (yn, r->route_group());
-       
+
        set_dirty();
 }
 
 void
-Session::set_listen (boost::shared_ptr<RouteList> rl, bool yn, sigc::slot<void,SessionEvent*> after, bool group_override)
+Session::set_listen (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
 {
        queue_event (get_rt_event (rl, yn, after, group_override, &Session::rt_set_listen));
 }
 
 void
-Session::rt_set_listen (boost::shared_ptr<RouteList> rl, bool yn, bool group_override)
+Session::rt_set_listen (boost::shared_ptr<RouteList> rl, bool yn, bool /*group_override*/ )
 {
        for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
-               if (!(*i)->is_hidden()) {
+               if (!(*i)->is_auditioner()) {
                        (*i)->set_listen (yn, this);
                }
        }
@@ -110,45 +141,82 @@ Session::rt_set_listen (boost::shared_ptr<RouteList> rl, bool yn, bool group_ove
 }
 
 void
-Session::set_mute (boost::shared_ptr<RouteList> rl, bool yn, sigc::slot<void,SessionEvent*> after, bool group_override)
+Session::set_mute (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
 {
        queue_event (get_rt_event (rl, yn, after, group_override, &Session::rt_set_mute));
 }
 
 void
-Session::rt_set_mute (boost::shared_ptr<RouteList> rl, bool yn, bool group_override)
+Session::rt_set_mute (boost::shared_ptr<RouteList> rl, bool yn, bool /*group_override*/)
 {
        for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
-               if (!(*i)->is_hidden()) {
+               if (!(*i)->is_monitor() && !(*i)->is_auditioner()) {
                        (*i)->set_mute (yn, this);
                }
        }
-       
+
+       set_dirty();
+}
+
+void
+Session::set_solo_isolated (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
+{
+       queue_event (get_rt_event (rl, yn, after, group_override, &Session::rt_set_solo_isolated));
+}
+
+void
+Session::rt_set_solo_isolated (boost::shared_ptr<RouteList> rl, bool yn, bool /*group_override*/)
+{
+       for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
+               if (!(*i)->is_master() && !(*i)->is_monitor() && !(*i)->is_auditioner()) {
+                       (*i)->set_solo_isolated (yn, this);
+               }
+       }
+
        set_dirty();
 }
 
 void
-Session::set_record_enable (boost::shared_ptr<RouteList> rl, bool yn, sigc::slot<void,SessionEvent*> after, bool group_override)
+Session::set_record_enabled (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
 {
        if (!writable()) {
                return;
        }
-       
-       queue_event (get_rt_event (rl, yn, after, group_override, &Session::rt_set_record_enable));
+
+       /* do the non-RT part of rec-enabling first - the RT part will be done
+        * on the next process cycle. This does mean that theoretically we are
+        * doing things provisionally on the assumption that the rec-enable
+        * change will work, but this had better be a solid assumption for
+        * other reasons.
+        */
+
+       for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
+               if ((*i)->is_auditioner()) {
+                       continue;
+               }
+
+               boost::shared_ptr<Track> t;
+
+               if ((t = boost::dynamic_pointer_cast<Track>(*i)) != 0) {
+                       t->prep_record_enabled (yn, (group_override ? (void*) t->route_group() : (void *) this));
+               }
+       }
+
+       queue_event (get_rt_event (rl, yn, after, group_override, &Session::rt_set_record_enabled));
 }
 
 void
-Session::rt_set_record_enable (boost::shared_ptr<RouteList> rl, bool yn, bool group_override)
+Session::rt_set_record_enabled (boost::shared_ptr<RouteList> rl, bool yn, bool group_override)
 {
        for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
-               if ((*i)->is_hidden()) {
+               if ((*i)->is_auditioner()) {
                        continue;
                }
 
                boost::shared_ptr<Track> t;
 
                if ((t = boost::dynamic_pointer_cast<Track>(*i)) != 0) {
-                       t->set_record_enable (yn, (group_override ? (void*) t->route_group() : (void *) this));
+                       t->set_record_enabled (yn, (group_override ? (void*) t->route_group() : (void *) this));
                }
        }
 
@@ -160,8 +228,8 @@ Session::process_rtop (SessionEvent* ev)
 {
        ev->rt_slot ();
 
-       if (ev->ui) {
-               ev->ui->call_slot (bind (ev->rt_return, ev));
+       if (ev->event_loop) {
+               ev->event_loop->call_slot (MISSING_INVALIDATOR, boost::bind (ev->rt_return, ev));
        } else {
                warning << string_compose ("programming error: %1", X_("Session RT event queued from thread without a UI - cleanup in RT thread!")) << endmsg;
                ev->rt_return (ev);