3 Copyright (C) 1999-2002 Paul Davis
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <boost/shared_ptr.hpp>
31 #include <glibmm/main.h>
33 #include "midi++/mmc.h"
34 #include "midi++/port.h"
35 #include "midi++/manager.h"
36 #include "pbd/error.h"
37 #include "pbd/pthread_utils.h"
39 #include "ardour/configuration.h"
40 #include "ardour/debug.h"
41 #include "ardour/audioengine.h"
42 #include "ardour/session.h"
43 #include "ardour/audio_track.h"
44 #include "ardour/midi_track.h"
45 #include "ardour/midi_ui.h"
46 #include "ardour/audio_diskstream.h"
47 #include "ardour/slave.h"
48 #include "ardour/cycles.h"
49 #include "ardour/timecode.h"
54 using namespace ARDOUR;
59 MachineControl::CommandSignature MMC_CommandSignature;
60 MachineControl::ResponseSignature MMC_ResponseSignature;
67 boost::shared_ptr<RouteList> r = routes.reader ();
69 for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
70 MidiTrack *track = dynamic_cast<MidiTrack*>((*i).get());
79 Session::use_config_midi_ports ()
83 if (default_mmc_port) {
84 set_mmc_port (default_mmc_port->name());
89 if (default_mtc_port) {
90 set_mtc_port (default_mtc_port->name());
95 if (default_midi_port) {
96 set_midi_port (default_midi_port->name());
101 if (default_midi_clock_port) {
102 set_midi_clock_port (default_midi_clock_port->name());
104 set_midi_clock_port ("");
111 /***********************************************************************
113 **********************************************************************/
116 Session::set_mtc_port (string port_tag)
120 if (port_tag.length() == 0) {
122 if (_slave && ((ms = dynamic_cast<MTC_Slave*> (_slave)) != 0)) {
123 error << string_compose (_("%1 is slaved to MTC - port cannot be reset"), PROGRAM_NAME) << endmsg;
127 if (_mtc_port == 0) {
137 if ((port = MIDI::Manager::instance()->port (port_tag)) == 0) {
138 error << string_compose (_("unknown port %1 requested for MTC"), port_tag) << endl;
144 if (_slave && ((ms = dynamic_cast<MTC_Slave*> (_slave)) != 0)) {
148 Config->set_mtc_port_name (port_tag);
151 MTC_PortChanged(); /* EMIT SIGNAL */
157 Session::set_mmc_receive_device_id (uint32_t device_id)
160 mmc->set_receive_device_id (device_id);
165 Session::set_mmc_send_device_id (uint32_t device_id)
168 mmc->set_send_device_id (device_id);
173 Session::set_mmc_port (string port_tag)
175 MIDI::byte old_recv_device_id = 0;
176 MIDI::byte old_send_device_id = 0;
177 bool reset_id = false;
179 if (port_tag.length() == 0) {
180 if (_mmc_port == 0) {
189 if ((port = MIDI::Manager::instance()->port (port_tag)) == 0) {
196 old_recv_device_id = mmc->receive_device_id();
197 old_recv_device_id = mmc->send_device_id();
202 mmc = new MIDI::MachineControl (*_mmc_port, 1.0,
203 MMC_CommandSignature,
204 MMC_ResponseSignature);
207 mmc->set_receive_device_id (old_recv_device_id);
208 mmc->set_send_device_id (old_send_device_id);
211 mmc->Play.connect_same_thread (*this, boost::bind (&Session::mmc_deferred_play, this, _1));
212 mmc->DeferredPlay.connect_same_thread (*this, boost::bind (&Session::mmc_deferred_play, this, _1));
213 mmc->Stop.connect_same_thread (*this, boost::bind (&Session::mmc_stop, this, _1));
214 mmc->FastForward.connect_same_thread (*this, boost::bind (&Session::mmc_fast_forward, this, _1));
215 mmc->Rewind.connect_same_thread (*this, boost::bind (&Session::mmc_rewind, this, _1));
216 mmc->Pause.connect_same_thread (*this, boost::bind (&Session::mmc_pause, this, _1));
217 mmc->RecordPause.connect_same_thread (*this, boost::bind (&Session::mmc_record_pause, this, _1));
218 mmc->RecordStrobe.connect_same_thread (*this, boost::bind (&Session::mmc_record_strobe, this, _1));
219 mmc->RecordExit.connect_same_thread (*this, boost::bind (&Session::mmc_record_exit, this, _1));
220 mmc->Locate.connect_same_thread (*this, boost::bind (&Session::mmc_locate, this, _1, _2));
221 mmc->Step.connect_same_thread (*this, boost::bind (&Session::mmc_step, this, _1, _2));
222 mmc->Shuttle.connect_same_thread (*this, boost::bind (&Session::mmc_shuttle, this, _1, _2, _3));
223 mmc->TrackRecordStatusChange.connect_same_thread (*this, boost::bind (&Session::mmc_record_enable, this, _1, _2, _3));
226 /* also handle MIDI SPP because its so common */
228 _mmc_port->input()->start.connect_same_thread (*this, boost::bind (&Session::spp_start, this, _1, _2));
229 _mmc_port->input()->contineu.connect_same_thread (*this, boost::bind (&Session::spp_continue, this, _1, _2));
230 _mmc_port->input()->stop.connect_same_thread (*this, boost::bind (&Session::spp_stop, this, _1, _2));
232 Config->set_mmc_port_name (port_tag);
235 MMC_PortChanged(); /* EMIT SIGNAL */
241 Session::set_midi_port (string /*port_tag*/)
244 if (port_tag.length() == 0) {
245 if (_midi_port == 0) {
254 if ((port = MIDI::Manager::instance()->port (port_tag)) == 0) {
260 /* XXX need something to forward this to control protocols ? or just
264 Config->set_midi_port_name (port_tag);
268 MIDI_PortChanged(); /* EMIT SIGNAL */
274 Session::set_midi_clock_port (string port_tag)
278 if (port_tag.length() == 0) {
280 if (_slave && ((ms = dynamic_cast<MIDIClock_Slave*> (_slave)) != 0)) {
281 error << string_compose (_("%1 is slaved to MIDI Clock - port cannot be reset"), PROGRAM_NAME) << endmsg;
285 if (_midi_clock_port == 0) {
289 _midi_clock_port = 0;
295 if ((port = MIDI::Manager::instance()->port (port_tag)) == 0) {
296 error << string_compose (_("unknown port %1 requested for MIDI Clock"), port_tag) << endl;
300 _midi_clock_port = port;
302 if (_slave && ((ms = dynamic_cast<MIDIClock_Slave*> (_slave)) != 0)) {
306 Config->set_midi_clock_port_name (port_tag);
309 MIDIClock_PortChanged(); /* EMIT SIGNAL */
315 Session::set_trace_midi_input (bool yn, MIDI::Port* port)
317 MIDI::Parser* input_parser;
319 cerr << "enabling tracing: " << yn << " for input port " << port->name() << endl;
322 if ((input_parser = port->input()) != 0) {
323 input_parser->trace (yn, &cout, "input: ");
328 if ((input_parser = _mmc_port->input()) != 0) {
329 input_parser->trace (yn, &cout, "input: ");
333 if (_mtc_port && _mtc_port != _mmc_port) {
334 if ((input_parser = _mtc_port->input()) != 0) {
335 input_parser->trace (yn, &cout, "input: ");
339 if (_midi_port && _midi_port != _mmc_port && _midi_port != _mtc_port ) {
340 if ((input_parser = _midi_port->input()) != 0) {
341 input_parser->trace (yn, &cout, "input: ");
346 && _midi_clock_port != _mmc_port
347 && _midi_clock_port != _mtc_port
348 && _midi_clock_port != _midi_port) {
349 if ((input_parser = _midi_clock_port->input()) != 0) {
350 input_parser->trace (yn, &cout, "input: ");
355 Config->set_trace_midi_input (yn);
359 Session::set_trace_midi_output (bool yn, MIDI::Port* port)
361 MIDI::Parser* output_parser;
364 if ((output_parser = port->output()) != 0) {
365 output_parser->trace (yn, &cout, "output: ");
369 if ((output_parser = _mmc_port->output()) != 0) {
370 output_parser->trace (yn, &cout, "output: ");
374 if (_mtc_port && _mtc_port != _mmc_port) {
375 if ((output_parser = _mtc_port->output()) != 0) {
376 output_parser->trace (yn, &cout, "output: ");
380 if (_midi_port && _midi_port != _mmc_port && _midi_port != _mtc_port ) {
381 if ((output_parser = _midi_port->output()) != 0) {
382 output_parser->trace (yn, &cout, "output: ");
388 Config->set_trace_midi_output (yn);
392 Session::get_trace_midi_input(MIDI::Port *port)
394 MIDI::Parser* input_parser;
396 if ((input_parser = port->input()) != 0) {
397 return input_parser->tracing();
402 if ((input_parser = _mmc_port->input()) != 0) {
403 return input_parser->tracing();
408 if ((input_parser = _mtc_port->input()) != 0) {
409 return input_parser->tracing();
414 if ((input_parser = _midi_port->input()) != 0) {
415 return input_parser->tracing();
424 Session::get_trace_midi_output(MIDI::Port *port)
426 MIDI::Parser* output_parser;
428 if ((output_parser = port->output()) != 0) {
429 return output_parser->tracing();
434 if ((output_parser = _mmc_port->output()) != 0) {
435 return output_parser->tracing();
440 if ((output_parser = _mtc_port->output()) != 0) {
441 return output_parser->tracing();
446 if ((output_parser = _midi_port->output()) != 0) {
447 return output_parser->tracing();
457 Session::setup_midi_control ()
459 outbound_mtc_timecode_frame = 0;
460 next_quarter_frame_to_send = 0;
462 /* setup the MMC buffer */
464 mmc_buffer[0] = 0xf0; // SysEx
465 mmc_buffer[1] = 0x7f; // Real Time SysEx ID for MMC
466 mmc_buffer[2] = (mmc ? mmc->send_device_id() : 0x7f);
467 mmc_buffer[3] = 0x6; // MCC
469 /* Set up the qtr frame message */
482 Session::spp_start (Parser &, nframes_t /*timestamp*/)
484 if (Config->get_mmc_control() && (!config.get_external_sync() || config.get_sync_source() != JACK)) {
485 request_transport_speed (1.0);
490 Session::spp_continue (Parser& ignored, nframes_t timestamp)
492 spp_start (ignored, timestamp);
496 Session::spp_stop (Parser&, nframes_t /*timestamp*/)
498 if (Config->get_mmc_control()) {
504 Session::mmc_deferred_play (MIDI::MachineControl &/*mmc*/)
506 if (Config->get_mmc_control() && (!config.get_external_sync() || (config.get_sync_source() != JACK))) {
507 request_transport_speed (1.0);
512 Session::mmc_record_pause (MIDI::MachineControl &/*mmc*/)
514 if (Config->get_mmc_control()) {
515 maybe_enable_record();
520 Session::mmc_record_strobe (MIDI::MachineControl &/*mmc*/)
522 if (!Config->get_mmc_control())
525 /* record strobe does an implicit "Play" command */
527 if (_transport_speed != 1.0) {
529 /* start_transport() will move from Enabled->Recording, so we
530 don't need to do anything here except enable recording.
531 its not the same as maybe_enable_record() though, because
532 that *can* switch to Recording, which we do not want.
535 save_state ("", true);
536 g_atomic_int_set (&_record_status, Enabled);
537 RecordStateChanged (); /* EMIT SIGNAL */
539 request_transport_speed (1.0);
548 Session::mmc_record_exit (MIDI::MachineControl &/*mmc*/)
550 if (Config->get_mmc_control()) {
551 disable_record (false);
556 Session::mmc_stop (MIDI::MachineControl &/*mmc*/)
558 if (Config->get_mmc_control()) {
564 Session::mmc_pause (MIDI::MachineControl &/*mmc*/)
566 if (Config->get_mmc_control()) {
568 /* We support RECORD_PAUSE, so the spec says that
569 we must interpret PAUSE like RECORD_PAUSE if
573 if (actively_recording()) {
574 maybe_enable_record ();
581 static bool step_queued = false;
584 Session::mmc_step (MIDI::MachineControl &/*mmc*/, int steps)
586 if (!Config->get_mmc_control()) {
591 struct timeval diff = { 0, 0 };
593 gettimeofday (&now, 0);
595 timersub (&now, &last_mmc_step, &diff);
597 gettimeofday (&now, 0);
598 timersub (&now, &last_mmc_step, &diff);
600 if (last_mmc_step.tv_sec != 0 && (diff.tv_usec + (diff.tv_sec * 1000000)) < _engine.usecs_per_cycle()) {
604 double diff_secs = diff.tv_sec + (diff.tv_usec / 1000000.0);
605 double cur_speed = (((steps * 0.5) * timecode_frames_per_second()) / diff_secs) / timecode_frames_per_second();
607 if (_transport_speed == 0 || cur_speed * _transport_speed < 0) {
608 /* change direction */
609 step_speed = cur_speed;
611 step_speed = (0.6 * step_speed) + (0.4 * cur_speed);
617 cerr << "delta = " << diff_secs
618 << " ct = " << _transport_speed
619 << " steps = " << steps
620 << " new speed = " << cur_speed
621 << " speed = " << step_speed
625 request_transport_speed (step_speed);
629 if (midi_control_ui) {
630 RefPtr<TimeoutSource> tsrc = TimeoutSource::create (100);
631 tsrc->connect (sigc::mem_fun (*this, &Session::mmc_step_timeout));
632 tsrc->attach (midi_control_ui->main_loop()->get_context());
639 Session::mmc_rewind (MIDI::MachineControl &/*mmc*/)
641 if (Config->get_mmc_control()) {
642 request_transport_speed(-8.0f);
647 Session::mmc_fast_forward (MIDI::MachineControl &/*mmc*/)
649 if (Config->get_mmc_control()) {
650 request_transport_speed(8.0f);
655 Session::mmc_locate (MIDI::MachineControl &/*mmc*/, const MIDI::byte* mmc_tc)
657 if (!Config->get_mmc_control()) {
661 nframes_t target_frame;
662 Timecode::Time timecode;
664 timecode.hours = mmc_tc[0] & 0xf;
665 timecode.minutes = mmc_tc[1];
666 timecode.seconds = mmc_tc[2];
667 timecode.frames = mmc_tc[3];
668 timecode.rate = timecode_frames_per_second();
669 timecode.drop = timecode_drop_frames();
671 // Also takes timecode offset into account:
672 timecode_to_sample( timecode, target_frame, true /* use_offset */, false /* use_subframes */ );
674 if (target_frame > max_frames) {
675 target_frame = max_frames;
678 /* Some (all?) MTC/MMC devices do not send a full MTC frame
679 at the end of a locate, instead sending only an MMC
680 locate command. This causes the current position
681 of an MTC slave to become out of date. Catch this.
684 MTC_Slave* mtcs = dynamic_cast<MTC_Slave*> (_slave);
687 // cerr << "Locate *with* MTC slave\n";
688 mtcs->handle_locate (mmc_tc);
690 // cerr << "Locate without MTC slave\n";
691 request_locate (target_frame, false);
696 Session::mmc_shuttle (MIDI::MachineControl &/*mmc*/, float speed, bool forw)
698 if (!Config->get_mmc_control()) {
702 if (Config->get_shuttle_speed_threshold() >= 0 && speed > Config->get_shuttle_speed_threshold()) {
703 speed *= Config->get_shuttle_speed_factor();
707 request_transport_speed (speed);
709 request_transport_speed (-speed);
714 Session::mmc_record_enable (MIDI::MachineControl &mmc, size_t trk, bool enabled)
716 if (Config->get_mmc_control()) {
718 RouteList::iterator i;
719 boost::shared_ptr<RouteList> r = routes.reader();
721 for (i = r->begin(); i != r->end(); ++i) {
724 if ((at = dynamic_cast<AudioTrack*>((*i).get())) != 0) {
725 if (trk == at->remote_control_id()) {
726 at->set_record_enable (enabled, &mmc);
734 /** Send MTC Full Frame message (complete Timecode time) for the start of this cycle.
735 * This resets the MTC code, the next quarter frame message that is sent will be
736 * the first one with the beginning of this cycle as the new start point.
739 Session::send_full_time_code(nframes_t /*nframes*/)
741 /* This function could easily send at a given frame offset, but would
742 * that be useful? Does ardour do sub-block accurate locating? [DR] */
745 Timecode::Time timecode;
747 _send_timecode_update = false;
749 if (_mtc_port == 0 || !session_send_mtc || _slave) {
753 // Get timecode time for this transport frame
754 sample_to_timecode(_transport_frame, timecode, true /* use_offset */, false /* no subframes */);
756 transmitting_timecode_time = timecode;
757 outbound_mtc_timecode_frame = _transport_frame;
759 // I don't understand this bit yet.. [DR]
760 if (((mtc_timecode_bits >> 5) != MIDI::MTC_25_FPS) && (transmitting_timecode_time.frames % 2)) {
761 // start MTC quarter frame transmission on an even frame
762 Timecode::increment (transmitting_timecode_time, config.get_subframes_per_frame());
763 outbound_mtc_timecode_frame += (nframes_t) _frames_per_timecode_frame;
766 // Compensate for audio latency
767 outbound_mtc_timecode_frame += _worst_output_latency;
768 next_quarter_frame_to_send = 0;
770 // Sync slave to the same Timecode time as we are on
778 msg[5] = mtc_timecode_bits | timecode.hours;
779 msg[6] = timecode.minutes;
780 msg[7] = timecode.seconds;
781 msg[8] = timecode.frames;
783 // Send message at offset 0, sent time is for the start of this cycle
784 if (_mtc_port->midimsg (msg, sizeof (msg), 0)) {
785 error << _("Session: could not send full MIDI time code") << endmsg;
792 /** Send MTC (quarter-frame) messages for this cycle.
793 * Must be called exactly once per cycle from the audio thread. Realtime safe.
794 * This function assumes the state of full Timecode is sane, eg. the slave is
795 * expecting quarter frame messages and has the right frame of reference (any
796 * full MTC Timecode time messages that needed to be sent should have been sent
797 * earlier already this cycle by send_full_time_code)
800 Session::send_midi_time_code_for_cycle(nframes_t nframes)
802 if (_mtc_port == 0 || _slave || !session_send_mtc || transmitting_timecode_time.negative || (next_quarter_frame_to_send < 0)) {
803 // cerr << "(MTC) Not sending MTC\n";
807 assert (next_quarter_frame_to_send >= 0);
808 assert (next_quarter_frame_to_send <= 7);
810 /* Duration of one quarter frame */
811 nframes_t quarter_frame_duration = ((long) _frames_per_timecode_frame) >> 2;
813 DEBUG_TRACE (DEBUG::MTC, string_compose ("TF %1 SF %2 NQ %3 FD %4\n", _transport_frame, outbound_mtc_timecode_frame,
814 next_quarter_frame_to_send, quarter_frame_duration));
816 assert((outbound_mtc_timecode_frame + (next_quarter_frame_to_send * quarter_frame_duration))
817 >= _transport_frame);
820 // Send quarter frames for this cycle
821 while (_transport_frame + nframes > (outbound_mtc_timecode_frame +
822 (next_quarter_frame_to_send * quarter_frame_duration))) {
824 DEBUG_TRACE (DEBUG::MTC, string_compose ("next frame to send: %1\n", next_quarter_frame_to_send));
826 switch (next_quarter_frame_to_send) {
828 mtc_msg[1] = 0x00 | (transmitting_timecode_time.frames & 0xf);
831 mtc_msg[1] = 0x10 | ((transmitting_timecode_time.frames & 0xf0) >> 4);
834 mtc_msg[1] = 0x20 | (transmitting_timecode_time.seconds & 0xf);
837 mtc_msg[1] = 0x30 | ((transmitting_timecode_time.seconds & 0xf0) >> 4);
840 mtc_msg[1] = 0x40 | (transmitting_timecode_time.minutes & 0xf);
843 mtc_msg[1] = 0x50 | ((transmitting_timecode_time.minutes & 0xf0) >> 4);
846 mtc_msg[1] = 0x60 | ((mtc_timecode_bits|transmitting_timecode_time.hours) & 0xf);
849 mtc_msg[1] = 0x70 | (((mtc_timecode_bits|transmitting_timecode_time.hours) & 0xf0) >> 4);
853 const nframes_t msg_time = (outbound_mtc_timecode_frame
854 + (quarter_frame_duration * next_quarter_frame_to_send));
856 // This message must fall within this block or something is broken
857 assert(msg_time >= _transport_frame);
858 assert(msg_time < _transport_frame + nframes);
860 nframes_t out_stamp = msg_time - _transport_frame;
861 assert(out_stamp < nframes);
863 if (_mtc_port->midimsg (mtc_msg, 2, out_stamp)) {
864 error << string_compose(_("Session: cannot send quarter-frame MTC message (%1)"), strerror (errno))
871 DEBUG_STR_APPEND(foo,"sending ");
872 DEBUG_STR_APPEND(foo, transmitting_timecode_time);
873 DEBUG_TRACE (DEBUG::MTC, string_compose ("%1 qfm = %2, stamp = %3\n", DEBUG_STR(foo).str(), next_quarter_frame_to_send,
877 // Increment quarter frame counter
878 next_quarter_frame_to_send++;
880 if (next_quarter_frame_to_send >= 8) {
881 // Wrap quarter frame counter
882 next_quarter_frame_to_send = 0;
883 // Increment timecode time twice
884 Timecode::increment( transmitting_timecode_time, config.get_subframes_per_frame() );
885 Timecode::increment( transmitting_timecode_time, config.get_subframes_per_frame() );
886 // Re-calculate timing of first quarter frame
887 //timecode_to_sample( transmitting_timecode_time, outbound_mtc_timecode_frame, true /* use_offset */, false );
888 outbound_mtc_timecode_frame += 8 * quarter_frame_duration;
895 /***********************************************************************
897 **********************************************************************/
900 Session::deliver_mmc (MIDI::MachineControl::Command cmd, nframes_t where)
902 using namespace MIDI;
904 Timecode::Time timecode;
906 if (_mmc_port == 0 || !session_send_mmc) {
907 // cerr << "Not delivering MMC " << _mmc_port << " - " << session_send_mmc << endl;
911 mmc_buffer[nbytes++] = cmd;
913 // cerr << "delivering MMC, cmd = " << hex << (int) cmd << dec << endl;
916 case MachineControl::cmdLocate:
917 timecode_time_subframes (where, timecode);
919 mmc_buffer[nbytes++] = 0x6; // byte count
920 mmc_buffer[nbytes++] = 0x1; // "TARGET" subcommand
921 mmc_buffer[nbytes++] = timecode.hours;
922 mmc_buffer[nbytes++] = timecode.minutes;
923 mmc_buffer[nbytes++] = timecode.seconds;
924 mmc_buffer[nbytes++] = timecode.frames;
925 mmc_buffer[nbytes++] = timecode.subframes;
928 case MachineControl::cmdStop:
931 case MachineControl::cmdPlay:
932 /* always convert Play into Deferred Play */
934 mmc_buffer[4] = MachineControl::cmdDeferredPlay;
937 case MachineControl::cmdDeferredPlay:
940 case MachineControl::cmdRecordStrobe:
943 case MachineControl::cmdRecordExit:
946 case MachineControl::cmdRecordPause:
955 mmc_buffer[nbytes++] = 0xf7; // terminate SysEx/MMC message
957 if (_mmc_port->midimsg (mmc_buffer, nbytes, 0)) {
958 error << string_compose(_("MMC: cannot send command %1%2%3"), &hex, cmd, &dec) << endmsg;
964 Session::mmc_step_timeout ()
969 gettimeofday (&now, 0);
971 timersub (&now, &last_mmc_step, &diff);
972 diff_usecs = diff.tv_sec * 1000000 + diff.tv_usec;
974 if (diff_usecs > 1000000.0 || fabs (_transport_speed) < 0.0000001) {
975 /* too long or too slow, stop transport */
976 request_transport_speed (0.0);
981 if (diff_usecs < 250000.0) {
982 /* too short, just keep going */
988 request_transport_speed (_transport_speed * 0.75);
992 /*---------------------------------------------------------------------------
994 ---------------------------------------------------------------------------*/
997 Session::start_midi_thread ()
999 midi_control_ui = new MidiControlUI (*this);
1000 midi_control_ui->run ();
1005 Session::terminate_midi_thread ()
1007 if (midi_control_ui) {
1008 midi_control_ui->quit ();