LTC Slave, add support for variable framerates
[ardour.git] / libs / surfaces / mackie / strip.cc
index 76fcc25a6c768e8bedcc2df0e78f2217c42857ff..2b4368f4bb2a8b6d77a6ea69d7a7ddf1dfb364a0 100644 (file)
@@ -70,9 +70,12 @@ Strip::Strip (Surface& s, const std::string& name, int index, const map<Button::
        , _fader_touch (0)
        , _vpot (0)
        , _fader (0)
+       , _meter (0)
        , _index (index)
        , _surface (&s)
        , _controls_locked (false)
+       , _transport_is_rolling (false)
+       , _metering_active (true)
        , _reset_display_at (0)
        , _last_gain_position_written (-1.0)
        , _last_pan_azi_position_written (-1.0)
@@ -80,7 +83,10 @@ Strip::Strip (Surface& s, const std::string& name, int index, const map<Button::
 {
        _fader = dynamic_cast<Fader*> (Fader::factory (*_surface, index, "fader", *this));
        _vpot = dynamic_cast<Pot*> (Pot::factory (*_surface, Pot::ID + index, "vpot", *this));
-       _meter = dynamic_cast<Meter*> (Meter::factory (*_surface, index, "meter", *this));
+
+       if (s.mcp().device_info().has_meters()) {
+               _meter = dynamic_cast<Meter*> (Meter::factory (*_surface, index, "meter", *this));
+       }
 
        for (map<Button::ID,StripButtonInfo>::const_iterator b = strip_buttons.begin(); b != strip_buttons.end(); ++b) {
                Button* bb = dynamic_cast<Button*> (Button::factory (*_surface, b->first, b->second.base_id + index, b->second.name, *this));
@@ -123,6 +129,7 @@ Strip::add (Control & control)
                        break;
                case Button::FaderTouch:
                        _fader_touch = button;
+                       break;
                default:
                        break;
                }
@@ -130,7 +137,7 @@ Strip::add (Control & control)
 }
 
 void
-Strip::set_route (boost::shared_ptr<Route> r, bool with_messages)
+Strip::set_route (boost::shared_ptr<Route> r, bool /*with_messages*/)
 {
        if (_controls_locked) {
                return;
@@ -151,6 +158,7 @@ Strip::set_route (boost::shared_ptr<Route> r, bool with_messages)
        reset_saved_values ();
 
        if (!r) {
+               zero ();
                return;
        }
 
@@ -162,7 +170,9 @@ Strip::set_route (boost::shared_ptr<Route> r, bool with_messages)
 
        set_vpot_parameter (PanAzimuthAutomation);
        
-       _route->solo_control()->Changed.connect(route_connections, MISSING_INVALIDATOR, boost::bind (&Strip::notify_solo_changed, this), ui_context());
+       _route->solo_changed.connect (route_connections, MISSING_INVALIDATOR, boost::bind (&Strip::notify_solo_changed, this), ui_context());
+       _route->listen_changed.connect (route_connections, MISSING_INVALIDATOR, boost::bind (&Strip::notify_solo_changed, this), ui_context());
+
        _route->mute_control()->Changed.connect(route_connections, MISSING_INVALIDATOR, boost::bind (&Strip::notify_mute_changed, this), ui_context());
 
        boost::shared_ptr<Pannable> pannable = _route->pannable();
@@ -213,8 +223,6 @@ Strip::set_route (boost::shared_ptr<Route> r, bool with_messages)
                        if ((a = automatable.find (PanWidthAutomation)) != automatable.end()) {
                                possible_pot_parameters.push_back (PanWidthAutomation);
                        }
-               } else {
-                       std::cerr << "connected to route without a panner\n";
                }
        }
 }
@@ -240,7 +248,7 @@ void
 Strip::notify_solo_changed ()
 {
        if (_route && _solo) {
-               _surface->write (_solo->set_state (_route->soloed() ? on : off));
+               _surface->write (_solo->set_state ((_route->soloed() || _route->listening_via_monitor()) ? on : off));
        }
 }
 
@@ -420,7 +428,7 @@ Strip::notify_panner_width_changed (bool force_update)
 }
 
 void
-Strip::select_event (Button& button, ButtonState bs)
+Strip::select_event (Button&, ButtonState bs)
 {
        DEBUG_TRACE (DEBUG::MackieControl, "select button\n");
        
@@ -455,15 +463,16 @@ Strip::select_event (Button& button, ButtonState bs)
 }
 
 void
-Strip::vselect_event (Button& button, ButtonState bs)
+Strip::vselect_event (Button&, ButtonState bs)
 {
        if (bs == press) {
 
                int ms = _surface->mcp().modifier_state();
                                
                if (ms & MackieControlProtocol::MODIFIER_SHIFT) {
-                       boost::shared_ptr<AutomationControl> ac = button.control ();
 
+                       boost::shared_ptr<AutomationControl> ac = _vpot->control ();
+                               
                        if (ac) {
                                
                                /* reset to default/normal value */
@@ -471,6 +480,7 @@ Strip::vselect_event (Button& button, ButtonState bs)
                        }
 
                }  else {
+
                        DEBUG_TRACE (DEBUG::MackieControl, "switching to next pot mode\n");
                        next_pot_mode ();
                }
@@ -479,7 +489,7 @@ Strip::vselect_event (Button& button, ButtonState bs)
 }
 
 void
-Strip::fader_touch_event (Button& button, ButtonState bs)
+Strip::fader_touch_event (Button&, ButtonState bs)
 {
        DEBUG_TRACE (DEBUG::MackieControl, string_compose ("fader touch, press ? %1\n", (bs == press)));
        
@@ -684,9 +694,9 @@ Strip::update_automation ()
 void
 Strip::update_meter ()
 {
-       if (_meter) {
+       if (_meter && _transport_is_rolling && _metering_active) {
                float dB = const_cast<PeakMeter&> (_route->peak_meter()).peak_power (0);
-               _surface->write (_meter->update_message (dB));
+               _meter->send_update (*_surface, dB);
        }
 }
 
@@ -755,9 +765,9 @@ Strip::unlock_controls ()
 }
 
 void
-Strip::gui_selection_changed (ARDOUR::RouteNotificationListPtr rl)
+Strip::gui_selection_changed (const ARDOUR::StrongRouteNotificationList& rl)
 {
-       for (ARDOUR::RouteNotificationList::iterator i = rl->begin(); i != rl->end(); ++i) {
+       for (ARDOUR::StrongRouteNotificationList::const_iterator i = rl.begin(); i != rl.end(); ++i) {
                if ((*i) == _route) {
                        _surface->write (_select->set_state (on));
                        return;
@@ -1060,3 +1070,28 @@ Strip::reset_saved_values ()
        _last_gain_position_written = -1.0;
 
 }
+
+void 
+Strip::notify_metering_state_changed()
+{
+       if (!_route || !_meter) {
+               return;
+       }
+       
+       bool transport_is_rolling = (_surface->mcp().get_transport_speed () != 0.0f);
+       bool metering_active = _surface->mcp().metering_active ();
+       
+       if ((_transport_is_rolling == transport_is_rolling) && (_metering_active == metering_active)) {
+               return;
+       }
+       
+       _meter->notify_metering_state_changed (*_surface, transport_is_rolling, metering_active);
+       
+       if (!transport_is_rolling || !metering_active) {
+               notify_property_changed (PBD::PropertyChange (ARDOUR::Properties::name));
+               notify_panner_azi_changed (true);
+       }
+       
+       _transport_is_rolling = transport_is_rolling;
+       _metering_active = metering_active;
+}