add bundle support to push2
authorPaul Davis <paul@linuxaudiosystems.com>
Fri, 8 Jul 2016 21:10:26 +0000 (17:10 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 27 Sep 2016 19:59:30 +0000 (14:59 -0500)
libs/surfaces/push2/push2.cc
libs/surfaces/push2/push2.h

index 60570e5d893d2c24a08712516ca659ff3236ef56..c471049fe61687c09e28fc8a78637b9111b76e91 100644 (file)
@@ -193,8 +193,8 @@ Push2::port_registration_handler ()
        vector<string> in;
        vector<string> out;
 
-       AudioEngine::instance()->get_ports (string_compose (".*%1", input_port_name), DataType::MIDI, PortFlags (IsPhysical|IsOutput), in);
-       AudioEngine::instance()->get_ports (string_compose (".*%1", output_port_name), DataType::MIDI, PortFlags (IsPhysical|IsInput), out);
+       AudioEngine::instance()->get_ports (string_compose (".*%1", input_port_name), DataType::MIDI, PortFlags (IsPhysical|IsOutput|ControlOnly), in);
+       AudioEngine::instance()->get_ports (string_compose (".*%1", output_port_name), DataType::MIDI, PortFlags (IsPhysical|IsInput|ControlOnly), out);
 
        if (!in.empty() && !out.empty()) {
                cerr << "Push2: both ports found\n";
@@ -238,23 +238,68 @@ Push2::open ()
 
        /* setup ports */
 
-       _async_in  = AudioEngine::instance()->register_input_port (DataType::MIDI, X_("push2 in"), true);
-       _async_out = AudioEngine::instance()->register_output_port (DataType::MIDI, X_("push2 out"), true);
+       _async_in  = AudioEngine::instance()->register_input_port (DataType::MIDI, X_("push 2 in"), true);
+       _async_out = AudioEngine::instance()->register_output_port (DataType::MIDI, X_("push 2 out"), true);
 
        if (_async_in == 0 || _async_out == 0) {
                return -1;
        }
 
+       _input_bundle.reset (new ARDOUR::Bundle (_("Push 2 In"), true));
+       _output_bundle.reset (new ARDOUR::Bundle (_("Push 2 Out"), false));
+
+       _input_bundle->add_channel (
+               _async_in->name(),
+               ARDOUR::DataType::MIDI,
+               session->engine().make_port_name_non_relative (_async_in->name())
+               );
+
+       _output_bundle->add_channel (
+               _async_out->name(),
+               ARDOUR::DataType::MIDI,
+               session->engine().make_port_name_non_relative (_async_out->name())
+               );
+
+
        _input_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(_async_in).get();
        _output_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(_async_out).get();
 
-       boost::dynamic_pointer_cast<AsyncMIDIPort> (_async_in)->add_shadow_port (string_compose (_("%1 Pads"), X_("Push 2")), boost::bind (&Push2::pad_filter, this, _1, _2));
+       /* Create a shadow port where, depending on the state of the surface,
+        * we will make pad note on/off events appear. The surface code will
+        * automatically this port to the first selected MIDI track.
+        */
+
+       boost::dynamic_pointer_cast<AsyncMIDIPort>(_async_in)->add_shadow_port (string_compose (_("%1 Pads"), X_("Push 2")), boost::bind (&Push2::pad_filter, this, _1, _2));
+       boost::shared_ptr<MidiPort> shadow_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(_async_in)->shadow_port();
+
+       if (shadow_port) {
+               _output_bundle->add_channel (
+                       shadow_port->name(),
+                       ARDOUR::DataType::MIDI,
+                       session->engine().make_port_name_non_relative (shadow_port->name())
+                       );
+       }
+
+       session->BundleAddedOrRemoved ();
 
        connect_to_parser ();
 
        return 0;
 }
 
+list<boost::shared_ptr<ARDOUR::Bundle> >
+Push2::bundles ()
+{
+       list<boost::shared_ptr<ARDOUR::Bundle> > b;
+
+       if (_input_bundle) {
+               b.push_back (_input_bundle);
+               b.push_back (_output_bundle);
+       }
+
+       return b;
+}
+
 int
 Push2::close ()
 {
index d92bf89755bacca520a438131ee865f6c4fbd88d..6180d66813d1e6ff6bb2b413ba6611f980c4dd89 100644 (file)
@@ -82,6 +82,8 @@ class Push2 : public ARDOUR::ControlProtocol
        static bool probe ();
        static void* request_factory (uint32_t);
 
+       std::list<boost::shared_ptr<ARDOUR::Bundle> > bundles ();
+
        bool has_editor () const { return true; }
        void* get_gui () const;
        void  tear_down_gui ();
@@ -373,6 +375,11 @@ class Push2 : public ARDOUR::ControlProtocol
 
        void build_maps ();
 
+       // Bundle to represent our input ports
+       boost::shared_ptr<ARDOUR::Bundle> _input_bundle;
+       // Bundle to represent our output ports
+       boost::shared_ptr<ARDOUR::Bundle> _output_bundle;
+
        MIDI::Port* _input_port;
        MIDI::Port* _output_port;
        boost::shared_ptr<ARDOUR::Port> _async_in;