track add/remove of monitor and/or master busses in mackie support code.
authorPaul Davis <paul@linuxaudiosystems.com>
Sun, 13 Dec 2015 13:33:02 +0000 (08:33 -0500)
committerPaul Davis <paul@linuxaudiosystems.com>
Sun, 13 Dec 2015 13:33:09 +0000 (08:33 -0500)
Somehow fails to move master fader to correct position when monitor section is added

libs/surfaces/mackie/mackie_control_protocol.cc
libs/surfaces/mackie/mackie_control_protocol.h
libs/surfaces/mackie/surface.cc
libs/surfaces/mackie/surface.h

index 966a2cbedd669e66b6aaa2b84d7ba6f59d9cc2ee..a69c99e383a797f8dacae769f5566198cbee32d9 100644 (file)
@@ -696,6 +696,7 @@ MackieControlProtocol::connect_session_signals()
 {
        // receive routes added
        session->RouteAdded.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_route_added, this, _1), this);
+       session->RouteAddedOrRemoved.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_route_added_or_removed, this), this);
        // receive record state toggled
        session->RecordStateChanged.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_record_state_changed, this), this);
        // receive transport state changed
@@ -1190,6 +1191,15 @@ void MackieControlProtocol::notify_parameter_changed (std::string const & p)
        }
 }
 
+void
+MackieControlProtocol::notify_route_added_or_removed ()
+{
+       Glib::Threads::Mutex::Lock lm (surfaces_lock);
+       for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
+               (*s)->master_monitor_may_have_changed ();
+       }
+}
+
 // RouteList is the set of routes that have just been added
 void
 MackieControlProtocol::notify_route_added (ARDOUR::RouteList & rl)
@@ -1202,6 +1212,15 @@ MackieControlProtocol::notify_route_added (ARDOUR::RouteList & rl)
                }
        }
 
+       /* special case: single route, and it is the monitor or master out */
+
+       if (rl.size() == 1 && (rl.front()->is_monitor() || rl.front()->is_master())) {
+               Glib::Threads::Mutex::Lock lm (surfaces_lock);
+               for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
+                       (*s)->master_monitor_may_have_changed ();
+               }
+       }
+
        // currently assigned banks are less than the full set of
        // strips, so activate the new strip now.
 
index f5db7942516cf42693a7b2b3647682a60a37fba2..1ce45ce82f7fa46c295ea03cc45a499e73f8f84e 100644 (file)
@@ -187,6 +187,7 @@ class MackieControlProtocol
 
        void handle_button_event (Mackie::Surface&, Mackie::Button& button, Mackie::ButtonState);
 
+       void notify_route_added_or_removed ();
        void notify_route_added (ARDOUR::RouteList &);
        void notify_remote_id_changed();
 
index f886a5f59488e543879691734b1c7d6437052432..0082bd480f77dff0d31be1c371acfb24050818a8 100644 (file)
@@ -363,6 +363,14 @@ Surface::init_strips (uint32_t n)
        }
 }
 
+void
+Surface::master_monitor_may_have_changed ()
+{
+       std::cerr << "MMmhc\n";
+       setup_master ();
+       std::cerr << " done\n";
+}
+
 void
 Surface::setup_master ()
 {
@@ -373,28 +381,37 @@ Surface::setup_master ()
        }
 
        if (!m) {
+               _master_fader->set_control (boost::shared_ptr<AutomationControl>());
+               master_connection.disconnect ();
                return;
        }
 
-       _master_fader = dynamic_cast<Fader*> (Fader::factory (*this, _mcp.device_info().strip_cnt(), "master", *groups["master"]));
+       if (!_master_fader) {
+               _master_fader = dynamic_cast<Fader*> (Fader::factory (*this, _mcp.device_info().strip_cnt(), "master", *groups["master"]));
+
+               Groups::iterator group_it;
+               group_it = groups.find("master");
+
+               DeviceInfo device_info = _mcp.device_info();
+               GlobalButtonInfo master_button = device_info.get_global_button(Button::MasterFaderTouch);
+               Button* bb = dynamic_cast<Button*> (Button::factory (
+                                                           *this,
+                                                           Button::MasterFaderTouch,
+                                                           master_button.id,
+                                                           master_button.label,
+                                                           *(group_it->second)
+                                                           ));
+
+               DEBUG_TRACE (DEBUG::MackieControl, string_compose ("surface %1 Master Fader new button BID %2 id %3\n",
+                                                                  number(), Button::MasterFaderTouch, bb->id()));
+       } else {
+               master_connection.disconnect ();
+       }
 
        _master_fader->set_control (m->gain_control());
-       m->gain_control()->Changed.connect (*this, MISSING_INVALIDATOR, boost::bind (&Surface::master_gain_changed, this), ui_context());
-
-       Groups::iterator group_it;
-       group_it = groups.find("master");
-
-       DeviceInfo device_info = _mcp.device_info();
-       GlobalButtonInfo master_button = device_info.get_global_button(Button::MasterFaderTouch);
-       Button* bb = dynamic_cast<Button*> (Button::factory (
-               *this,
-               Button::MasterFaderTouch,
-               master_button.id,
-               master_button.label,
-               *(group_it->second)
-));
-       DEBUG_TRACE (DEBUG::MackieControl, string_compose ("surface %1 Master Fader new button BID %2 id %3\n",
-               number(), Button::MasterFaderTouch, bb->id()));
+       m->gain_control()->Changed.connect (master_connection, MISSING_INVALIDATOR, boost::bind (&Surface::master_gain_changed, this), ui_context());
+       _last_master_gain_written = FLT_MAX; /* some essentially impossible value */
+       master_gain_changed ();
 }
 
 void
@@ -406,6 +423,7 @@ Surface::master_gain_changed ()
 
        boost::shared_ptr<AutomationControl> ac = _master_fader->control();
        if (!ac) {
+               std::cerr << "no control!\n";
                return;
        }
 
@@ -416,6 +434,8 @@ Surface::master_gain_changed ()
 
        DEBUG_TRACE (DEBUG::MackieControl, "Surface::master_gain_changed: updating surface master fader\n");
 
+       std::cerr << "send " << normalized_position << std::endl;
+
        _port->write (_master_fader->set_position (normalized_position));
        _last_master_gain_written = normalized_position;
 }
index 166b8ed4bf4a3559aacb7b8d19b86b819c28be77..78bb42ab6aeb97907ee7c9328c45903fe3037692 100644 (file)
@@ -169,6 +169,8 @@ public:
 
        bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool);
 
+       void master_monitor_may_have_changed ();
+
        XMLNode& get_state ();
        int set_state (const XMLNode&, int version);
 
@@ -183,6 +185,7 @@ public:
        Mackie::JogWheel*      _jog_wheel;
        Fader*                 _master_fader;
        float                  _last_master_gain_written;
+       PBD::ScopedConnection   master_connection;
 
        void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
        MidiByteArray host_connection_query (MidiByteArray& bytes);