push2: connect first selected track to pad port (and disconnect).
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 20 Jun 2016 17:47:45 +0000 (13:47 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 27 Sep 2016 19:59:30 +0000 (14:59 -0500)
Provisional. Lots of (fun) work to do here

libs/surfaces/push2/push2.cc
libs/surfaces/push2/push2.h

index c8ea3ceb4fa0e26fb8ecf8f57c588bf2ab6e6944..f1d37b246cde6d7d76862893e8bab3a4bf95a39f 100644 (file)
@@ -36,6 +36,8 @@
 #include "ardour/debug.h"
 #include "ardour/filesystem_paths.h"
 #include "ardour/midiport_manager.h"
+#include "ardour/midi_track.h"
+#include "ardour/midi_port.h"
 #include "ardour/session.h"
 #include "ardour/tempo.h"
 
@@ -1092,10 +1094,43 @@ void
 Push2::stripable_property_change (PropertyChange const& what_changed, int which)
 {
        if (what_changed.contains (Properties::selected)) {
+               if (!stripable[which]) {
+                       return;
+               }
+
                /* cancel string, which will cause a redraw on the next update
                 * cycle. The redraw will reflect selected status
                 */
+
                mid_layout[which]->set_text (string());
+
+               if (stripable[which]->presentation_info().selected()) {
+
+                       boost::shared_ptr<MidiPort> pad_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(_async_in)->shadow_port();
+                       boost::shared_ptr<Stripable> current_first_selection = first_selected_stripable.lock();
+                       boost::shared_ptr<MidiTrack> mtrack;
+
+                       mtrack = boost::dynamic_pointer_cast<MidiTrack> (current_first_selection);
+
+                       /* disconnect from pad port, if appropriate */
+                       if (mtrack && pad_port) {
+                               cerr << "Disconnect pads from " << mtrack->name() << endl;
+                               mtrack->input()->disconnect (mtrack->input()->nth(0), pad_port->name(), this);
+                       }
+
+                       first_selected_stripable = boost::weak_ptr<Stripable> (stripable[which]);
+
+                       /* now connect the pad port to this (newly) selected midi
+                        * track, if indeed it is
+                        */
+
+                       mtrack = boost::dynamic_pointer_cast<MidiTrack> (stripable[which]);
+
+                       if (mtrack && pad_port) {
+                               cerr << "Reconnect pads to " << mtrack->name() << endl;
+                               mtrack->input()->connect (mtrack->input()->nth (0), pad_port->name(), this);
+                       }
+               }
        }
 }
 
index cc2ff018c4e800b441bdef61d1c4517ee2e00b31..dab96260c62bbbb55ed04c9e054efc64e8507b0d 100644 (file)
@@ -450,6 +450,8 @@ class Push2 : public ARDOUR::ControlProtocol
        void switch_bank (uint32_t base);
 
        bool pad_filter (ARDOUR::MidiBuffer& in, ARDOUR::MidiBuffer& out) const;
+
+       boost::weak_ptr<ARDOUR::Stripable> first_selected_stripable;
 };