merge (w/fix) with master
[ardour.git] / libs / surfaces / mackie / strip.cc
index 0e5dffde5d31a2022cdcca7ed2df42dab6633671..ef4447d900906d6a92f34957de7e1523a35b2014 100644 (file)
@@ -59,7 +59,6 @@ using namespace ARDOUR;
 using namespace PBD;
 
 #define ui_context() MackieControlProtocol::instance() /* a UICallback-derived object that specifies the event loop for signal handling */
-#define ui_bind(f, ...) boost::protect (boost::bind (f, __VA_ARGS__))
 
 Strip::Strip (Surface& s, const std::string& name, int index, const map<Button::ID,StripButtonInfo>& strip_buttons)
        : Group (name)
@@ -71,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)
@@ -81,16 +83,17 @@ 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));
 
-#ifndef NDEBUG 
+       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));
                DEBUG_TRACE (DEBUG::MackieControl, string_compose ("surface %1 strip %2 new button BID %3 id %4 from base %5\n",
                                                                   _surface->number(), index, Button::id_to_name (bb->bid()), 
                                                                   bb->id(), b->second.base_id));
        }
-#endif 
 }      
 
 Strip::~Strip ()
@@ -126,6 +129,7 @@ Strip::add (Control & control)
                        break;
                case Button::FaderTouch:
                        _fader_touch = button;
+                       break;
                default:
                        break;
                }
@@ -133,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;
@@ -154,6 +158,7 @@ Strip::set_route (boost::shared_ptr<Route> r, bool with_messages)
        reset_saved_values ();
 
        if (!r) {
+               zero ();
                return;
        }
 
@@ -165,23 +170,25 @@ Strip::set_route (boost::shared_ptr<Route> r, bool with_messages)
 
        set_vpot_parameter (PanAzimuthAutomation);
        
