remove unused member
[ardour.git] / libs / surfaces / faderport8 / faderport8.cc
index 94fe52b78c6a41fb202e9b9568dee3717b18519d..5e5cf498f739ed0d2b0037f1f3a9157231d9e38e 100644 (file)
@@ -1,20 +1,21 @@
 /*
- * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
- * Copyright (C) 2015 Paul Davis
+ * Copyright (C) 2017-2018 Ben Loftis <ben@harrisonconsoles.com>
+ * Copyright (C) 2017-2018 Robin Gareus <robin@gareus.org>
+ * Copyright (C) 2017 Paul Davis <paul@linuxaudiosystems.com>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include <cstdlib>
@@ -37,6 +38,7 @@
 #include "ardour/debug.h"
 #include "ardour/midi_track.h"
 #include "ardour/midiport_manager.h"
+#include "ardour/panner_shell.h"
 #include "ardour/plugin.h"
 #include "ardour/plugin_insert.h"
 #include "ardour/processor.h"
@@ -88,6 +90,8 @@ debug_2byte_msg (std::string const& msg, int b0, int b1)
 FaderPort8::FaderPort8 (Session& s)
 #ifdef FADERPORT16
        : ControlProtocol (s, _("PreSonus FaderPort16"))
+#elif defined FADERPORT2
+       : ControlProtocol (s, _("PreSonus FaderPort2"))
 #else
        : ControlProtocol (s, _("PreSonus FaderPort8"))
 #endif
@@ -106,6 +110,7 @@ FaderPort8::FaderPort8 (Session& s)
        , gui (0)
        , _link_enabled (false)
        , _link_locked (false)
+       , _chan_locked (false)
        , _clock_mode (1)
        , _scribble_mode (2)
        , _two_line_text (false)
@@ -115,11 +120,14 @@ FaderPort8::FaderPort8 (Session& s)
        boost::shared_ptr<ARDOUR::Port> outp;
 
 #ifdef FADERPORT16
-       inp  = AudioEngine::instance()->register_input_port (DataType::MIDI, "FaderPort8 Recv", true);
-       outp = AudioEngine::instance()->register_output_port (DataType::MIDI, "FaderPort8 Send", true);
-#else
        inp  = AudioEngine::instance()->register_input_port (DataType::MIDI, "FaderPort16 Recv", true);
        outp = AudioEngine::instance()->register_output_port (DataType::MIDI, "FaderPort16 Send", true);
+#elif defined FADERPORT2
+       inp  = AudioEngine::instance()->register_input_port (DataType::MIDI, "FaderPort2 Recv", true);
+       outp = AudioEngine::instance()->register_output_port (DataType::MIDI, "FaderPort2 Send", true);
+#else
+       inp  = AudioEngine::instance()->register_input_port (DataType::MIDI, "FaderPort8 Recv", true);
+       outp = AudioEngine::instance()->register_output_port (DataType::MIDI, "FaderPort8 Send", true);
 #endif
        _input_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(inp);
        _output_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(outp);
@@ -129,11 +137,14 @@ FaderPort8::FaderPort8 (Session& s)
        }
 
 #ifdef FADERPORT16
-       _input_bundle.reset (new ARDOUR::Bundle (_("FaderPort8 (Receive)"), true));
-       _output_bundle.reset (new ARDOUR::Bundle (_("FaderPort8 (Send) "), false));
-#else
        _input_bundle.reset (new ARDOUR::Bundle (_("FaderPort16 (Receive)"), true));
-       _output_bundle.reset (new ARDOUR::Bundle (_("FaderPort16 (Send) "), false));
+       _output_bundle.reset (new ARDOUR::Bundle (_("FaderPort16 (Send)"), false));
+#elif defined FADERPORT2
+       _input_bundle.reset (new ARDOUR::Bundle (_("FaderPort2 (Receive)"), true));
+       _output_bundle.reset (new ARDOUR::Bundle (_("FaderPort2 (Send)"), false));
+#else
+       _input_bundle.reset (new ARDOUR::Bundle (_("FaderPort8 (Receive)"), true));
+       _output_bundle.reset (new ARDOUR::Bundle (_("FaderPort8 (Send)"), false));
 #endif
 
        _input_bundle->add_channel (
@@ -308,7 +319,7 @@ FaderPort8::close ()
        DEBUG_TRACE (DEBUG::FaderPort8, "FaderPort8::close\n");
        stop_midi_handling ();
        session_connections.drop_connections ();
-       automation_state_connections.drop_connections ();
+       route_state_connections.drop_connections ();
        assigned_stripable_connections.drop_connections ();
        _assigned_strips.clear ();
        drop_ctrl_connections ();
@@ -578,24 +589,24 @@ FaderPort8::controller_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb)
 {
        debug_2byte_msg ("CC", tb->controller_number, tb->value);
        /* encoder
-        * FaderPort8:
-        *    val Bit 7 = direction, Bits 0-6 = number of steps
-        * FaderPort16:
-        *    val Bit 6 = direction, Bits 0-5 = number of steps
+        *  val Bit 6 = direction, Bits 0-5 = number of steps
         */
