add a hack to deal with device discovery race, in which the devices were not actually...
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 19 Feb 2014 17:50:28 +0000 (12:50 -0500)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 19 Feb 2014 18:22:52 +0000 (13:22 -0500)
libs/surfaces/mackie/mackie_control_protocol.cc
libs/surfaces/mackie/mackie_control_protocol.h
libs/surfaces/mackie/strip.cc
libs/surfaces/mackie/strip.h
libs/surfaces/mackie/surface.cc

index e9bef5a9b0bf4b326e24050aed2c8db0df6dfeb8..fc1491d9e86a30b57042c1a55cd62175ec1608c1 100644 (file)
@@ -345,7 +345,9 @@ MackieControlProtocol::switch_banks (uint32_t initial, bool force)
 
        if (_current_initial_bank <= sorted.size()) {
 
-               DEBUG_TRACE (DEBUG::MackieControl, string_compose ("switch to %1, %2, available routes %3\n", _current_initial_bank, strip_cnt, sorted.size()));
+               DEBUG_TRACE (DEBUG::MackieControl, string_compose ("switch to %1, %2, available routes %3 on %4 surfaces\n", 
+                                                                  _current_initial_bank, strip_cnt, sorted.size(),
+                                                                  surfaces.size()));
 
                // link routes to strips
 
@@ -521,11 +523,23 @@ MackieControlProtocol::update_global_led (int id, LedState ls)
        }
 }
 
+void
+MackieControlProtocol::device_ready ()
+{
+       /* this is not required to be called, but for devices which do
+        * handshaking, it can be called once the device has verified the
+        * connection.
+        */
+        
+       DEBUG_TRACE (DEBUG::MackieControl, string_compose ("device ready init (active=%1)\n", active()));
+       update_surfaces ();
+}
+
 // send messages to surface to set controls to correct values
 void 
 MackieControlProtocol::update_surfaces()
 {
-       DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::update_surfaces() init\n");
+       DEBUG_TRACE (DEBUG::MackieControl, string_compose ("MackieControlProtocol::update_surfaces() init (active=%1)\n", active()));
        if (!active()) {
                return;
        }
index e1a71a2460fc04f01089dd61242666749a72e577..fc965d868b2d6f83f2591c6e5655693d0303d290 100644 (file)
@@ -119,6 +119,8 @@ class MackieControlProtocol
        const Mackie::DeviceInfo& device_info() const { return _device_info; }
        Mackie::DeviceProfile& device_profile() { return _device_profile; }
 
+        void device_ready ();
+
        int set_active (bool yn);
        int  set_device (const std::string&);
         void set_profile (const std::string&);
index ef4447d900906d6a92f34957de7e1523a35b2014..1893e31b8dbf6610aa59341e4910bdf0a81449b1 100644 (file)
@@ -626,13 +626,22 @@ Strip::do_parameter_display (AutomationType type, float val)
        }
 }
 
+void
+Strip::handle_fader_touch (Fader& fader, bool touch_on)
+{
+       if (touch_on) {
+               fader.start_touch (_surface->mcp().transport_frame());
+       } else {
+               fader.stop_touch (_surface->mcp().transport_frame(), false);
+       }
+}
+
 void
 Strip::handle_fader (Fader& fader, float position)
 {
        DEBUG_TRACE (DEBUG::MackieControl, string_compose ("fader to %1\n", position));
 
        fader.set_value (position);
-       fader.start_touch (_surface->mcp().transport_frame());
        queue_display_reset (2000);
 
        // must echo bytes back to slider now, because
index 225783d0fe36b28e6eb7f73f96959116d20adfce..c330e0e54db3a99622c609f129dc62952b5d43bf 100644 (file)
@@ -61,6 +61,7 @@ public:
 
        void handle_button (Button&, ButtonState bs);
        void handle_fader (Fader&, float position);
+       void handle_fader_touch (Fader&, bool touch_on);
        void handle_pot (Pot&, float delta);
 
        void periodic (uint64_t now_usecs);
index 694c73b1bcb638f49bb3772bceeb6a55159f33cb..09c5fff051dad322c559fb081a5d0478cdf3f7c3 100644 (file)
@@ -369,7 +369,7 @@ Surface::connect_to_signals ()
                p->controller.connect_same_thread (*this, boost::bind (&Surface::handle_midi_controller_message, this, _1, _2));
                /* Button messages are NoteOn */
                p->note_on.connect_same_thread (*this, boost::bind (&Surface::handle_midi_note_on_message, this, _1, _2));
-               /* Button messages are NoteOn. libmidi++ sends note-on w/velocity = 0 as note-off so catch them too */
+               /* Button messages are NoteOn but libmidi++ sends note-on w/velocity = 0 as note-off so catch them too */
                p->note_off.connect_same_thread (*this, boost::bind (&Surface::handle_midi_note_on_message, this, _1, _2));
                /* Fader messages are Pitchbend */
                uint32_t i;
@@ -386,7 +386,7 @@ Surface::connect_to_signals ()
 void
 Surface::handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t pb, uint32_t fader_id)
 {
-       /* Pitchbend messages are fader messages. Nothing in the data we get
+       /* Pitchbend messages are fader position messages. Nothing in the data we get
         * from the MIDI::Parser conveys the fader ID, which was given by the
         * channel ID in the status byte.
         *
@@ -394,7 +394,6 @@ Surface::handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t pb, uin
         * when we connected to the per-channel pitchbend events.
         */
 
-
        DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Surface::handle_midi_pitchbend_message on port %3, fader = %1 value = %2\n",
                                                           fader_id, pb, _number));
        