-       _route->solo_control()->Changed.connect(route_connections, MISSING_INVALIDATOR, ui_bind (&Strip::notify_solo_changed, this), ui_context());
-       _route->mute_control()->Changed.connect(route_connections, MISSING_INVALIDATOR, ui_bind (&Strip::notify_mute_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();
 
-       if (pannable) {
-               pannable->pan_azimuth_control->Changed.connect(route_connections, MISSING_INVALIDATOR, ui_bind (&Strip::notify_panner_azi_changed, this, false), ui_context());
-               pannable->pan_width_control->Changed.connect(route_connections, MISSING_INVALIDATOR, ui_bind (&Strip::notify_panner_width_changed, this, false), ui_context());
+       if (pannable && _route->panner()) {
+               pannable->pan_azimuth_control->Changed.connect(route_connections, MISSING_INVALIDATOR, boost::bind (&Strip::notify_panner_azi_changed, this, false), ui_context());
+               pannable->pan_width_control->Changed.connect(route_connections, MISSING_INVALIDATOR, boost::bind (&Strip::notify_panner_width_changed, this, false), ui_context());
        }
-       _route->gain_control()->Changed.connect(route_connections, MISSING_INVALIDATOR, ui_bind (&Strip::notify_gain_changed, this, false), ui_context());
-       _route->PropertyChanged.connect (route_connections, MISSING_INVALIDATOR, ui_bind (&Strip::notify_property_changed, this, _1), ui_context());
+       _route->gain_control()->Changed.connect(route_connections, MISSING_INVALIDATOR, boost::bind (&Strip::notify_gain_changed, this, false), ui_context());
+       _route->PropertyChanged.connect (route_connections, MISSING_INVALIDATOR, boost::bind (&Strip::notify_property_changed, this, _1), ui_context());
        
        boost::shared_ptr<Track> trk = boost::dynamic_pointer_cast<ARDOUR::Track>(_route);
        
        if (trk) {
                _recenable->set_control (trk->rec_enable_control());
-               trk->rec_enable_control()->Changed .connect(route_connections, MISSING_INVALIDATOR, ui_bind (&Strip::notify_record_enable_changed, this), ui_context());
+               trk->rec_enable_control()->Changed .connect(route_connections, MISSING_INVALIDATOR, boost::bind (&Strip::notify_record_enable_changed, this), ui_context());
 
                
        }
@@ -189,8 +196,8 @@ Strip::set_route (boost::shared_ptr<Route> r, bool with_messages)
        // TODO this works when a currently-banked route is made inactive, but not
        // when a route is activated which should be currently banked.
        
-       _route->active_changed.connect (route_connections, MISSING_INVALIDATOR, ui_bind (&Strip::notify_active_changed, this), ui_context());
-       _route->DropReferences.connect (route_connections, MISSING_INVALIDATOR, ui_bind (&Strip::notify_route_deleted, this), ui_context());
+       _route->active_changed.connect (route_connections, MISSING_INVALIDATOR, boost::bind (&Strip::notify_active_changed, this), ui_context());
+       _route->DropReferences.connect (route_connections, MISSING_INVALIDATOR, boost::bind (&Strip::notify_route_deleted, this), ui_context());
        
        /* Update */
        
@@ -201,20 +208,20 @@ Strip::set_route (boost::shared_ptr<Route> r, bool with_messages)
        build_input_list (_route->input()->n_ports());
        build_output_list (_route->output()->n_ports());
 
-       current_pot_modes.clear();
+       possible_pot_parameters.clear();
 
        if (pannable) {
-               boost::shared_ptr<Panner> panner = pannable->panner();
+               boost::shared_ptr<Panner> panner = _route->panner();
                if (panner) {
                        set<Evoral::Parameter> automatable = panner->what_can_be_automated ();
                        set<Evoral::Parameter>::iterator a;
                        
                        if ((a = automatable.find (PanAzimuthAutomation)) != automatable.end()) {
-                               current_pot_modes.push_back (PanAzimuthAutomation);
+                               possible_pot_parameters.push_back (PanAzimuthAutomation);
                        }
                        
                        if ((a = automatable.find (PanWidthAutomation)) != automatable.end()) {
-                               current_pot_modes.push_back (PanWidthAutomation);
+                               possible_pot_parameters.push_back (PanWidthAutomation);
                        }
                }
        }
@@ -241,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));
        }
 }
 
@@ -284,21 +291,20 @@ Strip::notify_gain_changed (bool force_update)
                
                Control* control;
 
