MCP: a fistful of improvements. probably best to just try it and see what it broken...
[ardour.git] / libs / surfaces / mackie / strip.cc
index b3e51f5912da679ac1946b198783d72ac66a3cf0..bf3ff0d588fe4dea19269061fe6a8f6e0d6a4416 100644 (file)
@@ -87,12 +87,14 @@ Strip::Strip (Surface& s, const std::string& name, int index, const map<Button::
        _vpot = dynamic_cast<Pot*> (Pot::factory (*_surface, Pot::ID + index, "vpot", *this));
        _meter = dynamic_cast<Meter*> (Meter::factory (*_surface, index, "meter", *this));
 
+#ifndef NDEBUG 
        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 ()
@@ -135,7 +137,7 @@ Strip::add (Control & control)
 }
 
 void
-Strip::set_route (boost::shared_ptr<Route> r)
+Strip::set_route (boost::shared_ptr<Route> r, bool with_messages)
 {
        if (_controls_locked) {
                return;
@@ -214,39 +216,16 @@ Strip::set_route (boost::shared_ptr<Route> r)
                        }
                }
        }
-
-       current_pot_modes.push_back (Input);
-       current_pot_modes.push_back (Output);
-
-       if (_route->nth_send (0) != 0) {
-               current_pot_modes.push_back (Send1);
-       }
-       if (_route->nth_send (1) != 0) {
-               current_pot_modes.push_back (Send2);
-       }
-       if (_route->nth_send (2) != 0) {
-               current_pot_modes.push_back (Send3);
-       }
-       if (_route->nth_send (3) != 0) {
-               current_pot_modes.push_back (Send4);
-       }
-       if (_route->nth_send (4) != 0) {
-               current_pot_modes.push_back (Send5);
-       }
-       if (_route->nth_send (5) != 0) {
-               current_pot_modes.push_back (Send6);
-       }
-       if (_route->nth_send (6) != 0) {
-               current_pot_modes.push_back (Send7);
-       }
-       if (_route->nth_send (7) != 0) {
-               current_pot_modes.push_back (Send8);
-       }
 }
 
 void 
 Strip::notify_all()
 {
+       if (!_route) {
+               zero ();
+               return;
+       }
+
        notify_solo_changed ();
        notify_mute_changed ();
        notify_gain_changed ();
@@ -299,8 +278,6 @@ Strip::notify_route_deleted ()
 void 
 Strip::notify_gain_changed (bool force_update)
 {
-       DEBUG_TRACE (DEBUG::MackieControl, string_compose ("gain changed for strip %1, flip mode %2\n", _index, _surface->mcp().flip_mode()));
-
        if (_route) {
                
                Control* control;
@@ -311,35 +288,29 @@ Strip::notify_gain_changed (bool force_update)
                        control = _fader;
                }
 
-               if (!control->in_use()) {
-
-                       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()) {
-                                       _surface->write (_vpot->set_all (normalized_position, true, Pot::wrap));
-                                       do_parameter_display (GainAutomation, gain_coefficient);
-                               } else {
-                                       _surface->write (_fader->set_position (normalized_position));
-                                       do_parameter_display (GainAutomation, gain_coefficient);
+               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 (!control->in_use()) {
+                                       _surface->write (_vpot->set (normalized_position, true, Pot::wrap));
                                }
-
-                               queue_display_reset (2000);
-                               _last_gain_position_written = normalized_position;
-                               
+                               do_parameter_display (GainAutomation, gain_coefficient);
                        } else {
-                               DEBUG_TRACE (DEBUG::MackieControl, "value is stale, no message sent\n");
+                               if (!control->in_use()) {
+                                       _surface->write (_fader->set_position (normalized_position));
+                               }
+                               do_parameter_display (GainAutomation, gain_coefficient);
                        }
-               } else {
-                       DEBUG_TRACE (DEBUG::MackieControl, "fader in use, no message sent\n");
+
+                       queue_display_reset (2000);
+                       _last_gain_position_written = normalized_position;
                }
-       } else {
-               DEBUG_TRACE (DEBUG::MackieControl, "no route or no fader\n");
        }
 }
 
@@ -359,7 +330,7 @@ Strip::notify_property_changed (const PropertyChange& what_changed)
                } else {
                        line1 = PBD::short_version (fullname, 6);
                }
