2 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
3 * Copyright (C) 2015 Paul Davis
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #include "pbd/error.h"
27 #include "pbd/failed_constructor.h"
28 #include "pbd/pthread_utils.h"
29 #include "pbd/compose.h"
30 #include "pbd/xml++.h"
32 #include "midi++/port.h"
34 #include "ardour/audioengine.h"
35 #include "ardour/audio_track.h"
36 #include "ardour/bundle.h"
37 #include "ardour/debug.h"
38 #include "ardour/midi_track.h"
39 #include "ardour/midiport_manager.h"
40 #include "ardour/plugin_insert.h"
41 #include "ardour/processor.h"
42 #include "ardour/rc_configuration.h"
43 #include "ardour/route.h"
44 #include "ardour/session.h"
45 #include "ardour/session_configuration.h"
46 #include "ardour/vca.h"
48 #include "faderport8.h"
50 using namespace ARDOUR;
51 using namespace ArdourSurface;
55 using namespace ArdourSurface::FP8Types;
59 #include "pbd/abstract_ui.cc" // instantiate template
62 //#define VERBOSE_DEBUG
66 debug_2byte_msg (std::string const& msg, int b0, int b1)
69 if (DEBUG_ENABLED(DEBUG::FaderPort8)) {
71 DEBUG_STR_APPEND(a, "RECV: ");
72 DEBUG_STR_APPEND(a, msg);
73 DEBUG_STR_APPEND(a,' ');
74 DEBUG_STR_APPEND(a,hex);
75 DEBUG_STR_APPEND(a,"0x");
76 DEBUG_STR_APPEND(a, b0);
77 DEBUG_STR_APPEND(a,' ');
78 DEBUG_STR_APPEND(a,"0x");
79 DEBUG_STR_APPEND(a, b1);
80 DEBUG_STR_APPEND(a,'\n');
81 DEBUG_TRACE (DEBUG::FaderPort8, DEBUG_STR(a).str());
86 FaderPort8::FaderPort8 (Session& s)
87 : ControlProtocol (s, _("PreSonus FaderPort8"))
88 , AbstractUI<FaderPort8Request> (name())
89 , _connection_state (ConnectionState (0))
90 , _device_active (false)
95 , _blink_onoff (false)
97 , _shift_pressed (false)
100 boost::shared_ptr<ARDOUR::Port> inp;
101 boost::shared_ptr<ARDOUR::Port> outp;
103 inp = AudioEngine::instance()->register_input_port (DataType::MIDI, "FaderPort8 Recv", true);
104 outp = AudioEngine::instance()->register_output_port (DataType::MIDI, "FaderPort8 Send", true);
105 _input_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(inp);
106 _output_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(outp);
108 if (_input_port == 0 || _output_port == 0) {
109 throw failed_constructor();
112 _input_bundle.reset (new ARDOUR::Bundle (_("FaderPort8 (Receive)"), true));
113 _output_bundle.reset (new ARDOUR::Bundle (_("FaderPort8 (Send) "), false));
115 _input_bundle->add_channel (
117 ARDOUR::DataType::MIDI,
118 session->engine().make_port_name_non_relative (inp->name())
121 _output_bundle->add_channel (
123 ARDOUR::DataType::MIDI,
124 session->engine().make_port_name_non_relative (outp->name())
127 ARDOUR::AudioEngine::instance()->PortConnectedOrDisconnected.connect (port_connection, MISSING_INVALIDATOR, boost::bind (&FaderPort8::connection_handler, this, _1, _2, _3, _4, _5), this);
129 StripableSelectionChanged.connect (selection_connection, MISSING_INVALIDATOR, boost::bind (&FaderPort8::gui_track_selection_changed, this), this);
132 _ctrls.FaderModeChanged.connect_same_thread (modechange_connections, boost::bind (&FaderPort8::notify_fader_mode_changed, this));
133 _ctrls.MixModeChanged.connect_same_thread (modechange_connections, boost::bind (&FaderPort8::assign_strips, this, true));
136 FaderPort8::~FaderPort8 ()
139 stop_midi_handling ();
143 DEBUG_TRACE (DEBUG::FaderPort8, string_compose ("unregistering input port %1\n", boost::shared_ptr<ARDOUR::Port>(_input_port)->name()));
144 AudioEngine::instance()->unregister_port (_input_port);
145 _input_port.reset ();
149 _output_port->drain (10000, 250000); /* check every 10 msecs, wait up to 1/4 second for the port to drain */
150 DEBUG_TRACE (DEBUG::FaderPort8, string_compose ("unregistering output port %1\n", boost::shared_ptr<ARDOUR::Port>(_output_port)->name()));
151 AudioEngine::instance()->unregister_port (_output_port);
152 _output_port.reset ();
157 /* stop event loop */
158 DEBUG_TRACE (DEBUG::FaderPort8, "BaseUI::quit ()\n");
162 /* ****************************************************************************
167 FaderPort8::request_factory (uint32_t num_requests)
169 /* AbstractUI<T>::request_buffer_factory() is a template method only
170 * instantiated in this source module. To provide something visible for
171 * use in the interface/descriptor, we have this static method that is
174 return request_buffer_factory (num_requests);
178 FaderPort8::do_request (FaderPort8Request* req)
180 if (req->type == CallSlot) {
181 call_slot (MISSING_INVALIDATOR, req->the_slot);
182 } else if (req->type == Quit) {
195 FaderPort8::thread_init ()
197 struct sched_param rtparam;
199 pthread_set_name (event_loop_name().c_str());
201 PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048);
202 ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128);
204 memset (&rtparam, 0, sizeof (rtparam));
205 rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */
207 if (pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam) != 0) {
208 // do we care? not particularly.
213 FaderPort8::periodic ()
215 /* prepare TC display -- handled by stripable Periodic () */
216 if (_ctrls.display_timecode ()) {
217 // TODO allow BBT, HHMMSS
218 // used in FP8Strip::periodic_update_timecode
220 session->timecode_time (TC);
221 _timecode = Timecode::timecode_format_time(TC);
226 /* update stripables */
232 FaderPort8::blink_it ()
234 _blink_onoff = !_blink_onoff;
235 BlinkIt (_blink_onoff);
239 /* ****************************************************************************
240 * Port and Signal Connection Management
243 FaderPort8::set_active (bool yn)
245 DEBUG_TRACE (DEBUG::FaderPort8, string_compose("set_active init with yn: '%1'\n", yn));
247 if (yn == active()) {
252 /* start event loop */
254 connect_session_signals ();
260 ControlProtocol::set_active (yn);
261 DEBUG_TRACE (DEBUG::FaderPort8, string_compose("set_active done with yn: '%1'\n", yn));
268 _assigned_strips.clear ();
269 stop_midi_handling ();
270 session_connections.drop_connections ();
271 automation_state_connections.drop_connections ();
272 assigned_stripable_connections.drop_connections ();
273 drop_ctrl_connections ();
274 port_connection.disconnect ();
275 selection_connection.disconnect ();
279 FaderPort8::stop_midi_handling ()
281 _periodic_connection.disconnect ();
282 _blink_connection.disconnect ();
283 midi_connections.drop_connections ();
284 /* Note: the input handler is still active at this point, but we're no
285 * longer connected to any of the parser signals
290 FaderPort8::connected ()
292 DEBUG_TRACE (DEBUG::FaderPort8, "initializing\n");
293 // ideally check firmware version >= 1.01 (USB bcdDevice 0x0101) (vendor 0x194f prod 0x0202)
294 // but we don't have a handle to the underlying USB device here.
296 _channel_off = _plugin_off = _parameter_off = 0;
297 _blink_onoff = false;
299 _shift_pressed = false;
301 start_midi_handling ();
302 _ctrls.initialize ();
304 /* highlight bound user-actions */
305 for (FP8Controls::UserButtonMap::const_iterator i = _ctrls.user_buttons ().begin ();
306 i != _ctrls.user_buttons ().end (); ++i) {
307 _ctrls.button (i->first).set_active (! _user_action_map[i->first].empty ());
309 /* shift button lights */
310 tx_midi3 (0x90, 0x06, 0x00);
311 tx_midi3 (0x90, 0x46, 0x00);
313 send_session_state ();
314 assign_strips (true);
316 Glib::RefPtr<Glib::TimeoutSource> blink_timer =
317 Glib::TimeoutSource::create (200);
318 _blink_connection = blink_timer->connect (sigc::mem_fun (*this, &FaderPort8::blink_it));
319 blink_timer->attach (main_loop()->get_context());
321 Glib::RefPtr<Glib::TimeoutSource> periodic_timer =
322 Glib::TimeoutSource::create (100);
323 _periodic_connection = periodic_timer->connect (sigc::mem_fun (*this, &FaderPort8::periodic));
324 periodic_timer->attach (main_loop()->get_context());
328 FaderPort8::disconnected ()
330 stop_midi_handling ();
331 for (uint8_t id = 0; id < 8; ++id) {
332 _ctrls.strip(id).unset_controllables ();
337 FaderPort8::connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn)
340 DEBUG_TRACE (DEBUG::FaderPort8, "FaderPort8::connection_handler: start\n");
342 if (!_input_port || !_output_port) {
346 string ni = ARDOUR::AudioEngine::instance()->make_port_name_non_relative (boost::shared_ptr<ARDOUR::Port>(_input_port)->name());
347 string no = ARDOUR::AudioEngine::instance()->make_port_name_non_relative (boost::shared_ptr<ARDOUR::Port>(_output_port)->name());
349 if (ni == name1 || ni == name2) {
351 _connection_state |= InputConnected;
353 _connection_state &= ~InputConnected;
355 } else if (no == name1 || no == name2) {
357 _connection_state |= OutputConnected;
359 _connection_state &= ~OutputConnected;
363 DEBUG_TRACE (DEBUG::FaderPort8, string_compose ("Connections between %1 and %2 changed, but I ignored it\n", name1, name2));
369 if ((_connection_state & (InputConnected|OutputConnected)) == (InputConnected|OutputConnected)) {
371 /* XXX this is a horrible hack. Without a short sleep here,
372 * something prevents the device wakeup messages from being
373 * sent and/or the responses from being received.
376 DEBUG_TRACE (DEBUG::FaderPort8, "device now connected for both input and output\n");
378 _device_active = true;
381 DEBUG_TRACE (DEBUG::FaderPort8, "Device disconnected (input or output or both) or not yet fully connected\n");
383 _device_active = false;
386 ConnectionChange (); /* emit signal for our GUI */
389 DEBUG_TRACE (DEBUG::FaderPort8, "FaderPort8::connection_handler: end\n");
392 return true; /* connection status changed */
395 list<boost::shared_ptr<ARDOUR::Bundle> >
396 FaderPort8::bundles ()
398 list<boost::shared_ptr<ARDOUR::Bundle> > b;
401 b.push_back (_input_bundle);
402 b.push_back (_output_bundle);
408 /* ****************************************************************************
412 FaderPort8::midi_input_handler (Glib::IOCondition ioc, boost::weak_ptr<ARDOUR::AsyncMIDIPort> wport)
414 boost::shared_ptr<AsyncMIDIPort> port (wport.lock());
421 DEBUG_TRACE (DEBUG::FaderPort8, string_compose ("something happend on %1\n", boost::shared_ptr<MIDI::Port>(port)->name()));
432 DEBUG_TRACE (DEBUG::FaderPort8, string_compose ("data available on %1\n", boost::shared_ptr<MIDI::Port>(port)->name()));
434 framepos_t now = session->engine().sample_time();
442 FaderPort8::start_midi_handling ()
444 _input_port->parser()->sysex.connect_same_thread (midi_connections, boost::bind (&FaderPort8::sysex_handler, this, _1, _2, _3));
445 _input_port->parser()->poly_pressure.connect_same_thread (midi_connections, boost::bind (&FaderPort8::polypressure_handler, this, _1, _2));
446 for (uint8_t i = 0; i < 16; ++i) {
447 _input_port->parser()->channel_pitchbend[i].connect_same_thread (midi_connections, boost::bind (&FaderPort8::pitchbend_handler, this, _1, i, _2));
449 _input_port->parser()->controller.connect_same_thread (midi_connections, boost::bind (&FaderPort8::controller_handler, this, _1, _2));
450 _input_port->parser()->note_on.connect_same_thread (midi_connections, boost::bind (&FaderPort8::note_on_handler, this, _1, _2));
451 _input_port->parser()->note_off.connect_same_thread (midi_connections, boost::bind (&FaderPort8::note_off_handler, this, _1, _2));
453 /* This connection means that whenever data is ready from the input
454 * port, the relevant thread will invoke our ::midi_input_handler()
455 * method, which will read the data, and invoke the parser.
457 _input_port->xthread().set_receive_handler (sigc::bind (sigc::mem_fun (this, &FaderPort8::midi_input_handler), boost::weak_ptr<AsyncMIDIPort> (_input_port)));
458 _input_port->xthread().attach (main_loop()->get_context());
462 FaderPort8::tx_midi (std::vector<uint8_t> const& d) const
464 /* work around midi buffer overflow for batch changes */
465 if (d.size() == 3 && (d[0] == 0x91 || d[0] == 0x92)) {
466 /* set colors triplet in one go */
467 } else if (d.size() == 3 && (d[0] == 0x93)) {
470 g_usleep (400 * d.size());
473 size_t tx = _output_port->write (&d[0], d.size(), 0);
474 assert (tx == d.size());
477 return _output_port->write (&d[0], d.size(), 0);
481 /* ****************************************************************************
485 FaderPort8::polypressure_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb)
487 debug_2byte_msg ("PP", tb->controller_number, tb->value);
488 // outgoing only (meter)
492 FaderPort8::pitchbend_handler (MIDI::Parser &, uint8_t chan, MIDI::pitchbend_t pb)
494 debug_2byte_msg ("PB", chan, pb);
495 /* fader 0..16368 (0x3ff0 -- 1024 steps) */
496 _ctrls.midi_fader (chan, pb);
500 FaderPort8::controller_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb)
502 debug_2byte_msg ("CC", tb->controller_number, tb->value);
504 // val Bit 7 = direction, Bits 0-6 = number of steps
505 if (tb->controller_number == 0x3c) {
506 encoder_navigate (tb->value & 0x40 ? true : false, tb->value & 0x3f);
508 if (tb->controller_number == 0x10) {
509 encoder_parameter (tb->value & 0x40 ? true : false, tb->value & 0x3f);
514 FaderPort8::note_on_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb)
516 debug_2byte_msg ("ON", tb->note_number, tb->velocity);
519 if (tb->note_number >= 0x68 && tb->note_number <= 0x6f) {
520 _ctrls.midi_touch (tb->note_number - 0x68, tb->velocity);
524 /* special case shift */
525 if (tb->note_number == 0x06 || tb->note_number == 0x46) {
526 _shift_pressed = true;
527 _shift_connection.disconnect ();
530 ShiftButtonChange (false);
531 tx_midi3 (0x90, 0x06, 0x00);
532 tx_midi3 (0x90, 0x46, 0x00);
536 Glib::RefPtr<Glib::TimeoutSource> shift_timer =
537 Glib::TimeoutSource::create (1000);
538 shift_timer->attach (main_loop()->get_context());
539 _shift_connection = shift_timer->connect (sigc::mem_fun (*this, &FaderPort8::shift_timeout));
541 ShiftButtonChange (true);
542 tx_midi3 (0x90, 0x06, 0x7f);
543 tx_midi3 (0x90, 0x46, 0x7f);
547 _ctrls.midi_event (tb->note_number, tb->velocity);
551 FaderPort8::note_off_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb)
553 debug_2byte_msg ("OF", tb->note_number, tb->velocity);
555 if (tb->note_number >= 0x68 && tb->note_number <= 0x6f) {
557 _ctrls.midi_touch (tb->note_number - 0x68, tb->velocity);
561 /* special case shift */
562 if (tb->note_number == 0x06 || tb->note_number == 0x46) {
563 _shift_pressed = false;
567 ShiftButtonChange (false);
568 tx_midi3 (0x90, 0x06, 0x00);
569 tx_midi3 (0x90, 0x46, 0x00);
570 /* just in case this happens concurrently */
571 _shift_connection.disconnect ();
576 bool handled = _ctrls.midi_event (tb->note_number, tb->velocity);
577 /* if Shift key is held while activating an action, don't lock shift. */
578 if (_shift_pressed && handled) {
579 _shift_connection.disconnect ();
585 FaderPort8::sysex_handler (MIDI::Parser &p, MIDI::byte *buf, size_t size)
588 if (DEBUG_ENABLED(DEBUG::FaderPort8)) {
590 DEBUG_STR_APPEND(a, string_compose ("RECV sysex siz=%1", size));
591 for (size_t i=0; i < size; ++i) {
592 DEBUG_STR_APPEND(a,hex);
593 DEBUG_STR_APPEND(a,"0x");
594 DEBUG_STR_APPEND(a,(int)buf[i]);
595 DEBUG_STR_APPEND(a,' ');
597 DEBUG_STR_APPEND(a,'\n');
598 DEBUG_TRACE (DEBUG::FaderPort8, DEBUG_STR(a).str());
603 /* ****************************************************************************
607 FaderPort8::set_button_action (FP8Controls::ButtonId id, bool press, std::string const& action_name)
609 if (_ctrls.user_buttons().find (id) == _ctrls.user_buttons().end ()) {
612 _user_action_map[id].action (press).assign_action (action_name);
614 if (!_device_active) {
617 _ctrls.button (id).set_active (!_user_action_map[id].empty ());
621 FaderPort8::get_button_action (FP8Controls::ButtonId id, bool press)
623 return _user_action_map[id].action(press)._action_name;
626 /* ****************************************************************************
630 FaderPort8::get_state ()
632 DEBUG_TRACE (DEBUG::FaderPort8, "FaderPort8::get_state\n");
633 XMLNode& node (ControlProtocol::get_state());
637 child = new XMLNode (X_("Input"));
638 child->add_child_nocopy (boost::shared_ptr<ARDOUR::Port>(_input_port)->get_state());
639 node.add_child_nocopy (*child);
641 child = new XMLNode (X_("Output"));
642 child->add_child_nocopy (boost::shared_ptr<ARDOUR::Port>(_output_port)->get_state());
643 node.add_child_nocopy (*child);
645 for (UserActionMap::const_iterator i = _user_action_map.begin (); i != _user_action_map.end (); ++i) {
646 if (i->second.empty()) {
650 if (!_ctrls.button_enum_to_name (i->first, name)) {
653 XMLNode* btn = new XMLNode (X_("Button"));
654 btn->add_property (X_("id"), name);
655 if (!i->second.action(true).empty ()) {
656 btn->add_property ("press", i->second.action(true)._action_name);
658 if (!i->second.action(false).empty ()) {
659 btn->add_property ("release", i->second.action(false)._action_name);
661 node.add_child_nocopy (*btn);
668 FaderPort8::set_state (const XMLNode& node, int version)
670 DEBUG_TRACE (DEBUG::FaderPort8, "FaderPort8::set_state\n");
672 XMLNodeConstIterator niter;
673 XMLNode const* child;
675 if (ControlProtocol::set_state (node, version)) {
679 if ((child = node.child (X_("Input"))) != 0) {
680 XMLNode* portnode = child->child (Port::state_node_name.c_str());
682 DEBUG_TRACE (DEBUG::FaderPort8, "FaderPort8::set_state Input\n");
683 boost::shared_ptr<ARDOUR::Port>(_input_port)->set_state (*portnode, version);
687 if ((child = node.child (X_("Output"))) != 0) {
688 XMLNode* portnode = child->child (Port::state_node_name.c_str());
690 DEBUG_TRACE (DEBUG::FaderPort8, "FaderPort8::set_state Output\n");
691 boost::shared_ptr<ARDOUR::Port>(_output_port)->set_state (*portnode, version);
695 _user_action_map.clear ();
696 // TODO: When re-loading state w/o surface re-init becomes possible,
697 // unset lights and reset colors of user buttons.
699 for (XMLNodeList::const_iterator n = node.children().begin(); n != node.children().end(); ++n) {
700 if ((*n)->name() != X_("Button")) {
703 XMLProperty const* prop = (*n)->property (X_("id"));
708 FP8Controls::ButtonId id;
709 if (!_ctrls.button_name_to_enum (prop->value(), id)) {
713 prop = (*n)->property (X_("press"));
715 set_button_action (id, true, prop->value());
717 prop = (*n)->property (X_("release"));
719 set_button_action (id, false, prop->value());
726 /* ****************************************************************************
727 * Stripable Assignment
730 static bool flt_audio_track (boost::shared_ptr<Stripable> s) {
731 return boost::dynamic_pointer_cast<AudioTrack>(s) != 0;
734 static bool flt_midi_track (boost::shared_ptr<Stripable> s) {
735 return boost::dynamic_pointer_cast<MidiTrack>(s) != 0;
738 static bool flt_bus (boost::shared_ptr<Stripable> s) {
739 if (boost::dynamic_pointer_cast<Route>(s) == 0) {
743 if (s->mixbus () == 0) {
747 return boost::dynamic_pointer_cast<Track>(s) == 0;
750 static bool flt_auxbus (boost::shared_ptr<Stripable> s) {
751 if (boost::dynamic_pointer_cast<Route>(s) == 0) {
755 if (s->mixbus () > 0) {
759 return boost::dynamic_pointer_cast<Track>(s) == 0;
762 static bool flt_vca (boost::shared_ptr<Stripable> s) {
763 return boost::dynamic_pointer_cast<VCA>(s) != 0;
766 static bool flt_selected (boost::shared_ptr<Stripable> s) {
767 return s->is_selected ();
770 static bool flt_mains (boost::shared_ptr<Stripable> s) {
771 return (s->is_master() || s->is_monitor());
774 static bool flt_all (boost::shared_ptr<Stripable> s) {
778 static bool flt_rec_armed (boost::shared_ptr<Stripable> s) {
779 boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track>(s);
783 return t->rec_enable_control ()->get_value () > 0.;
786 static bool flt_instrument (boost::shared_ptr<Stripable> s) {
787 boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route>(s);
791 return 0 != r->the_instrument ();
794 struct FP8SortByNewDisplayOrder
797 bool operator () (const boost::shared_ptr<Stripable> & a, const boost::shared_ptr<Stripable> & b) const
799 if (a->presentation_info().flags () == b->presentation_info().flags ()) {
800 return a->presentation_info().order() < b->presentation_info().order();
806 if (a->presentation_info().flags () & ARDOUR::PresentationInfo::VCA) {
810 else if (a->presentation_info().flags () & ARDOUR::PresentationInfo::MasterOut) {
813 else if (a->presentation_info().flags () & ARDOUR::PresentationInfo::Mixbus || a->mixbus()) {
818 if (b->presentation_info().flags () & ARDOUR::PresentationInfo::VCA) {
822 else if (b->presentation_info().flags () & ARDOUR::PresentationInfo::MasterOut) {
825 else if (b->presentation_info().flags () & ARDOUR::PresentationInfo::Mixbus || b->mixbus()) {
831 // this can happen with older MB sessions (no PresentationInfo::Mixbus flag)
832 if (cmp_a == cmp_a) {
833 return a->presentation_info().order() < b->presentation_info().order();
836 return cmp_a < cmp_b;
841 FaderPort8::filter_stripables (StripableList& strips) const
843 typedef bool (*FilterFunction)(boost::shared_ptr<Stripable>);
846 bool allow_master = false;
847 bool allow_monitor = false;
849 switch (_ctrls.mix_mode ()) {
851 flt = &flt_audio_track;
854 flt = &flt_instrument;
863 flt = &flt_midi_track;
871 allow_monitor = true;
875 flt = &flt_rec_armed;
887 session->get_stripables (all);
889 for (StripableList::const_iterator s = all.begin(); s != all.end(); ++s) {
890 if ((*s)->is_auditioner ()) { continue; }
891 if ((*s)->is_hidden ()) { continue; }
893 if (!allow_master && (*s)->is_master ()) { continue; }
894 if (!allow_monitor && (*s)->is_monitor ()) { continue; }
897 strips.push_back (*s);
900 strips.sort (FP8SortByNewDisplayOrder());
903 /* Track/Pan mode: assign stripable to strips */
905 FaderPort8::assign_stripables ()
907 StripableList strips;
908 filter_stripables (strips);
910 set_periodic_display_mode (FP8Strip::Stripables);
912 int n_strips = strips.size();
913 _channel_off = std::min (_channel_off, n_strips - 8);
914 _channel_off = std::max (0, _channel_off);
917 int skip = _channel_off;
918 for (StripableList::const_iterator s = strips.begin(); s != strips.end(); ++s) {
924 _assigned_strips[*s] = id;
925 (*s)->DropReferences.connect (assigned_stripable_connections, MISSING_INVALIDATOR,
926 boost::bind (&FaderPort8::notify_stripable_added_or_removed, this), this);
928 (*s)->PropertyChanged.connect (assigned_stripable_connections, MISSING_INVALIDATOR,
929 boost::bind (&FaderPort8::notify_stripable_property_changed, this, boost::weak_ptr<Stripable> (*s), _1), this);
930 (*s)->presentation_info ().PropertyChanged.connect (assigned_stripable_connections, MISSING_INVALIDATOR,
931 boost::bind (&FaderPort8::notify_stripable_property_changed, this, boost::weak_ptr<Stripable> (*s), _1), this);
933 _ctrls.strip(id).set_stripable (*s, _ctrls.fader_mode() == ModePan);
935 boost::function<void ()> cb (boost::bind (&FaderPort8::select_strip, this, boost::weak_ptr<Stripable> (*s)));
936 _ctrls.strip(id).set_select_cb (cb);
942 for (; id < 8; ++id) {
943 _ctrls.strip(id).unset_controllables();
948 FaderPort8::assign_processor_ctrls ()
950 int n_parameters = _proc_params.size();
951 if (n_parameters == 0) {
952 _ctrls.set_fader_mode (ModeTrack);
955 set_periodic_display_mode (FP8Strip::PluginParam);
957 _parameter_off = std::min (_parameter_off, n_parameters - 8);
958 _parameter_off = std::max (0, _parameter_off);
960 int skip = _parameter_off;
962 for ( std::list <ProcessorCtrl>::iterator i = _proc_params.begin(); i != _proc_params.end(); ++i) {
967 _ctrls.strip(id).unset_controllables (FP8Strip::CTRL_ALL & ~FP8Strip::CTRL_FADER & ~FP8Strip::CTRL_TEXT1);
968 _ctrls.strip(id).set_fader_controllable ((*i).ac);
969 _ctrls.strip(id).set_text_line (0, (*i).name);
976 for (; id < 8; ++id) {
977 _ctrls.strip(id).unset_controllables ();
982 FaderPort8::build_well_known_processor_ctrls (boost::shared_ptr<Stripable> s, bool eq)
984 #define PUSH_BACK_NON_NULL(N, C) do {if (C) { _proc_params.push_back (ProcessorCtrl (N, C)); }} while (0)
986 _proc_params.clear ();
988 int cnt = s->eq_band_cnt();
989 PUSH_BACK_NON_NULL ("Enable", s->eq_enable_controllable ());
990 PUSH_BACK_NON_NULL ("HPF", s->eq_hpf_controllable ());
991 for (int band = 0; band < cnt; ++band) {
992 std::string bn = s->eq_band_name (band);
993 PUSH_BACK_NON_NULL (string_compose ("Gain %1", bn), s->eq_gain_controllable (band));
994 PUSH_BACK_NON_NULL (string_compose ("Freq %1", bn), s->eq_freq_controllable (band));
995 PUSH_BACK_NON_NULL (string_compose ("Band %1", bn), s->eq_q_controllable (band));
996 PUSH_BACK_NON_NULL (string_compose ("Shape %1", bn), s->eq_shape_controllable (band));
999 PUSH_BACK_NON_NULL ("Enable", s->comp_enable_controllable ());
1000 PUSH_BACK_NON_NULL ("Threshold", s->comp_threshold_controllable ());
1001 PUSH_BACK_NON_NULL ("Speed", s->comp_speed_controllable ());
1002 PUSH_BACK_NON_NULL ("Mode", s->comp_mode_controllable ());
1007 FaderPort8::select_plugin (int num)
1009 boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (first_selected_stripable());
1011 _ctrls.set_fader_mode (ModeTrack);
1015 build_well_known_processor_ctrls (r, num == -1);
1016 assign_processor_ctrls ();
1020 boost::shared_ptr<Processor> proc = r->nth_plugin (num);
1022 _ctrls.set_fader_mode (ModeTrack);
1026 // switching to "Mode Track" -> calls FaderPort8::notify_fader_mode_changed()
1027 // which drops the references, disconnects the signal and re-spills tracks
1028 proc->DropReferences.connect (processor_connections, MISSING_INVALIDATOR, boost::bind (&FP8Controls::set_fader_mode, &_ctrls, ModeTrack), this);
1031 _proc_params.clear();
1032 set<Evoral::Parameter> p = proc->what_can_be_automated ();
1033 for (set<Evoral::Parameter>::iterator i = p.begin(); i != p.end(); ++i) {
1034 std::string n = proc->describe_parameter (*i);
1035 if (n == "hidden") {
1038 _proc_params.push_back (ProcessorCtrl (n, proc->automation_control (*i)));
1042 assign_processor_ctrls ();
1045 /* short 4 chars at most */
1046 static std::string plugintype (ARDOUR::PluginType t) {
1063 return enum_2_string (t);
1067 FaderPort8::spill_plugins ()
1069 boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (first_selected_stripable());
1071 _ctrls.set_fader_mode (ModeTrack);
1075 drop_ctrl_connections ();
1077 // switching to "Mode Track" -> calls FaderPort8::notify_fader_mode_changed()
1078 // which drops the references, disconnects the signal and re-spills tracks
1079 r->DropReferences.connect (processor_connections, MISSING_INVALIDATOR, boost::bind (&FP8Controls::set_fader_mode, &_ctrls, ModeTrack), this);
1081 // update when processor change
1082 r->processors_changed.connect (processor_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::spill_plugins, this), this);
1085 boost::shared_ptr<Processor> proc;
1087 std::vector<uint32_t> procs;
1089 for (uint32_t i = 0; 0 != (proc = r->nth_plugin (i)); ++i) {
1090 if (!proc->display_to_user ()) {
1094 set<Evoral::Parameter> p = proc->what_can_be_automated ();
1095 for (set<Evoral::Parameter>::iterator i = p.begin(); i != p.end(); ++i) {
1096 std::string n = proc->describe_parameter (*i);
1097 if (n == "hidden") {
1102 if (n_controls > 0) {
1103 procs.push_back (i);
1107 int n_plugins = procs.size();
1109 bool have_well_known_eq = false;
1110 bool have_well_known_comp = false;
1112 // reserve last slot(s) for "well-known"
1113 if (r->eq_band_cnt() > 0) {
1115 have_well_known_eq = true;
1117 if (r->comp_enable_controllable ()) {
1119 have_well_known_comp = true;
1122 if (n_plugins == 0 && !have_well_known_eq && !have_well_known_comp) {
1123 _ctrls.set_fader_mode (ModeTrack);
1127 set_periodic_display_mode (FP8Strip::PluginSelect);
1129 _plugin_off = std::min (_plugin_off, n_plugins - spillwidth);
1130 _plugin_off = std::max (0, _plugin_off);
1133 for (uint32_t i = _plugin_off; ; ++i) {
1134 if (i >= procs.size()) {
1137 boost::shared_ptr<Processor> proc = r->nth_plugin (procs[i]);
1141 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (proc);
1142 boost::function<void ()> cb (boost::bind (&FaderPort8::select_plugin, this, i));
1144 _ctrls.strip(id).unset_controllables (FP8Strip::CTRL_ALL & ~FP8Strip::CTRL_TEXT & ~FP8Strip::CTRL_SELECT);
1145 _ctrls.strip(id).set_select_cb (cb);
1146 _ctrls.strip(id).select_button ().set_color (0x00ff00ff);
1147 _ctrls.strip(id).select_button ().set_active (true /*proc->enabled()*/);
1148 _ctrls.strip(id).select_button ().set_blinking (false);
1149 _ctrls.strip(id).set_text_line (0, proc->name());
1150 _ctrls.strip(id).set_text_line (1, pi->plugin()->maker());
1151 _ctrls.strip(id).set_text_line (2, plugintype (pi->type()));
1153 if (++id == spillwidth) {
1158 for (; id < spillwidth; ++id) {
1159 _ctrls.strip(id).unset_controllables ();
1162 if (have_well_known_comp) {
1164 boost::function<void ()> cb (boost::bind (&FaderPort8::select_plugin, this, -2));
1165 _ctrls.strip(id).unset_controllables (FP8Strip::CTRL_ALL & ~FP8Strip::CTRL_TEXT & ~FP8Strip::CTRL_SELECT);
1166 _ctrls.strip(id).set_select_cb (cb);
1167 _ctrls.strip(id).select_button ().set_color (0xffff00ff);
1168 _ctrls.strip(id).select_button ().set_active (true);
1169 _ctrls.strip(id).select_button ().set_blinking (false);
1170 _ctrls.strip(id).set_text_line (0, "Comp");
1171 _ctrls.strip(id).set_text_line (1, "Built-In");
1172 _ctrls.strip(id).set_text_line (2, "--");
1175 if (have_well_known_eq) {
1177 boost::function<void ()> cb (boost::bind (&FaderPort8::select_plugin, this, -1));
1178 _ctrls.strip(id).unset_controllables (FP8Strip::CTRL_ALL & ~FP8Strip::CTRL_TEXT & ~FP8Strip::CTRL_SELECT);
1179 _ctrls.strip(id).set_select_cb (cb);
1180 _ctrls.strip(id).select_button ().set_color (0xffff00ff);
1181 _ctrls.strip(id).select_button ().set_active (true);
1182 _ctrls.strip(id).select_button ().set_blinking (false);
1183 _ctrls.strip(id).set_text_line (0, "EQ");
1184 _ctrls.strip(id).set_text_line (1, "Built-In");
1185 _ctrls.strip(id).set_text_line (2, "--");
1192 FaderPort8::assign_sends ()
1194 boost::shared_ptr<Stripable> s = first_selected_stripable();
1196 _ctrls.set_fader_mode (ModeTrack);
1201 while (0 != s->send_level_controllable (n_sends)) {
1205 _ctrls.set_fader_mode (ModeTrack);
1209 drop_ctrl_connections ();
1210 s->DropReferences.connect (processor_connections, MISSING_INVALIDATOR, boost::bind (&FP8Controls::set_fader_mode, &_ctrls, ModeTrack), this);
1212 set_periodic_display_mode (FP8Strip::PluginParam);
1214 _plugin_off = std::min (_plugin_off, n_sends - 8);
1215 _plugin_off = std::max (0, _plugin_off);
1218 int skip = _parameter_off;
1219 for (uint32_t i = _plugin_off; ; ++i) {
1224 boost::shared_ptr<AutomationControl> send = s->send_level_controllable (i);
1229 _ctrls.strip(id).unset_controllables (FP8Strip::CTRL_ALL & ~FP8Strip::CTRL_FADER & ~FP8Strip::CTRL_TEXT1);
1230 _ctrls.strip(id).set_fader_controllable (send);
1231 _ctrls.strip(id).set_text_line (0, s->send_name (i));
1232 //_ctrls.strip(id).set_mute_controllable (s->send_enable_controllable (i)); // XXX TODO MB assign -> select ?
1239 for (; id < 8; ++id) {
1240 _ctrls.strip(id).unset_controllables ();
1245 FaderPort8::set_periodic_display_mode (FP8Strip::DisplayMode m)
1247 for (uint8_t id = 0; id < 8; ++id) {
1248 _ctrls.strip(id).set_periodic_display_mode (m);
1253 FaderPort8::assign_strips (bool reset_bank)
1259 _assigned_strips.clear ();
1260 assigned_stripable_connections.drop_connections ();
1262 FaderMode fadermode = _ctrls.fader_mode ();
1263 switch (fadermode) {
1266 assign_stripables ();
1267 gui_track_selection_changed (); // update selection, automation-state
1270 if (_proc_params.size() > 0) {
1271 assign_processor_ctrls ();
1284 FaderPort8::drop_ctrl_connections ()
1286 _proc_params.clear();
1287 processor_connections.drop_connections ();
1291 FaderPort8::notify_fader_mode_changed ()
1293 FaderMode fadermode = _ctrls.fader_mode ();
1295 boost::shared_ptr<Stripable> s = first_selected_stripable();
1296 if (!s && (fadermode == ModePlugins || fadermode == ModeSend)) {
1297 _ctrls.set_fader_mode (ModeTrack);
1301 drop_ctrl_connections ();
1303 switch (fadermode) {
1311 // force unset rec-arm button, see also FaderPort8::button_arm
1312 _ctrls.button (FP8Controls::BtnArm).set_active (false);
1313 ARMButtonChange (false);
1316 assign_strips (false);
1317 notify_automation_mode_changed ();
1320 /* ****************************************************************************
1321 * Assigned Stripable Callbacks
1325 FaderPort8::notify_stripable_added_or_removed ()
1329 * - session->RouteAdded
1330 * - PresentationInfo::Change -> Properties::hidden
1332 assign_strips (false);
1335 /* functor for FP8Strip's select button */
1337 FaderPort8::select_strip (boost::weak_ptr<Stripable> ws)
1339 boost::shared_ptr<Stripable> s = ws.lock();
1343 if (_shift_pressed) {
1344 if (s->is_selected ()) {
1345 RemoveStripableFromSelection (s);
1347 SetStripableSelection (s);
1351 if (s->is_selected () && s != first_selected_stripable ()) {
1352 set_first_selected_stripable (s);
1353 gui_track_selection_changed ();
1355 ToggleStripableSelection (s);
1359 /* called from static PresentationInfo::Change */
1361 FaderPort8::notify_pi_property_changed (const PropertyChange& what_changed)
1363 if (what_changed.contains (Properties::hidden)) {
1364 notify_stripable_added_or_removed ();
1366 if (what_changed.contains (Properties::order)) {
1367 notify_stripable_added_or_removed ();
1369 // Properties::selected is handled via StripableSelectionChanged
1373 FaderPort8::notify_stripable_property_changed (boost::weak_ptr<Stripable> ws, const PropertyChange& what_changed)
1375 boost::shared_ptr<Stripable> s = ws.lock();
1377 assert (0); // this should not happen
1380 assert (_assigned_strips.find (s) != _assigned_strips.end());
1381 uint8_t id = _assigned_strips[s];
1383 if (what_changed.contains (Properties::color)) {
1384 _ctrls.strip(id).select_button ().set_color (s->presentation_info ().color());
1387 if (what_changed.contains (Properties::name)) {
1388 _ctrls.strip(id).set_text_line (0, s->name());
1393 FaderPort8::gui_track_selection_changed (/*ARDOUR::StripableNotificationListPtr*/)
1395 automation_state_connections.drop_connections();
1397 switch (_ctrls.fader_mode ()) {
1399 if (_proc_params.size () > 0) {
1400 ; // TODO w/"well-known" -> re-assign to new strip ?!
1402 notify_fader_mode_changed ();
1406 notify_automation_mode_changed ();
1412 for (StripAssignmentMap::const_iterator i = _assigned_strips.begin(); i != _assigned_strips.end(); ++i) {
1413 boost::shared_ptr<ARDOUR::Stripable> s = i->first;
1414 uint8_t id = i->second;
1415 bool sel = s->is_selected ();
1416 _ctrls.strip(id).select_button ().set_active (sel);
1417 _ctrls.strip(id).select_button ().set_blinking (sel && s == first_selected_stripable ());
1420 boost::shared_ptr<Stripable> s = first_selected_stripable();
1422 boost::shared_ptr<AutomationControl> ac;
1423 ac = s->gain_control();
1424 if (ac && ac->alist()) {
1425 ac->alist()->automation_state_changed.connect (automation_state_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_automation_mode_changed, this), this);
1427 ac = s->pan_azimuth_control();
1428 if (ac && ac->alist()) {
1429 ac->alist()->automation_state_changed.connect (automation_state_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_automation_mode_changed, this), this);
1432 notify_automation_mode_changed ();
1436 /* ****************************************************************************
1441 FaderPort8::move_selected_into_view ()
1443 boost::shared_ptr<Stripable> selected = first_selected_stripable ();
1448 StripableList strips;
1449 filter_stripables (strips);
1451 StripableList::iterator it = std::find (strips.begin(), strips.end(), selected);
1452 if (it == strips.end()) {
1455 int off = std::distance (strips.begin(), it);
1457 if (_channel_off <= off && off < _channel_off + 8) {
1461 if (_channel_off > off) {
1464 _channel_off = off - 7;
1466 assign_strips (false);
1470 FaderPort8::bank (bool down, bool page)
1472 int dt = page ? 8 : 1;
1477 assign_strips (false);
1481 FaderPort8::bank_param (bool down, bool page)
1483 int dt = page ? 8 : 1;
1488 switch (_ctrls.fader_mode ()) {
1490 if (_proc_params.size() > 0) {
1491 _parameter_off += dt;
1492 assign_processor_ctrls ();