-               if (_surface->mcp().flip_mode()) {
+               if (_surface->mcp().flip_mode() != MackieControlProtocol::Normal) {
                        control = _vpot;
                } else {
                        control = _fader;
                }
 
-
                boost::shared_ptr<AutomationControl> ac = _route->gain_control();
                
                float gain_coefficient = ac->get_value();
                float normalized_position = ac->internal_to_interface (gain_coefficient);
-               
+
                if (force_update || normalized_position != _last_gain_position_written) {
                        
-                       if (_surface->mcp().flip_mode()) {
+                       if (_surface->mcp().flip_mode() != MackieControlProtocol::Normal) {
                                if (!control->in_use()) {
                                        _surface->write (_vpot->set (normalized_position, true, Pot::wrap));
                                }
@@ -346,7 +352,7 @@ Strip::notify_panner_azi_changed (bool force_update)
 
                boost::shared_ptr<Pannable> pannable = _route->pannable();
 
-               if (!pannable) {
+               if (!pannable || !_route->panner()) {
                        _surface->write (_vpot->zero());
                        return;
                }
@@ -385,7 +391,7 @@ Strip::notify_panner_width_changed (bool force_update)
 
                boost::shared_ptr<Pannable> pannable = _route->pannable();
 
-               if (!pannable) {
+               if (!pannable || !_route->panner()) {
                        _surface->write (_vpot->zero());
                        return;
                }
@@ -401,7 +407,7 @@ Strip::notify_panner_width_changed (bool force_update)
                
                if (force_update || pos != _last_pan_azi_position_written) {
                        
-                       if (_surface->mcp().flip_mode()) {
+                       if (_surface->mcp().flip_mode() != MackieControlProtocol::Normal) {
 
                                if (control == _fader) {
                                        if (!control->in_use()) {
@@ -421,7 +427,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");
        
@@ -456,16 +462,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 */
@@ -473,6 +479,7 @@ Strip::vselect_event (Button& button, ButtonState bs)
                        }
 
                }  else {
+
                        DEBUG_TRACE (DEBUG::MackieControl, "switching to next pot mode\n");
                        next_pot_mode ();
                }
@@ -481,7 +488,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)));
        
@@ -599,8 +606,8 @@ Strip::do_parameter_display (AutomationType type, float val)
        case PanAzimuthAutomation:
                if (_route) {
                        boost::shared_ptr<Pannable> p = _route->pannable();
-                       if (p && p->panner()) {
-                               string str = p->panner()->value_as_string (p->pan_azimuth_control);
+                       if (p && _route->panner()) {
+                               string str =_route->panner()->value_as_string (p->pan_azimuth_control);
                                _surface->write (display (1, str));
                        }
                }
@@ -686,9 +693,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);
        }
 }
 
@@ -757,9 +764,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;
@@ -937,7 +944,7 @@ Strip::next_pot_mode ()
 {
        vector<Evoral::Parameter>::iterator i;
 
-       if (_surface->mcp().flip_mode()) {
+       if (_surface->mcp().flip_mode() != MackieControlProtocol::Normal) {
                /* do not change vpot mode while in flipped mode */
                DEBUG_TRACE (DEBUG::MackieControl, "not stepping pot mode - in flip mode\n");
                _surface->write (display (1, "Flip"));
@@ -945,13 +952,18 @@ Strip::next_pot_mode ()
                return;
        }
 
+
        boost::shared_ptr<AutomationControl> ac = _vpot->control();
 
        if (!ac) {
                return;
        }
 
-       for (i = current_pot_modes.begin(); i != current_pot_modes.end(); ++i) {
+       if (possible_pot_parameters.empty() || (possible_pot_parameters.size() == 1 && possible_pot_parameters.front() == ac->parameter())) {
+               return;
+       }
+
+       for (i = possible_pot_parameters.begin(); i != possible_pot_parameters.end(); ++i) {
                if ((*i) == ac->parameter()) {
                        break;
                }
@@ -961,12 +973,12 @@ Strip::next_pot_mode ()
           also happen if the current mode is not in the current pot mode list)
        */
 
-       if (i != current_pot_modes.end()) {
+       if (i != possible_pot_parameters.end()) {
                ++i;
        }
 
-       if (i == current_pot_modes.end()) {
-               i = current_pot_modes.begin();
+       if (i == possible_pot_parameters.end()) {
+               i = possible_pot_parameters.begin();
        }
 
        set_vpot_parameter (*i);
@@ -985,7 +997,7 @@ Strip::set_vpot_parameter (Evoral::Parameter p)
        case PanAzimuthAutomation:
                pannable = _route->pannable ();
                if (pannable) {
-                       if (_surface->mcp().flip_mode()) {
+                       if (_surface->mcp().flip_mode() != MackieControlProtocol::Normal) {
                                /* gain to vpot, pan azi to fader */
                                _vpot->set_control (_route->gain_control());
                                control_by_parameter[GainAutomation] = _vpot;
@@ -1013,7 +1025,7 @@ Strip::set_vpot_parameter (Evoral::Parameter p)
        case PanWidthAutomation:
                pannable = _route->pannable ();
                if (pannable) {
-                       if (_surface->mcp().flip_mode()) {
+                       if (_surface->mcp().flip_mode() != MackieControlProtocol::Normal) {
                                /* gain to vpot, pan width to fader */
                                _vpot->set_control (_route->gain_control());
                                control_by_parameter[GainAutomation] = _vpot;
@@ -1057,3 +1069,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;
+}