-               
+
                _surface->write (display (0, line1));
        }
 }
@@ -400,7 +371,7 @@ Strip::notify_panner_azi_changed (bool force_update)
                                        _surface->write (_fader->set_position (pos));
                                        do_parameter_display (PanAzimuthAutomation, pos);
                                } else {
-                                       _surface->write (_vpot->set_all (pos, true, Pot::dot));
+                                       _surface->write (_vpot->set (pos, true, Pot::dot));
                                        do_parameter_display (PanAzimuthAutomation, pos);
                                }
 
@@ -447,7 +418,7 @@ Strip::notify_panner_width_changed (bool force_update)
                                        _surface->write (_fader->set_position (pos));
                                        do_parameter_display (PanWidthAutomation, pos);
                                } else {
-                                       _surface->write (_vpot->set_all (pos, true, Pot::dot));
+                                       _surface->write (_vpot->set (pos, true, Pot::spread));
                                        do_parameter_display (PanWidthAutomation, pos);
                                }
 
@@ -723,19 +694,15 @@ Strip::update_meter ()
        }
 }
 
-MidiByteArray
+void
 Strip::zero ()
 {
-       MidiByteArray retval;
-
        for (Group::Controls::const_iterator it = _controls.begin(); it != _controls.end(); ++it) {
-               retval << (*it)->zero ();
+               _surface->write ((*it)->zero ());
        }
 
-       retval << blank_display (0);
-       retval << blank_display (1);
-       
-       return retval;
+       _surface->write (blank_display (0));
+       _surface->write (blank_display (1));
 }
 
 MidiByteArray
@@ -776,8 +743,6 @@ Strip::display (uint32_t line_number, const std::string& line)
        // sysex trailer
        retval << MIDI::eox;
        
-       DEBUG_TRACE (DEBUG::MackieControl, string_compose ("MackieMidiBuilder::strip_display midi: %1\n", retval));
-
        return retval;
 }
 
@@ -853,6 +818,14 @@ Strip::flip_mode_changed (bool notify)
                return;
        }
 
+       if (_surface->mcp().flip_mode()) {
+               /* flip mode is on - save what it used to be */
+               _preflip_vpot_mode = _vpot_mode;
+       } else {
+               /* flip mode is off - restore flip mode to what it used to be */
+               _vpot_mode = _preflip_vpot_mode;
+       }
+
        boost::shared_ptr<AutomationControl> fader_controllable = _fader->control ();
        boost::shared_ptr<AutomationControl> vpot_controllable = _vpot->control ();
 
@@ -891,7 +864,12 @@ Strip::clear_display_reset ()
 void
 Strip::reset_display ()
 {
-       _surface->write (display (1, vpot_mode_string()));
+       if (_route) {
+               _surface->write (display (1, vpot_mode_string()));
+       } else {
+               _surface->write (blank_display (1));
+       }
+               
        clear_display_reset ();
 }
                         
@@ -981,7 +959,7 @@ Strip::next_pot_mode ()
                /* 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"));
-               queue_display_reset (2000);
+               queue_display_reset (1000);
                return;
        }
 
@@ -1040,13 +1018,11 @@ Strip::set_vpot_mode (PotMode m)
                                if (pannable) {
                                        _fader->set_control (pannable->pan_azimuth_control);
                                }
-                               _vpot->set_mode (Pot::boost_cut);
                                _vpot_mode = Gain;
                        } else {
                                /* gain to fader, pan azi to vpot */
                                _fader->set_control (_route->gain_control());
                                if (pannable) {
-                                       _vpot->set_mode (Pot::dot);
                                        _vpot->set_control (pannable->pan_azimuth_control);
                                }
                        }
@@ -1061,13 +1037,11 @@ Strip::set_vpot_mode (PotMode m)
                                if (pannable) {
                                        _fader->set_control (pannable->pan_width_control);
                                }
-                               _vpot->set_mode (Pot::boost_cut);
                                _vpot_mode = Gain;
                        } else {
                                /* gain to fader, pan width to vpot */
                                _fader->set_control (_route->gain_control());
                                if (pannable) {
-                                       _vpot->set_mode (Pot::dot);
                                        _vpot->set_control (pannable->pan_width_control);
                                }
                        }