enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / libs / surfaces / faderport / faderport.cc
1 /*
2     Copyright (C) 2015 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <cstdlib>
21 #include <sstream>
22 #include <algorithm>
23
24 #include <stdint.h>
25
26 #include <glibmm/fileutils.h>
27 #include <glibmm/miscutils.h>
28
29 #include "pbd/error.h"
30 #include "pbd/failed_constructor.h"
31 #include "pbd/file_utils.h"
32 #include "pbd/pthread_utils.h"
33 #include "pbd/compose.h"
34 #include "pbd/xml++.h"
35
36 #include "midi++/port.h"
37
38 #include "ardour/async_midi_port.h"
39 #include "ardour/audioengine.h"
40 #include "ardour/amp.h"
41 #include "ardour/bundle.h"
42 #include "ardour/controllable_descriptor.h"
43 #include "ardour/debug.h"
44 #include "ardour/filesystem_paths.h"
45 #include "ardour/midi_port.h"
46 #include "ardour/midiport_manager.h"
47 #include "ardour/monitor_processor.h"
48 #include "ardour/profile.h"
49 #include "ardour/rc_configuration.h"
50 #include "ardour/record_enable_control.h"
51 #include "ardour/stripable.h"
52 #include "ardour/session.h"
53 #include "ardour/session_configuration.h"
54 #include "ardour/track.h"
55
56 #include "faderport.h"
57
58 using namespace ARDOUR;
59 using namespace ArdourSurface;
60 using namespace PBD;
61 using namespace Glib;
62 using namespace std;
63
64 #include "pbd/i18n.h"
65
66 #include "pbd/abstract_ui.cc" // instantiate template
67
68 FaderPort::FaderPort (Session& s)
69         : ControlProtocol (s, _("PreSonus FaderPort"))
70         , AbstractUI<FaderPortRequest> (name())
71         , gui (0)
72         , connection_state (ConnectionState (0))
73         , _device_active (false)
74         , fader_msb (0)
75         , fader_lsb (0)
76         , fader_is_touched (false)
77         , button_state (ButtonState (0))
78         , blink_state (false)
79         , rec_enable_state (false)
80 {
81         last_encoder_time = 0;
82
83         boost::shared_ptr<ARDOUR::Port> inp;
84         boost::shared_ptr<ARDOUR::Port> outp;
85
86         inp  = AudioEngine::instance()->register_input_port (DataType::MIDI, "Faderport Recv", true);
87         outp = AudioEngine::instance()->register_output_port (DataType::MIDI, "Faderport Send", true);
88
89         _input_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(inp);
90         _output_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(outp);
91
92         if (_input_port == 0 || _output_port == 0) {
93                 throw failed_constructor();
94         }
95
96         _input_bundle.reset (new ARDOUR::Bundle (_("Faderport Support (Receive)"), true));
97         _output_bundle.reset (new ARDOUR::Bundle (_("Faderport Support (Send) "), false));
98
99         _input_bundle->add_channel (
100                 inp->name(),
101                 ARDOUR::DataType::MIDI,
102                 session->engine().make_port_name_non_relative (inp->name())
103                 );
104
105         _output_bundle->add_channel (
106                 outp->name(),
107                 ARDOUR::DataType::MIDI,
108                 session->engine().make_port_name_non_relative (outp->name())
109                 );
110
111
112         StripableSelectionChanged.connect (selection_connection, MISSING_INVALIDATOR, boost::bind (&FaderPort::gui_track_selection_changed, this, _1), this);
113
114         /* Catch port connections and disconnections */
115         ARDOUR::AudioEngine::instance()->PortConnectedOrDisconnected.connect (port_connection, MISSING_INVALIDATOR, boost::bind (&FaderPort::connection_handler, this, _1, _2, _3, _4, _5), this);
116
117         buttons.insert (std::make_pair (Mute, Button (*this, _("Mute"), Mute, 21)));
118         buttons.insert (std::make_pair (Solo, Button (*this, _("Solo"), Solo, 22)));
119         buttons.insert (std::make_pair (Rec, Button (*this, _("Rec"), Rec, 23)));
120         buttons.insert (std::make_pair (Left, Button (*this, _("Left"), Left, 20)));
121         buttons.insert (std::make_pair (Bank, Button (*this, _("Bank"), Bank, 19)));
122         buttons.insert (std::make_pair (Right, Button (*this, _("Right"), Right, 18)));
123         buttons.insert (std::make_pair (Output, Button (*this, _("Output"), Output, 17)));
124         buttons.insert (std::make_pair (FP_Read, Button (*this, _("Read"), FP_Read, 13)));
125         buttons.insert (std::make_pair (FP_Write, Button (*this, _("Write"), FP_Write, 14)));
126         buttons.insert (std::make_pair (FP_Touch, Button (*this, _("Touch"), FP_Touch, 15)));
127         buttons.insert (std::make_pair (FP_Off, Button (*this, _("Off"), FP_Off, 16)));
128         buttons.insert (std::make_pair (Mix, Button (*this, _("Mix"), Mix, 12)));
129         buttons.insert (std::make_pair (Proj, Button (*this, _("Proj"), Proj, 11)));
130         buttons.insert (std::make_pair (Trns, Button (*this, _("Trns"), Trns, 10)));
131         buttons.insert (std::make_pair (Undo, Button (*this, _("Undo"), Undo, 9)));
132         buttons.insert (std::make_pair (Shift, Button (*this, _("Shift"), Shift, 5)));
133         buttons.insert (std::make_pair (Punch, Button (*this, _("Punch"), Punch, 6)));
134         buttons.insert (std::make_pair (User, Button (*this, _("User"), User, 7)));
135         buttons.insert (std::make_pair (Loop, Button (*this, _("Loop"), Loop, 8)));
136         buttons.insert (std::make_pair (Rewind, Button (*this, _("Rewind"), Rewind, 4)));
137         buttons.insert (std::make_pair (Ffwd, Button (*this, _("Ffwd"), Ffwd, 3)));
138         buttons.insert (std::make_pair (Stop, Button (*this, _("Stop"), Stop, 2)));
139         buttons.insert (std::make_pair (Play, Button (*this, _("Play"), Play, 1)));
140         buttons.insert (std::make_pair (RecEnable, Button (*this, _("RecEnable"), RecEnable, 0)));
141         buttons.insert (std::make_pair (Footswitch, Button (*this, _("Footswitch"), Footswitch, -1)));
142         buttons.insert (std::make_pair (FaderTouch, Button (*this, _("Fader (touch)"), FaderTouch, -1)));
143
144         get_button (Shift).set_flash (true);
145         get_button (Mix).set_flash (true);
146         get_button (Proj).set_flash (true);
147         get_button (Trns).set_flash (true);
148         get_button (User).set_flash (true);
149
150         get_button (Left).set_action ( boost::bind (&FaderPort::left, this), true);
151         get_button (Right).set_action ( boost::bind (&FaderPort::right, this), true);
152
153         get_button (Undo).set_action (boost::bind (&FaderPort::undo, this), true);
154         get_button (Undo).set_action (boost::bind (&FaderPort::redo, this), true, ShiftDown);
155         get_button (Undo).set_flash (true);
156
157         get_button (FP_Read).set_action (boost::bind (&FaderPort::read, this), true);
158         get_button (FP_Read).set_action (boost::bind (&FaderPort::off, this), false, LongPress);
159         get_button (FP_Write).set_action (boost::bind (&FaderPort::write, this), true);
160         get_button (FP_Write).set_action (boost::bind (&FaderPort::off, this), false, LongPress);
161         get_button (FP_Touch).set_action (boost::bind (&FaderPort::touch, this), true);
162         get_button (FP_Touch).set_action (boost::bind (&FaderPort::off, this), false, LongPress);
163         get_button (FP_Off).set_action (boost::bind (&FaderPort::off, this), true);
164
165         get_button (Play).set_action (boost::bind (&BasicUI::transport_play, this, true), true);
166         get_button (RecEnable).set_action (boost::bind (&BasicUI::rec_enable_toggle, this), true);
167         /* Stop is a modifier, so we have to use its own button state to get
168            the default action (since StopDown will be set when looking for the
169            action to invoke.
170         */
171         get_button (Stop).set_action (boost::bind (&BasicUI::transport_stop, this), true, StopDown);
172         get_button (Ffwd).set_action (boost::bind (&BasicUI::ffwd, this), true);
173
174         /* See comments about Stop above .. */
175         get_button (Rewind).set_action (boost::bind (&BasicUI::rewind, this), true, RewindDown);
176         get_button (Rewind).set_action (boost::bind (&BasicUI::goto_zero, this), true, ButtonState (RewindDown|StopDown));
177         get_button (Rewind).set_action (boost::bind (&BasicUI::goto_start, this), true, ButtonState (RewindDown|ShiftDown));
178
179         get_button (Ffwd).set_action (boost::bind (&BasicUI::ffwd, this), true);
180         get_button (Ffwd).set_action (boost::bind (&BasicUI::goto_end, this), true, ShiftDown);
181
182         get_button (Punch).set_action (boost::bind (&FaderPort::punch, this), true);
183
184         get_button (Loop).set_action (boost::bind (&BasicUI::loop_toggle, this), true);
185         get_button (Loop).set_action (boost::bind (&BasicUI::add_marker, this, string()), true, ShiftDown);
186
187         get_button (Punch).set_action (boost::bind (&BasicUI::prev_marker, this), true, ShiftDown);
188         get_button (User).set_action (boost::bind (&BasicUI::next_marker, this), true, ButtonState(ShiftDown|UserDown));
189
190         get_button (Mute).set_action (boost::bind (&FaderPort::mute, this), true);
191         get_button (Solo).set_action (boost::bind (&FaderPort::solo, this), true);
192         get_button (Rec).set_action (boost::bind (&FaderPort::rec_enable, this), true);
193
194         get_button (Output).set_action (boost::bind (&FaderPort::use_master, this), true);
195         get_button (Output).set_action (boost::bind (&FaderPort::use_monitor, this), true, ShiftDown);
196 }
197
198 FaderPort::~FaderPort ()
199 {
200         all_lights_out ();
201
202         if (_input_port) {
203                 DEBUG_TRACE (DEBUG::FaderPort, string_compose ("unregistering input port %1\n", boost::shared_ptr<ARDOUR::Port>(_input_port)->name()));
204                 AudioEngine::instance()->unregister_port (_input_port);
205                 _input_port.reset ();
206         }
207
208         if (_output_port) {
209                 _output_port->drain (10000,  250000); /* check every 10 msecs, wait up to 1/4 second for the port to drain */
210                 DEBUG_TRACE (DEBUG::FaderPort, string_compose ("unregistering output port %1\n", boost::shared_ptr<ARDOUR::Port>(_output_port)->name()));
211                 AudioEngine::instance()->unregister_port (_output_port);
212                 _output_port.reset ();
213         }
214
215         tear_down_gui ();
216
217         /* stop event loop */
218         DEBUG_TRACE (DEBUG::FaderPort, "BaseUI::quit ()\n");
219         BaseUI::quit ();
220 }
221
222 void*
223 FaderPort::request_factory (uint32_t num_requests)
224 {
225         /* AbstractUI<T>::request_buffer_factory() is a template method only
226            instantiated in this source module. To provide something visible for
227            use in the interface/descriptor, we have this static method that is
228            template-free.
229         */
230         return request_buffer_factory (num_requests);
231 }
232
233 void
234 FaderPort::start_midi_handling ()
235 {
236         /* handle device inquiry response */
237         _input_port->parser()->sysex.connect_same_thread (midi_connections, boost::bind (&FaderPort::sysex_handler, this, _1, _2, _3));
238         /* handle buttons */
239         _input_port->parser()->poly_pressure.connect_same_thread (midi_connections, boost::bind (&FaderPort::button_handler, this, _1, _2));
240         /* handle encoder */
241         _input_port->parser()->pitchbend.connect_same_thread (midi_connections, boost::bind (&FaderPort::encoder_handler, this, _1, _2));
242         /* handle fader */
243         _input_port->parser()->controller.connect_same_thread (midi_connections, boost::bind (&FaderPort::fader_handler, this, _1, _2));
244
245         /* This connection means that whenever data is ready from the input
246          * port, the relevant thread will invoke our ::midi_input_handler()
247          * method, which will read the data, and invoke the parser.
248          */
249
250         _input_port->xthread().set_receive_handler (sigc::bind (sigc::mem_fun (this, &FaderPort::midi_input_handler), _input_port));
251         _input_port->xthread().attach (main_loop()->get_context());
252 }
253
254 void
255 FaderPort::stop_midi_handling ()
256 {
257         midi_connections.drop_connections ();
258
259         /* Note: the input handler is still active at this point, but we're no
260          * longer connected to any of the parser signals
261          */
262 }
263
264 void
265 FaderPort::do_request (FaderPortRequest* req)
266 {
267         if (req->type == CallSlot) {
268
269                 call_slot (MISSING_INVALIDATOR, req->the_slot);
270
271         } else if (req->type == Quit) {
272
273                 stop ();
274         }
275 }
276
277 int
278 FaderPort::stop ()
279 {
280         BaseUI::quit ();
281
282         return 0;
283 }
284
285 void
286 FaderPort::thread_init ()
287 {
288         struct sched_param rtparam;
289
290         pthread_set_name (event_loop_name().c_str());
291
292         PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048);
293         ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128);
294
295         memset (&rtparam, 0, sizeof (rtparam));
296         rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */
297
298         if (pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam) != 0) {
299                 // do we care? not particularly.
300         }
301 }
302
303 void
304 FaderPort::all_lights_out ()
305 {
306         for (ButtonMap::iterator b = buttons.begin(); b != buttons.end(); ++b) {
307                 b->second.set_led_state (_output_port, false);
308         }
309 }
310
311 FaderPort::Button&
312 FaderPort::get_button (ButtonID id) const
313 {
314         ButtonMap::const_iterator b = buttons.find (id);
315         assert (b != buttons.end());
316         return const_cast<Button&>(b->second);
317 }
318
319 bool
320 FaderPort::button_long_press_timeout (ButtonID id)
321 {
322         if (buttons_down.find (id) != buttons_down.end()) {
323                 get_button (id).invoke (ButtonState (LongPress|button_state), false);
324         } else {
325                 /* release happened and somehow we were not cancelled */
326         }
327
328         /* whichever button this was, we've used it ... don't invoke the
329            release action.
330         */
331         consumed.insert (id);
332
333         return false; /* don't get called again */
334 }
335
336 void
337 FaderPort::start_press_timeout (Button& button, ButtonID id)
338 {
339         Glib::RefPtr<Glib::TimeoutSource> timeout = Glib::TimeoutSource::create (500); // milliseconds
340         button.timeout_connection = timeout->connect (sigc::bind (sigc::mem_fun (*this, &FaderPort::button_long_press_timeout), id));
341         timeout->attach (main_loop()->get_context());
342 }
343
344 void
345 FaderPort::button_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb)
346 {
347         ButtonID id (ButtonID (tb->controller_number));
348         Button& button (get_button (id));
349
350         DEBUG_TRACE (DEBUG::FaderPort, string_compose ("button event for ID %1 press ? %2\n", (int) tb->controller_number, (tb->value ? "yes" : "no")));
351
352         if (tb->value) {
353                 buttons_down.insert (id);
354         } else {
355                 buttons_down.erase (id);
356                 button.timeout_connection.disconnect ();
357         }
358
359         ButtonState bs (ButtonState (0));
360
361         switch (id) {
362         case Shift:
363                 bs = ShiftDown;
364                 break;
365         case Stop:
366                 bs = StopDown;
367                 break;
368         case Rewind:
369                 bs = RewindDown;
370                 break;
371         case User:
372                 bs = UserDown;
373                 break;
374         case FaderTouch:
375                 fader_is_touched = tb->value;
376                 if (_current_stripable) {
377                         boost::shared_ptr<AutomationControl> gain = _current_stripable->gain_control ();
378                         if (gain) {
379                                 framepos_t now = session->engine().sample_time();
380                                 if (tb->value) {
381                                         gain->start_touch (now);
382                                 } else {
383                                         gain->stop_touch (true, now);
384                                 }
385                         }
386                 }
387                 break;
388         default:
389                 if (tb->value) {
390                         start_press_timeout (button, id);
391                 }
392                 break;
393         }
394
395         if (bs) {
396                 button_state = (tb->value ? ButtonState (button_state|bs) : ButtonState (button_state&~bs));
397                 DEBUG_TRACE (DEBUG::FaderPort, string_compose ("reset button state to %1 using %2\n", button_state, (int) bs));
398         }
399
400         if (button.uses_flash()) {
401                 button.set_led_state (_output_port, (int)tb->value);
402         }
403
404         set<ButtonID>::iterator c = consumed.find (id);
405
406         if (c == consumed.end()) {
407                 button.invoke (button_state, tb->value ? true : false);
408         } else {
409                 DEBUG_TRACE (DEBUG::FaderPort, "button was consumed, ignored\n");
410                 consumed.erase (c);
411         }
412 }
413
414 void
415 FaderPort::encoder_handler (MIDI::Parser &, MIDI::pitchbend_t pb)
416 {
417         int delta = 1;
418
419         if (pb >= 8192) {
420                 delta = -1;
421         }
422
423         //knob debouncing and hysteresis.  The presonus encoder often sends bursts of events, or goes the wrong direction
424         {
425                 last_last_encoder_delta = last_encoder_delta;
426                 last_encoder_delta = delta;
427                 microseconds_t now = get_microseconds ();
428                 if ((now - last_encoder_time) < 10*1000) { //require at least 10ms interval between changes, because the device sometimes sends multiple deltas
429                         return;
430                 }
431                 if ((now - last_encoder_time) < 100*1000) { //avoid directional changes while "spinning", 100ms window
432                         if ( (delta == last_encoder_delta) && (delta == last_last_encoder_delta) ) {
433                                 last_good_encoder_delta = delta;  //3 in a row, grudgingly accept this as the new direction
434                         }
435                         if (delta != last_good_encoder_delta) {  //otherwise ensure we keep going the same way
436                                 delta = last_good_encoder_delta;
437                         }
438                 } else {  //we aren't yet in a spin window, just assume this move is really what we want
439                         //NOTE:  if you are worried about where these get initialized, here it is.
440                         last_last_encoder_delta = delta;
441                         last_encoder_delta = delta;
442                 }
443                 last_encoder_time = now;
444                 last_good_encoder_delta = delta;
445         }
446
447         if (_current_stripable) {
448
449                 ButtonState trim_modifier;
450                 ButtonState width_modifier;
451
452                 if (Profile->get_mixbus()) {
453                         trim_modifier = ShiftDown;
454                         width_modifier = ButtonState (0);
455                 } else {
456                         trim_modifier = UserDown;
457                         width_modifier = ShiftDown;
458                 }
459
460                 if ((button_state & trim_modifier) == trim_modifier ) {    // mod+encoder = input trim
461                         boost::shared_ptr<AutomationControl> trim = _current_stripable->trim_control ();
462                         if (trim) {
463                                 float val = trim->get_user();  //for gain elements, the "user" value is in dB
464                                 val += delta;
465                                 trim->set_user(val);
466                         }
467                 } else if (width_modifier && ((button_state & width_modifier) == width_modifier)) {
468                         ardour_pan_width (delta);
469
470                 } else {  // pan/balance
471                         if (!Profile->get_mixbus()) {
472                                 ardour_pan_azimuth (delta);
473                         } else {
474                                 mixbus_pan (delta);
475                         }
476                 }
477         }
478
479         /* if the user button was pressed, mark it as consumed so that its
480          * release action has no effect.
481          */
482
483         if (!Profile->get_mixbus() && (button_state & UserDown)) {
484                 consumed.insert (User);
485         }
486 }
487
488 void
489 FaderPort::fader_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb)
490 {
491         bool was_fader = false;
492
493         if (tb->controller_number == 0x0) {
494                 fader_msb = tb->value;
495                 was_fader = true;
496         } else if (tb->controller_number == 0x20) {
497                 fader_lsb = tb->value;
498                 was_fader = true;
499         }
500
501         if (was_fader) {
502                 if (_current_stripable) {
503                         boost::shared_ptr<AutomationControl> gain = _current_stripable->gain_control ();
504                         if (gain) {
505                                 int ival = (fader_msb << 7) | fader_lsb;
506                                 float val = gain->interface_to_internal (ival/16384.0);
507                                 /* even though the faderport only controls a
508                                    single stripable at a time, allow the fader to
509                                    modify the group, if appropriate.
510                                 */
511                                 _current_stripable->gain_control()->set_value (val, Controllable::UseGroup);
512                         }
513                 }
514         }
515 }
516
517 void
518 FaderPort::sysex_handler (MIDI::Parser &p, MIDI::byte *buf, size_t sz)
519 {
520         DEBUG_TRACE (DEBUG::FaderPort, string_compose ("sysex message received, size = %1\n", sz));
521
522         if (sz < 17) {
523                 return;
524         }
525
526         if (buf[2] != 0x7f ||
527             buf[3] != 0x06 ||
528             buf[4] != 0x02 ||
529             buf[5] != 0x0 ||
530             buf[6] != 0x1 ||
531             buf[7] != 0x06 ||
532             buf[8] != 0x02 ||
533             buf[9] != 0x0 ||
534             buf[10] != 0x01 ||
535             buf[11] != 0x0) {
536                 return;
537         }
538
539         _device_active = true;
540
541         DEBUG_TRACE (DEBUG::FaderPort, "FaderPort identified via MIDI Device Inquiry response\n");
542
543         /* put it into native mode */
544
545         MIDI::byte native[3];
546         native[0] = 0x91;
547         native[1] = 0x00;
548         native[2] = 0x64;
549
550         _output_port->write (native, 3, 0);
551
552         all_lights_out ();
553
554         /* catch up on state */
555
556         /* make sure that rec_enable_state is consistent with current device state */
557         get_button (RecEnable).set_led_state (_output_port, rec_enable_state);
558
559         map_transport_state ();
560         map_recenable_state ();
561 }
562
563 int
564 FaderPort::set_active (bool yn)
565 {
566         DEBUG_TRACE (DEBUG::FaderPort, string_compose("Faderport::set_active init with yn: '%1'\n", yn));
567
568         if (yn == active()) {
569                 return 0;
570         }
571
572         if (yn) {
573
574                 /* start event loop */
575
576                 BaseUI::run ();
577
578                 connect_session_signals ();
579
580                 Glib::RefPtr<Glib::TimeoutSource> blink_timeout = Glib::TimeoutSource::create (200); // milliseconds
581                 blink_connection = blink_timeout->connect (sigc::mem_fun (*this, &FaderPort::blink));
582                 blink_timeout->attach (main_loop()->get_context());
583
584                 Glib::RefPtr<Glib::TimeoutSource> periodic_timeout = Glib::TimeoutSource::create (100); // milliseconds
585                 periodic_connection = periodic_timeout->connect (sigc::mem_fun (*this, &FaderPort::periodic));
586                 periodic_timeout->attach (main_loop()->get_context());
587
588         } else {
589
590                 BaseUI::quit ();
591                 close ();
592
593         }
594
595         ControlProtocol::set_active (yn);
596
597         DEBUG_TRACE (DEBUG::FaderPort, string_compose("Faderport::set_active done with yn: '%1'\n", yn));
598
599         return 0;
600 }
601
602 bool
603 FaderPort::periodic ()
604 {
605         if (!_current_stripable) {
606                 return true;
607         }
608
609         ARDOUR::AutoState gain_state = _current_stripable->gain_control()->automation_state();
610
611         if (gain_state == ARDOUR::Touch || gain_state == ARDOUR::Play) {
612                 map_gain ();
613         }
614
615         return true;
616 }
617
618 void
619 FaderPort::stop_blinking (ButtonID id)
620 {
621         blinkers.remove (id);
622         get_button (id).set_led_state (_output_port, false);
623 }
624
625 void
626 FaderPort::start_blinking (ButtonID id)
627 {
628         blinkers.push_back (id);
629         get_button (id).set_led_state (_output_port, true);
630 }
631
632 bool
633 FaderPort::blink ()
634 {
635         blink_state = !blink_state;
636
637         for (Blinkers::iterator b = blinkers.begin(); b != blinkers.end(); b++) {
638                 get_button(*b).set_led_state (_output_port, blink_state);
639         }
640
641         map_recenable_state ();
642
643         return true;
644 }
645
646 void
647 FaderPort::close ()
648 {
649         all_lights_out ();
650
651         stop_midi_handling ();
652         session_connections.drop_connections ();
653         port_connection.disconnect ();
654         blink_connection.disconnect ();
655         selection_connection.disconnect ();
656         stripable_connections.drop_connections ();
657
658 #if 0
659         stripable_connections.drop_connections ();
660 #endif
661 }
662
663 void
664 FaderPort::map_recenable_state ()
665 {
666         /* special case for RecEnable because its status can change as a
667          * confluence of unrelated parameters: (a) session rec-enable state (b)
668          * rec-enabled tracks. So we don't add the button to the blinkers list,
669          * we just call this:
670          *
671          *  * from the blink callback
672          *  * when the session tells us about a status change
673          *
674          * We do the last one so that the button changes state promptly rather
675          * than waiting for the next blink callback. The change in "blinking"
676          * based on having record-enabled tracks isn't urgent, and that happens
677          * during the blink callback.
678          */
679
680         bool onoff;
681
682         switch (session->record_status()) {
683         case Session::Disabled:
684                 onoff = false;
685                 break;
686         case Session::Enabled:
687                 onoff = blink_state;
688                 break;
689         case Session::Recording:
690                 if (session->have_rec_enabled_track ()) {
691                         onoff = true;
692                 } else {
693                         onoff = blink_state;
694                 }
695                 break;
696         }
697
698         if (onoff != rec_enable_state) {
699                 get_button(RecEnable).set_led_state (_output_port, onoff);
700                 rec_enable_state = onoff;
701         }
702 }
703
704 void
705 FaderPort::map_transport_state ()
706 {
707         get_button (Loop).set_led_state (_output_port, session->get_play_loop());
708
709         float ts = session->transport_speed();
710
711         if (ts == 0) {
712                 stop_blinking (Play);
713         } else if (fabs (ts) == 1.0) {
714                 stop_blinking (Play);
715                 get_button (Play).set_led_state (_output_port, true);
716         } else {
717                 start_blinking (Play);
718         }
719
720         get_button (Stop).set_led_state (_output_port, session->transport_stopped ());
721         get_button (Rewind).set_led_state (_output_port, session->transport_speed() < 0.0);
722         get_button (Ffwd).set_led_state (_output_port, session->transport_speed() > 1.0);
723 }
724
725 void
726 FaderPort::parameter_changed (string what)
727 {
728         if (what == "punch-in" || what == "punch-out") {
729                 bool in = session->config.get_punch_in ();
730                 bool out = session->config.get_punch_out ();
731                 if (in && out) {
732                         get_button (Punch).set_led_state (_output_port, true);
733                         blinkers.remove (Punch);
734                 } else if (in || out) {
735                         start_blinking (Punch);
736                 } else {
737                         stop_blinking (Punch);
738                 }
739         }
740 }
741
742 void
743 FaderPort::connect_session_signals()
744 {
745         session->RecordStateChanged.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort::map_recenable_state, this), this);
746         session->TransportStateChange.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort::map_transport_state, this), this);
747         /* not session, but treat it similarly */
748         session->config.ParameterChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort::parameter_changed, this, _1), this);
749 }
750
751 bool
752 FaderPort::midi_input_handler (Glib::IOCondition ioc, boost::shared_ptr<ARDOUR::AsyncMIDIPort> port)
753 {
754         DEBUG_TRACE (DEBUG::FaderPort, string_compose ("something happend on  %1\n", boost::shared_ptr<MIDI::Port>(port)->name()));
755
756         if (ioc & ~IO_IN) {
757                 return false;
758         }
759
760         if (ioc & IO_IN) {
761
762                 port->clear ();
763                 DEBUG_TRACE (DEBUG::FaderPort, string_compose ("data available on %1\n", boost::shared_ptr<MIDI::Port>(port)->name()));
764                 framepos_t now = session->engine().sample_time();
765                 port->parse (now);
766         }
767
768         return true;
769 }
770
771
772 XMLNode&
773 FaderPort::get_state ()
774 {
775         XMLNode& node (ControlProtocol::get_state());
776
777         XMLNode* child;
778
779         child = new XMLNode (X_("Input"));
780         child->add_child_nocopy (boost::shared_ptr<ARDOUR::Port>(_input_port)->get_state());
781         node.add_child_nocopy (*child);
782
783
784         child = new XMLNode (X_("Output"));
785         child->add_child_nocopy (boost::shared_ptr<ARDOUR::Port>(_output_port)->get_state());
786         node.add_child_nocopy (*child);
787
788         /* Save action state for Mix, Proj, Trns and User buttons, since these
789          * are user controlled. We can only save named-action operations, since
790          * internal functions are just pointers to functions and hard to
791          * serialize without enumerating them all somewhere.
792          */
793
794         node.add_child_nocopy (get_button (Mix).get_state());
795         node.add_child_nocopy (get_button (Proj).get_state());
796         node.add_child_nocopy (get_button (Trns).get_state());
797         node.add_child_nocopy (get_button (User).get_state());
798         node.add_child_nocopy (get_button (Footswitch).get_state());
799
800         return node;
801 }
802
803 int
804 FaderPort::set_state (const XMLNode& node, int version)
805 {
806         XMLNodeList nlist;
807         XMLNodeConstIterator niter;
808         XMLNode const* child;
809
810         if (ControlProtocol::set_state (node, version)) {
811                 return -1;
812         }
813
814         if ((child = node.child (X_("Input"))) != 0) {
815                 XMLNode* portnode = child->child (Port::state_node_name.c_str());
816                 if (portnode) {
817                         boost::shared_ptr<ARDOUR::Port>(_input_port)->set_state (*portnode, version);
818                 }
819         }
820
821         if ((child = node.child (X_("Output"))) != 0) {
822                 XMLNode* portnode = child->child (Port::state_node_name.c_str());
823                 if (portnode) {
824                         boost::shared_ptr<ARDOUR::Port>(_output_port)->set_state (*portnode, version);
825                 }
826         }
827
828         for (XMLNodeList::const_iterator n = node.children().begin(); n != node.children().end(); ++n) {
829                 if ((*n)->name() == X_("Button")) {
830                         XMLProperty const * prop = (*n)->property (X_("id"));
831                         if (!prop) {
832                                 continue;
833                         }
834                         int xid = atoi (prop->value());
835                         ButtonMap::iterator b = buttons.find (ButtonID (xid));
836                         if (b == buttons.end()) {
837                                 continue;
838                         }
839                         b->second.set_state (**n);
840                 }
841         }
842
843         return 0;
844 }
845
846 bool
847 FaderPort::connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn)
848 {
849         DEBUG_TRACE (DEBUG::FaderPort, "FaderPort::connection_handler  start\n");
850         if (!_input_port || !_output_port) {
851                 return false;
852         }
853
854         string ni = ARDOUR::AudioEngine::instance()->make_port_name_non_relative (boost::shared_ptr<ARDOUR::Port>(_input_port)->name());
855         string no = ARDOUR::AudioEngine::instance()->make_port_name_non_relative (boost::shared_ptr<ARDOUR::Port>(_output_port)->name());
856
857         if (ni == name1 || ni == name2) {
858                 if (yn) {
859                         connection_state |= InputConnected;
860                 } else {
861                         connection_state &= ~InputConnected;
862                 }
863         } else if (no == name1 || no == name2) {
864                 if (yn) {
865                         connection_state |= OutputConnected;
866                 } else {
867                         connection_state &= ~OutputConnected;
868                 }
869         } else {
870                 DEBUG_TRACE (DEBUG::FaderPort, string_compose ("Connections between %1 and %2 changed, but I ignored it\n", name1, name2));
871                 /* not our ports */
872                 return false;
873         }
874
875         if ((connection_state & (InputConnected|OutputConnected)) == (InputConnected|OutputConnected)) {
876
877                 /* XXX this is a horrible hack. Without a short sleep here,
878                    something prevents the device wakeup messages from being
879                    sent and/or the responses from being received.
880                 */
881
882                 g_usleep (100000);
883                 DEBUG_TRACE (DEBUG::FaderPort, "device now connected for both input and output\n");
884                 connected ();
885
886         } else {
887                 DEBUG_TRACE (DEBUG::FaderPort, "Device disconnected (input or output or both) or not yet fully connected\n");
888                 _device_active = false;
889         }
890
891         ConnectionChange (); /* emit signal for our GUI */
892
893         DEBUG_TRACE (DEBUG::FaderPort, "FaderPort::connection_handler  end\n");
894
895         return true; /* connection status changed */
896 }
897
898 void
899 FaderPort::connected ()
900 {
901         DEBUG_TRACE (DEBUG::FaderPort, "sending device inquiry message...\n");
902
903         start_midi_handling ();
904
905         /* send device inquiry */
906
907         MIDI::byte buf[6];
908
909         buf[0] = 0xf0;
910         buf[1] = 0x7e;
911         buf[2] = 0x7f;
912         buf[3] = 0x06;
913         buf[4] = 0x01;
914         buf[5] = 0xf7;
915
916         _output_port->write (buf, 6, 0);
917 }
918
919 void
920 FaderPort::Button::invoke (FaderPort::ButtonState bs, bool press)
921 {
922         DEBUG_TRACE (DEBUG::FaderPort, string_compose ("invoke button %1 for %2 state %3%4%5\n", id, (press ? "press":"release"), hex, bs, dec));
923
924         ToDoMap::iterator x;
925
926         if (press) {
927                 if ((x = on_press.find (bs)) == on_press.end()) {
928                         DEBUG_TRACE (DEBUG::FaderPort, string_compose ("no press action for button %1 state %2 @ %3 in %4\n", id, bs, this, &on_press));
929                         return;
930                 }
931         } else {
932                 if ((x = on_release.find (bs)) == on_release.end()) {
933                         DEBUG_TRACE (DEBUG::FaderPort, string_compose ("no release action for button %1 state %2 @%3 in %4\n", id, bs, this, &on_release));
934                         return;
935                 }
936         }
937
938         switch (x->second.type) {
939         case NamedAction:
940                 if (!x->second.action_name.empty()) {
941                         fp.access_action (x->second.action_name);
942                 }
943                 break;
944         case InternalFunction:
945                 if (x->second.function) {
946                         x->second.function ();
947                 }
948         }
949 }
950
951 void
952 FaderPort::Button::set_action (string const& name, bool when_pressed, FaderPort::ButtonState bs)
953 {
954         ToDo todo;
955
956         todo.type = NamedAction;
957
958         if (when_pressed) {
959                 if (name.empty()) {
960                         on_press.erase (bs);
961                 } else {
962                         DEBUG_TRACE (DEBUG::FaderPort, string_compose ("set button %1 to action %2 on press + %3%4%5\n", id, name, bs));
963                         todo.action_name = name;
964                         on_press[bs] = todo;
965                 }
966         } else {
967                 if (name.empty()) {
968                         on_release.erase (bs);
969                 } else {
970                         DEBUG_TRACE (DEBUG::FaderPort, string_compose ("set button %1 to action %2 on release + %3%4%5\n", id, name, bs));
971                         todo.action_name = name;
972                         on_release[bs] = todo;
973                 }
974         }
975 }
976
977 string
978 FaderPort::Button::get_action (bool press, FaderPort::ButtonState bs)
979 {
980         ToDoMap::iterator x;
981
982         if (press) {
983                 if ((x = on_press.find (bs)) == on_press.end()) {
984                         return string();
985                 }
986                 if (x->second.type != NamedAction) {
987                         return string ();
988                 }
989                 return x->second.action_name;
990         } else {
991                 if ((x = on_release.find (bs)) == on_release.end()) {
992                         return string();
993                 }
994                 if (x->second.type != NamedAction) {
995                         return string ();
996                 }
997                 return x->second.action_name;
998         }
999 }
1000
1001 void
1002 FaderPort::Button::set_action (boost::function<void()> f, bool when_pressed, FaderPort::ButtonState bs)
1003 {
1004         ToDo todo;
1005         todo.type = InternalFunction;
1006
1007         if (when_pressed) {
1008                 DEBUG_TRACE (DEBUG::FaderPort, string_compose ("set button %1 (%2) @ %5 to some functor on press + %3 in %4\n", id, name, bs, &on_press, this));
1009                 todo.function = f;
1010                 on_press[bs] = todo;
1011         } else {
1012                 DEBUG_TRACE (DEBUG::FaderPort, string_compose ("set button %1 (%2) @ %5 to some functor on release + %3\n", id, name, bs, this));
1013                 todo.function = f;
1014                 on_release[bs] = todo;
1015         }
1016 }
1017
1018 void
1019 FaderPort::Button::set_led_state (boost::shared_ptr<MIDI::Port> port, bool onoff)
1020 {
1021         if (out < 0) {
1022                 /* fader button ID - no LED */
1023                 return;
1024         }
1025
1026         MIDI::byte buf[3];
1027         buf[0] = 0xa0;
1028         buf[1] = out;
1029         buf[2] = onoff ? 1 : 0;
1030         port->write (buf, 3, 0);
1031 }
1032
1033 int
1034 FaderPort::Button::set_state (XMLNode const& node)
1035 {
1036         const XMLProperty* prop = node.property ("id");
1037         if (!prop) {
1038                 return -1;
1039         }
1040
1041         int xid = atoi (prop->value());
1042         if (xid != id) {
1043                 return -1;
1044         }
1045
1046         typedef pair<string,FaderPort::ButtonState> state_pair_t;
1047         vector<state_pair_t> state_pairs;
1048
1049         state_pairs.push_back (make_pair (string ("plain"), ButtonState (0)));
1050         state_pairs.push_back (make_pair (string ("shift"), ShiftDown));
1051         state_pairs.push_back (make_pair (string ("long"), LongPress));
1052
1053         for (vector<state_pair_t>::const_iterator sp = state_pairs.begin(); sp != state_pairs.end(); ++sp) {
1054                 string propname;
1055
1056                 propname = sp->first + X_("-press");
1057                 if ((prop = node.property (propname)) != 0) {
1058                         set_action (prop->value(), true, sp->second);
1059                 }
1060
1061                 propname = sp->first + X_("-release");
1062                 if ((prop = node.property (propname)) != 0) {
1063                         set_action (prop->value(), false, sp->second);
1064                 }
1065         }
1066
1067         return 0;
1068 }
1069
1070 XMLNode&
1071 FaderPort::Button::get_state () const
1072 {
1073         XMLNode* node = new XMLNode (X_("Button"));
1074         char buf[16];
1075         snprintf (buf, sizeof (buf), "%d", id);
1076
1077         node->add_property (X_("id"), buf);
1078
1079         ToDoMap::const_iterator x;
1080         ToDo null;
1081         null.type = NamedAction;
1082
1083         typedef pair<string,FaderPort::ButtonState> state_pair_t;
1084         vector<state_pair_t> state_pairs;
1085
1086         state_pairs.push_back (make_pair (string ("plain"), ButtonState (0)));
1087         state_pairs.push_back (make_pair (string ("shift"), ShiftDown));
1088         state_pairs.push_back (make_pair (string ("long"), LongPress));
1089
1090         for (vector<state_pair_t>::const_iterator sp = state_pairs.begin(); sp != state_pairs.end(); ++sp) {
1091                 if ((x = on_press.find (sp->second)) != on_press.end()) {
1092                         if (x->second.type == NamedAction) {
1093                                 node->add_property (string (sp->first + X_("-press")).c_str(), x->second.action_name);
1094                         }
1095                 }
1096
1097                 if ((x = on_release.find (sp->second)) != on_release.end()) {
1098                         if (x->second.type == NamedAction) {
1099                                 node->add_property (string (sp->first + X_("-release")).c_str(), x->second.action_name);
1100                         }
1101                 }
1102         }
1103
1104         return *node;
1105 }
1106
1107 void
1108 FaderPort::gui_track_selection_changed (StripableNotificationListPtr stripables)
1109 {
1110         boost::shared_ptr<Stripable> r;
1111
1112         if (!stripables->empty()) {
1113                 r = stripables->front().lock();
1114         }
1115
1116         set_current_stripable (r);
1117 }
1118
1119 void
1120 FaderPort::drop_current_stripable ()
1121 {
1122         if (_current_stripable) {
1123                 if (_current_stripable == session->monitor_out()) {
1124                         set_current_stripable (session->master_out());
1125                 } else {
1126                         set_current_stripable (boost::shared_ptr<Stripable>());
1127                 }
1128         }
1129 }
1130
1131 void
1132 FaderPort::set_current_stripable (boost::shared_ptr<Stripable> r)
1133 {
1134         stripable_connections.drop_connections ();
1135
1136         _current_stripable = r;
1137
1138         /* turn this off. It will be turned on back on in use_master() or
1139            use_monitor() as appropriate.
1140         */
1141         get_button(Output).set_led_state (_output_port, false);
1142
1143         if (_current_stripable) {
1144                 _current_stripable->DropReferences.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort::drop_current_stripable, this), this);
1145
1146                 _current_stripable->mute_control()->Changed.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort::map_mute, this), this);
1147                 _current_stripable->solo_control()->Changed.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort::map_solo, this), this);
1148
1149                 boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track> (_current_stripable);
1150                 if (t) {
1151                         t->rec_enable_control()->Changed.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort::map_recenable, this), this);
1152                 }
1153
1154                 boost::shared_ptr<AutomationControl> control = _current_stripable->gain_control ();
1155                 if (control) {
1156                         control->Changed.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort::map_gain, this), this);
1157                         control->alist()->automation_state_changed.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort::map_auto, this), this);
1158                 }
1159
1160                 boost::shared_ptr<MonitorProcessor> mp = _current_stripable->monitor_control();
1161                 if (mp) {
1162                         mp->cut_control()->Changed.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort::map_cut, this), this);
1163                 }
1164         }
1165
1166         //ToDo: subscribe to the fader automation modes so we can light the LEDs
1167
1168         map_stripable_state ();
1169 }
1170
1171 void
1172 FaderPort::map_auto ()
1173 {
1174         /* Under no circumstances send a message to "enable" the LED state of
1175          * the Off button, because this will disable the fader.
1176          */
1177
1178         boost::shared_ptr<AutomationControl> control = _current_stripable->gain_control ();
1179         const AutoState as = control->automation_state ();
1180
1181         switch (as) {
1182                 case ARDOUR::Play:
1183                         get_button (FP_Read).set_led_state (_output_port, true);
1184                         get_button (FP_Write).set_led_state (_output_port, false);
1185                         get_button (FP_Touch).set_led_state (_output_port, false);
1186                 break;
1187                 case ARDOUR::Write:
1188                         get_button (FP_Read).set_led_state (_output_port, false);
1189                         get_button (FP_Write).set_led_state (_output_port, true);
1190                         get_button (FP_Touch).set_led_state (_output_port, false);
1191                 break;
1192                 case ARDOUR::Touch:
1193                         get_button (FP_Read).set_led_state (_output_port, false);
1194                         get_button (FP_Write).set_led_state (_output_port, false);
1195                         get_button (FP_Touch).set_led_state (_output_port, true);
1196                 break;
1197                 case ARDOUR::Off:
1198                         get_button (FP_Read).set_led_state (_output_port, false);
1199                         get_button (FP_Write).set_led_state (_output_port, false);
1200                         get_button (FP_Touch).set_led_state (_output_port, false);
1201                 break;
1202         }
1203
1204 }
1205
1206
1207 void
1208 FaderPort::map_cut ()
1209 {
1210         boost::shared_ptr<MonitorProcessor> mp = _current_stripable->monitor_control();
1211
1212         if (mp) {
1213                 bool yn = mp->cut_all ();
1214                 if (yn) {
1215                         start_blinking (Mute);
1216                 } else {
1217                         stop_blinking (Mute);
1218                 }
1219         } else {
1220                 stop_blinking (Mute);
1221         }
1222 }
1223
1224 void
1225 FaderPort::map_mute ()
1226 {
1227         if (_current_stripable) {
1228                 if (_current_stripable->mute_control()->muted()) {
1229                         stop_blinking (Mute);
1230                         get_button (Mute).set_led_state (_output_port, true);
1231                 } else if (_current_stripable->mute_control()->muted_by_others_soloing () || _current_stripable->mute_control()->muted_by_masters()) {
1232                         start_blinking (Mute);
1233                 } else {
1234                         stop_blinking (Mute);
1235                 }
1236         } else {
1237                 stop_blinking (Mute);
1238         }
1239 }
1240
1241 void
1242 FaderPort::map_solo ()
1243 {
1244         if (_current_stripable) {
1245                 get_button (Solo).set_led_state (_output_port, _current_stripable->solo_control()->soloed());
1246         } else {
1247                 get_button (Solo).set_led_state (_output_port, false);
1248         }
1249 }
1250
1251 void
1252 FaderPort::map_recenable ()
1253 {
1254         boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track> (_current_stripable);
1255         if (t) {
1256                 get_button (Rec).set_led_state (_output_port, t->rec_enable_control()->get_value());
1257         } else {
1258                 get_button (Rec).set_led_state (_output_port, false);
1259         }
1260 }
1261
1262 void
1263 FaderPort::map_gain ()
1264 {
1265         if (fader_is_touched) {
1266                 /* Do not send fader moves while the user is touching the fader */
1267                 return;
1268         }
1269
1270         if (!_current_stripable) {
1271                 return;
1272         }
1273
1274         boost::shared_ptr<AutomationControl> control = _current_stripable->gain_control ();
1275         double val;
1276
1277         if (!control) {
1278                 val = 0.0;
1279         } else {
1280                 val = control->internal_to_interface (control->get_value ());
1281         }
1282
1283         /* Faderport sends fader position with range 0..16384 (though some of
1284          * the least-significant bits at the top end are missing - it may only
1285          * get to 1636X or so).
1286          *
1287          * But ... position must be sent in the range 0..1023.
1288          *
1289          * Thanks, Obama.
1290          */
1291
1292         int ival = (int) lrintf (val * 1023.0);
1293
1294         /* MIDI normalization requires that we send two separate messages here,
1295          * not one single 6 byte one.
1296          */
1297
1298         MIDI::byte buf[3];
1299
1300         buf[0] = 0xb0;
1301         buf[1] = 0x0;
1302         buf[2] = ival >> 7;
1303
1304         _output_port->write (buf, 3, 0);
1305
1306         buf[1] = 0x20;
1307         buf[2] = ival & 0x7f;
1308
1309         _output_port->write (buf, 3, 0);
1310 }
1311
1312 void
1313 FaderPort::map_stripable_state ()
1314 {
1315         if (!_current_stripable) {
1316                 stop_blinking (Mute);
1317                 stop_blinking (Solo);
1318                 get_button (Rec).set_led_state (_output_port, false);
1319         } else {
1320                 map_solo ();
1321                 map_recenable ();
1322                 map_gain ();
1323                 map_auto ();
1324
1325                 if (_current_stripable == session->monitor_out()) {
1326                         map_cut ();
1327                 } else {
1328                         map_mute ();
1329                 }
1330         }
1331 }
1332
1333 list<boost::shared_ptr<ARDOUR::Bundle> >
1334 FaderPort::bundles ()
1335 {
1336         list<boost::shared_ptr<ARDOUR::Bundle> > b;
1337
1338         if (_input_bundle) {
1339                 b.push_back (_input_bundle);
1340                 b.push_back (_output_bundle);
1341         }
1342
1343         return b;
1344 }
1345
1346 boost::shared_ptr<Port>
1347 FaderPort::output_port()
1348 {
1349         return _output_port;
1350 }
1351
1352 boost::shared_ptr<Port>
1353 FaderPort::input_port()
1354 {
1355         return _input_port;
1356 }
1357
1358 void
1359 FaderPort::set_action (ButtonID id, std::string const& action_name, bool on_press, ButtonState bs)
1360 {
1361         get_button(id).set_action (action_name, on_press, bs);
1362 }
1363
1364 string
1365 FaderPort::get_action (ButtonID id, bool press, ButtonState bs)
1366 {
1367         return get_button(id).get_action (press, bs);
1368 }