allow to customize variable i/o plugin inputs
[ardour.git] / libs / ardour / session_rtevents.cc
index 921a6348ebdd87cfc7fd507cf2700ceaf4203e56..132f706c66def58a7e065dd42d3e12c388221e03 100644 (file)
@@ -32,40 +32,74 @@ using namespace PBD;
 using namespace ARDOUR;
 using namespace Glib;
 
-SessionEvent*
-Session::get_rt_event (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback 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,
+                         Controllable::GroupControlDisposition group_override)
+{
+       queue_event (get_rt_event (rl, mc, after, group_override, &Session::rt_set_monitoring));
+}
+
+void
+Session::rt_set_monitoring (boost::shared_ptr<RouteList> rl, MonitorChoice mc, Controllable::GroupControlDisposition group_override)
 {
-       SessionEvent* ev = new SessionEvent (SessionEvent::RealTimeOperation, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0);
-       ev->rt_slot = boost::bind (method, this, rl, yn, group_override);
-       ev->rt_return = after;
-       ev->event_loop = EventLoop::get_event_loop_for_thread ();
+       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, group_override);
+                       }
+               }
+       }
+
+       set_dirty();
+}
+
+void
+Session::clear_all_solo_state (boost::shared_ptr<RouteList> rl)
+{
+       queue_event (get_rt_event (rl, false, rt_cleanup, Controllable::NoGroup, &Session::rt_clear_all_solo_state));
+}
 
-       return ev;
+void
+Session::rt_clear_all_solo_state (boost::shared_ptr<RouteList> rl, bool /* yn */, Controllable::GroupControlDisposition /* group_override */)
+{
+       for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
+               if ((*i)->is_auditioner()) {
+                       continue;
+               }
+               (*i)->clear_all_solo_state();
+       }
+       set_dirty();
 }
 
 void
-Session::set_solo (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
+Session::set_solo (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after,
+                   Controllable::GroupControlDisposition 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, Controllable::GroupControlDisposition group_override)
 {
        for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
-               if (!(*i)->is_hidden()) {
-                       (*i)->set_solo (yn, this);
+               if (!(*i)->is_auditioner()) {
+                       (*i)->set_solo (yn, group_override);
                }
        }
 
        set_dirty();
+       /* XXX boost::shared_ptr<RouteList>  goes out of scope here and is likley free()ed in RT context
+        * because boost's shared_ptr does reference counting and free/delete in the dtor.
+        * (this also applies to other rt_  methods here)
+        */
 }
 
 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 
+       /* 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.
        */
@@ -73,38 +107,38 @@ Session::set_just_one_solo (boost::shared_ptr<Route> r, bool yn, SessionEvent::R
        boost::shared_ptr<RouteList> rl (new RouteList);
        rl->push_back (r);
 
-       queue_event (get_rt_event (rl, yn, after, false, &Session::rt_set_just_one_solo));
+       queue_event (get_rt_event (rl, yn, after, Controllable::NoGroup, &Session::rt_set_just_one_solo));
 }
 
 void
-Session::rt_set_just_one_solo (boost::shared_ptr<RouteList> just_one, bool yn, bool /*ignored*/)
+Session::rt_set_just_one_solo (boost::shared_ptr<RouteList> just_one, bool yn, Controllable::GroupControlDisposition /*ignored*/)
 {
        boost::shared_ptr<RouteList> rl = routes.reader ();
        boost::shared_ptr<Route> r = just_one->front();
 
        for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
-               if (!(*i)->is_hidden() && r != *i) {
-                       (*i)->set_solo (!yn, (*i)->route_group());
+               if (!(*i)->is_auditioner() && r != *i) {
+                       (*i)->set_solo (!yn, Controllable::NoGroup);
                }
        }
-       
-       r->set_solo (yn, r->route_group());
-       
+
+       r->set_solo (yn, Controllable::NoGroup);
+
        set_dirty();
 }
 
 void
-Session::set_listen (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
+Session::set_listen (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, Controllable::GroupControlDisposition 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, Controllable::GroupControlDisposition group_override)
 {
        for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
-               if (!(*i)->is_hidden()) {
-                       (*i)->set_listen (yn, this);
+               if (!(*i)->is_auditioner()) {
+                       (*i)->set_listen (yn, group_override);
                }
        }
 
@@ -112,63 +146,114 @@ Session::rt_set_listen (boost::shared_ptr<RouteList> rl, bool yn, bool /*group_o
 }
 
 void
-Session::set_mute (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
+Session::set_mute (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, Controllable::GroupControlDisposition group_override)
 {
+       /* Set superficial value of mute controls for automation. */
+       for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
+               boost::shared_ptr<Route::MuteControllable> mc = (*i)->mute_control();
+               mc->set_superficial_value(yn);
+       }
+
        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, Controllable::GroupControlDisposition group_override)
 {
        for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
-               if (!(*i)->is_hidden()) {
-                       (*i)->set_mute (yn, this);
+               if (!(*i)->is_monitor() && !(*i)->is_auditioner()) {
+                       (*i)->set_mute (yn, group_override);
                }
        }
-       
+
        set_dirty();
 }
 
 void
-Session::set_solo_isolated (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
+Session::set_solo_isolated (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, Controllable::GroupControlDisposition 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*/)
+Session::rt_set_solo_isolated (boost::shared_ptr<RouteList> rl, bool yn, Controllable::GroupControlDisposition group_override)
 {
        for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
-               if (!(*i)->is_master() && !(*i)->is_monitor() && !(*i)->is_hidden()) {
-                       (*i)->set_solo_isolated (yn, this);
+               if (!(*i)->is_master() && !(*i)->is_monitor() && !(*i)->is_auditioner()) {
+                       (*i)->set_solo_isolated (yn, group_override);
                }
        }
-       
+
        set_dirty();
 }
 
 void
-Session::set_record_enable (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, bool group_override)
+Session::set_record_enabled (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, Controllable::GroupControlDisposition 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() || (*i)->record_safe ()) {
+                       continue;
+               }
+
+               boost::shared_ptr<Track> t;
+
+               if ((t = boost::dynamic_pointer_cast<Track>(*i)) != 0) {
+                       t->prep_record_enabled (yn, group_override);
+               }
+       }
+
+       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, Controllable::GroupControlDisposition group_override)
 {
        for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
-               if ((*i)->is_hidden()) {
+               if ((*i)->is_auditioner() || (*i)->record_safe ()) {
+                       continue;
+               }
+
+               boost::shared_ptr<Track> t;
+
+               if ((t = boost::dynamic_pointer_cast<Track>(*i)) != 0) {
+                       t->set_record_enabled (yn, group_override);
+               }
+       }
+
+       set_dirty ();
+}
+
+
+void
+Session::set_record_safe (boost::shared_ptr<RouteList> rl, bool yn, SessionEvent::RTeventCallback after, Controllable::GroupControlDisposition group_override)
+{
+       set_record_enabled (rl, false, after, group_override);
+       queue_event (get_rt_event (rl, yn, after, group_override, &Session::rt_set_record_safe));
+}
+
+void
+Session::rt_set_record_safe (boost::shared_ptr<RouteList> rl, bool yn, Controllable::GroupControlDisposition group_override)
+{
+       for (RouteList::iterator i = rl->begin (); i != rl->end (); ++i) {
+               if ((*i)->is_auditioner ()) { // REQUIRES REVIEW Can audiotioner be in Record Safe mode?
                        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_safe (yn, group_override);
                }
        }