@@ -429,6 +428,28 @@ Surface::handle_midi_note_on_message (MIDI::Parser &, MIDI::EventTwoBytes* ev)
                turn_it_on ();
        }
 
+       /* fader touch sense is given by "buttons" 0xe..0xe7 and 0xe8 for the
+        * master. 
+        */
+
+       if (ev->note_number >= 0xE0 && ev->note_number <= 0xE8) {
+               Fader* fader = faders[ev->note_number];
+
+               DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Surface: fader touch message, fader = %1\n", fader));
+
+               if (fader) {
+
+                       Strip* strip = dynamic_cast<Strip*> (&fader->group());
+
+                       if (ev->velocity > 64) {
+                               strip->handle_fader_touch (*fader, true);
+                       } else {
+                               strip->handle_fader_touch (*fader, false);
+                       }
+               }
+               return;
+       }
+
        Button* button = buttons[ev->note_number];
 
        if (button) {
@@ -516,8 +537,10 @@ Surface::handle_midi_sysex (MIDI::Parser &, MIDI::byte * raw_bytes, size_t count
                   LCP: Connection Challenge 
                */
                if (bytes[4] == 0x10 || bytes[4] == 0x11) {
+                       DEBUG_TRACE (DEBUG::MackieControl, "Logic Control Device connection challenge\n");
                        write_sysex (host_connection_query (bytes));
                } else {
+                       DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Mackie Control Device ready, current status = %1\n", _active));
                        if (!_active) {
                                turn_it_on ();
                        }
@@ -525,6 +548,7 @@ Surface::handle_midi_sysex (MIDI::Parser &, MIDI::byte * raw_bytes, size_t count
                break;
 
        case 0x03: /* LCP Connection Confirmation */
+               DEBUG_TRACE (DEBUG::MackieControl, "Logic Control Device confirms connection, ardour replies\n");
                if (bytes[4] == 0x10 || bytes[4] == 0x11) {
                        write_sysex (host_connection_confirmation (bytes));
                        _active = true;
@@ -532,6 +556,7 @@ Surface::handle_midi_sysex (MIDI::Parser &, MIDI::byte * raw_bytes, size_t count
                break;
 
        case 0x04: /* LCP: Confirmation Denied */
+               DEBUG_TRACE (DEBUG::MackieControl, "Logic Control Device denies connection\n");
                _active = false;
                break;
        default:
@@ -610,6 +635,8 @@ Surface::turn_it_on ()
 
        _active = true;
 
+       _mcp.device_ready ();
+
        for (Strips::iterator s = strips.begin(); s != strips.end(); ++s) {
                (*s)->notify_all ();
        }
@@ -739,6 +766,8 @@ Surface::map_routes (const vector<boost::shared_ptr<Route> >& routes)
        vector<boost::shared_ptr<Route> >::const_iterator r;
        Strips::iterator s = strips.begin();
 
+       DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Mapping %1 routes", routes.size()));
+
        for (r = routes.begin(); r != routes.end() && s != strips.end(); ++s) {
 
                /* don't try to assign routes to a locked strip. it won't