-#ifdef FADERPORT16
-       static const uint8_t dir_mask = 0x20;
-       static const uint8_t step_mask = 0x1f;
-#else
        static const uint8_t dir_mask = 0x40;
        static const uint8_t step_mask = 0x3f;
-#endif
 
        if (tb->controller_number == 0x3c) {
                encoder_navigate (tb->value & dir_mask ? true : false, tb->value & step_mask);
        }
        if (tb->controller_number == 0x10) {
+#ifdef FADERPORT2
+               if (_ctrls.nav_mode() == NavPan) {
+                       encoder_parameter (tb->value & dir_mask ? true : false, tb->value & step_mask);
+               } else {
+                       encoder_navigate (tb->value & dir_mask ? true : false, tb->value & step_mask);
+               }
+#else
                encoder_parameter (tb->value & dir_mask ? true : false, tb->value & step_mask);
+#endif
        }
 }
 
@@ -605,7 +616,7 @@ FaderPort8::note_on_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb)
        debug_2byte_msg ("ON", tb->note_number, tb->velocity);
 
        /* fader touch */
-#ifdef FaderPort16
+#ifdef FADERPORT16
        static const uint8_t touch_id_uppper = 0x77;
 #else
        static const uint8_t touch_id_uppper = 0x6f;
@@ -649,7 +660,12 @@ FaderPort8::note_off_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb)
 {
        debug_2byte_msg ("OF", tb->note_number, tb->velocity);
 
-       if (tb->note_number >= 0x68 && tb->note_number <= 0x6f) {
+#ifdef FADERPORT16
+       static const uint8_t touch_id_uppper = 0x77;
+#else
+       static const uint8_t touch_id_uppper = 0x6f;
+#endif
+       if (tb->note_number >= 0x68 && tb->note_number <= touch_id_uppper) {
                // fader touch
                _ctrls.midi_touch (tb->note_number - 0x68, tb->velocity);
                return;
@@ -742,9 +758,11 @@ FaderPort8::get_state ()
        child->add_child_nocopy (boost::shared_ptr<ARDOUR::Port>(_output_port)->get_state());
        node.add_child_nocopy (*child);
 
+#ifndef FADERPORT2
        node.set_property (X_("clock-mode"), _clock_mode);
        node.set_property (X_("scribble-mode"), _scribble_mode);
        node.set_property (X_("two-line-text"), _two_line_text);
+#endif
 
        for (UserActionMap::const_iterator i = _user_action_map.begin (); i != _user_action_map.end (); ++i) {
                if (i->second.empty()) {
@@ -941,7 +959,7 @@ FaderPort8::filter_stripables (StripableList& strips) const
                        break;
                default:
                        assert (0);
-                       // fall through
+                       /* fallthrough */
                case MixAll:
                        allow_master = true;
                        flt = &flt_all;
@@ -976,6 +994,16 @@ FaderPort8::assign_stripables (bool select_only)
                set_periodic_display_mode (FP8Strip::Stripables);
        }
 
+#ifdef FADERPORT2
+       boost::shared_ptr<Stripable> s = first_selected_stripable();
+       if (s) {
+               _ctrls.strip(0).set_stripable (s, _ctrls.fader_mode() == ModePan);
+       } else {
+               _ctrls.strip(0).unset_controllables ( FP8Strip::CTRL_ALL );
+       }
+       return;
+#endif
+
        int n_strips = strips.size();
        int channel_off = get_channel_off (_ctrls.mix_mode ());
        channel_off = std::min (channel_off, n_strips - N_STRIPS);
@@ -999,10 +1027,17 @@ FaderPort8::assign_stripables (bool select_only)
                (*s)->presentation_info ().PropertyChanged.connect (assigned_stripable_connections, MISSING_INVALIDATOR,
                                boost::bind (&FaderPort8::notify_stripable_property_changed, this, boost::weak_ptr<Stripable> (*s), _1), this);
 
+               if (boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route>(*s)) {
+                       if (r->panner_shell()) {
+                               r->panner_shell()->Changed.connect (assigned_stripable_connections, MISSING_INVALIDATOR,
+                               boost::bind (&FaderPort8::notify_stripable_property_changed, this, boost::weak_ptr<Stripable> (*s), PropertyChange()), this);
+                       }
+               }
+
                if (select_only) {
                        /* used in send mode */
                        _ctrls.strip(id).set_text_line (3, (*s)->name (), true);
-                       _ctrls.strip(id).select_button ().set_color ((*s)->presentation_info ().color());
+                       _ctrls.strip(id).set_select_button_color ((*s)->presentation_info ().color());
                        /* update selection lights */
                        _ctrls.strip(id).select_button ().set_active ((*s)->is_selected ());
                        _ctrls.strip(id).select_button ().set_blinking (*s == first_selected_stripable ());
@@ -1270,6 +1305,7 @@ FaderPort8::build_well_known_processor_ctrls (boost::shared_ptr<Stripable> s, bo
        } else {
                PUSH_BACK_NON_NULL ("Comp In", s->comp_enable_controllable ());
                PUSH_BACK_NON_NULL ("Threshold", s->comp_threshold_controllable ());
+               PUSH_BACK_NON_NULL ("Makeup", s->comp_makeup_controllable ());
                PUSH_BACK_NON_NULL ("Speed", s->comp_speed_controllable ());
                PUSH_BACK_NON_NULL ("Mode", s->comp_mode_controllable ());
        }
@@ -1433,12 +1469,14 @@ FaderPort8::spill_plugins ()
 
        for (uint32_t i = 0; 0 != (proc = r->nth_plugin (i)); ++i) {
                if (!proc->display_to_user ()) {
+                       continue;
+               }
 #ifdef MIXBUS
-                       boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (proc);
-                       if (pi->is_channelstrip ()) // don't skip MB PRE
-#endif
+               /* don't show channelstrip plugins, use "well known" */
+               if (boost::dynamic_pointer_cast<PluginInsert> (proc)->is_channelstrip ()) {
                        continue;
                }
+#endif
                int n_controls = 0;
                set<Evoral::Parameter> p = proc->what_can_be_automated ();
                for (set<Evoral::Parameter>::iterator j = p.begin(); j != p.end(); ++j) {
@@ -1745,7 +1783,7 @@ FaderPort8::notify_fader_mode_changed ()
                        break;
        }
        assign_strips ();
-       notify_automation_mode_changed ();
+       notify_route_state_changed ();
 }
 
 void
@@ -1798,7 +1836,11 @@ FaderPort8::notify_stripable_property_changed (boost::weak_ptr<Stripable> ws, co
        uint8_t id = _assigned_strips[s];
 
        if (what_changed.contains (Properties::color)) {
-               _ctrls.strip(id).select_button ().set_color (s->presentation_info ().color());
+               _ctrls.strip(id).set_select_button_color (s->presentation_info ().color());
+       }
+
+       if (what_changed.empty ()) {
+               _ctrls.strip(id).set_stripable (s, _ctrls.fader_mode() == ModePan);
        }
 
        if (what_changed.contains (Properties::name)) {
@@ -1817,6 +1859,20 @@ FaderPort8::notify_stripable_property_changed (boost::weak_ptr<Stripable> ws, co
        }
 }
 
+#ifdef FADERPORT2
+void
+FaderPort8::stripable_selection_changed ()
+{
+       if (!_device_active || _chan_locked) {
+               return;
+       }
+       route_state_connections.drop_connections ();
+       assign_stripables (false);
+       subscribe_to_strip_signals ();
+}
+
+#else
+
 void
 FaderPort8::stripable_selection_changed ()
 {
@@ -1826,7 +1882,7 @@ FaderPort8::stripable_selection_changed ()
                 */
                return;
        }
-       automation_state_connections.drop_connections();
+       route_state_connections.drop_connections();
 
        switch (_ctrls.fader_mode ()) {
                case ModePlugins:
@@ -1835,6 +1891,9 @@ FaderPort8::stripable_selection_changed ()
                                int wk = _showing_well_known;
                                drop_ctrl_connections ();
                                select_plugin (wk);
+                       } else if (_proc_params.size() == 0) {
+                               /* selecting plugin, update available */
+                               spill_plugins ();
                        }
                        return;
                case ModeSend:
@@ -1855,21 +1914,34 @@ FaderPort8::stripable_selection_changed ()
                _ctrls.strip(id).select_button ().set_blinking (sel && s == first_selected_stripable ());
        }
 
-       /* track automation-mode of primary selection */
+       subscribe_to_strip_signals ();
+}
+#endif
+
+void
+FaderPort8::subscribe_to_strip_signals ()
+{
+       /* keep track of automation-mode of primary selection, shared buttons */
        boost::shared_ptr<Stripable> s = first_selected_stripable();
        if (s) {
                boost::shared_ptr<AutomationControl> ac;
                ac = s->gain_control();
                if (ac && ac->alist()) {
-                       ac->alist()->automation_state_changed.connect (automation_state_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_automation_mode_changed, this), this);
+                       ac->alist()->automation_state_changed.connect (route_state_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_route_state_changed, this), this);
                }
                ac = s->pan_azimuth_control();
                if (ac && ac->alist()) {
-                       ac->alist()->automation_state_changed.connect (automation_state_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_automation_mode_changed, this), this);
+                       ac->alist()->automation_state_changed.connect (route_state_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_route_state_changed, this), this);
+               }
+#ifdef FADERPORT2
+               ac = s->rec_enable_control();
+               if (ac) {
+                       ac->Changed.connect (route_state_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_route_state_changed, this), this);
                }
+#endif
        }
        /* set lights */
-       notify_automation_mode_changed ();
+       notify_route_state_changed ();
 }
 
 
@@ -1954,6 +2026,12 @@ FaderPort8::select_prev_next (bool next)
 void
 FaderPort8::bank (bool down, bool page)
 {
+#ifdef FADERPORT2
+       // XXX this should preferably be in actions.cc
+       AccessAction ("Editor", down ? "select-prev-stripable" : "select-next-stripable");
+       return;
+#endif
+
        int dt = page ? N_STRIPS : 1;
        if (down) {
                dt *= -1;