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