use a note tracker to resolve notes cut off during render by the end of the region
[ardour.git] / libs / ardour / session_midi.cc
index cc12b959d5e9302d5f674f529248f5929d5a884c..7b961ac6ba4cc4a6b687938c1804173e064eabc5 100644 (file)
@@ -1,21 +1,27 @@
 /*
-  Copyright (C) 1999-2002 Paul Davis
-
-  This program is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program; if not, write to the Free Software
-  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
+ * Copyright (C) 2005-2009 Taybin Rutkin <taybin@taybin.com>
+ * Copyright (C) 2005-2019 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2006-2012 David Robillard <d@drobilla.net>
+ * Copyright (C) 2008 Hans Baier <hansfbaier@googlemail.com>
+ * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
+ * Copyright (C) 2012-2019 Robin Gareus <robin@gareus.org>
+ * Copyright (C) 2013 John Emmas <john@creativepost.co.uk>
+ * Copyright (C) 2013 Michael Fisher <mfisher31@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
 #include <string>
 #include <cmath>
@@ -77,7 +83,7 @@ Session::setup_midi_control ()
        outbound_mtc_timecode_frame = 0;
        next_quarter_frame_to_send = 0;
 
-       /* Set up the qtr sample message */
+       /* Set up the qtr frame message */
 
        mtc_msg[0] = 0xf1;
        mtc_msg[2] = 0xf1;
@@ -130,19 +136,6 @@ Session::mmc_record_pause (MIDI::MachineControl &/*mmc*/)
 void
 Session::mmc_record_strobe (MIDI::MachineControl &/*mmc*/)
 {
-       if (Profile->get_trx()) {
-
-               /* In Tracks Live, there is no concept of punch, so we just
-                  treat RecordStrobe like RecordPause. This violates the MMC
-                  specification.
-               */
-
-               if (Config->get_mmc_control()) {
-                       maybe_enable_record();
-               }
-               return;
-       }
-
        if (!Config->get_mmc_control() || (_step_editors > 0)) {
                return;
        }
@@ -300,7 +293,7 @@ Session::mmc_locate (MIDI::MachineControl &/*mmc*/, const MIDI::byte* mmc_tc)
                target_sample = max_samplepos;
        }
 
-       /* Some (all?) MTC/MMC devices do not send a full MTC sample
+       /* Some (all?) MTC/MMC devices do not send a full MTC frame
           at the end of a locate, instead sending only an MMC
           locate command. This causes the current position
           of an MTC slave to become out of date. Catch this.
@@ -438,11 +431,9 @@ Session::send_full_time_code (samplepos_t const t, MIDI::pframes_t nframes)
 
        DEBUG_TRACE (DEBUG::MTC, string_compose ("Full MTC TC %1 (off %2)\n", outbound_mtc_timecode_frame, mtc_offset));
 
-       // I don't understand this bit yet.. [DR]
-       // I do [rg]:
-       // according to MTC spec 24, 30 drop and 30 non-drop TC, the sample-number represented by 8 quarter frames must be even.
+       /* according to MTC spec 24, 30 drop and 30 non-drop TC, the frame-number represented by 8 quarter frames must be even. */
        if (((mtc_timecode_bits >> 5) != MIDI::MTC_25_FPS) && (transmitting_timecode_time.frames % 2)) {
-               // start MTC quarter frame transmission on an even sample
+               /* start MTC quarter frame transmission on an even frame */
                Timecode::increment (transmitting_timecode_time, config.get_subframes_per_frame());
                outbound_mtc_timecode_frame += _samples_per_timecode_frame;
        }
@@ -474,7 +465,7 @@ Session::send_full_time_code (samplepos_t const t, MIDI::pframes_t nframes)
 /** Send MTC (quarter-frame) messages for this cycle.
  * Must be called exactly once per cycle from the process thread.  Realtime safe.
  * This function assumes the state of full Timecode is sane, eg. the slave is
- * expecting quarter frame messages and has the right sample of reference (any
+ * expecting quarter frame messages and has the right frame of reference (any
  * full MTC Timecode time messages that needed to be sent should have been sent
  * earlier already this cycle by send_full_time_code)
  */
@@ -556,7 +547,7 @@ Session::send_midi_time_code_for_cycle (samplepos_t start_sample, samplepos_t en
                        break;
                }
 
-               const samplepos_t msg_time = rint(outbound_mtc_timecode_frame   + (quarter_frame_duration * next_quarter_frame_to_send));
+               const samplepos_t msg_time = rint (outbound_mtc_timecode_frame + (quarter_frame_duration * next_quarter_frame_to_send));
 
                // This message must fall within this block or something is broken
                assert (msg_time >= start_sample);
@@ -575,8 +566,8 @@ Session::send_midi_time_code_for_cycle (samplepos_t start_sample, samplepos_t en
 
 #ifndef NDEBUG
                if (DEBUG_ENABLED(DEBUG::MTC)) {
-                       DEBUG_STR_DECL(foo)
-                               DEBUG_STR_APPEND(foo,"sending ");
+                       DEBUG_STR_DECL(foo);
+                       DEBUG_STR_APPEND(foo,"sending ");
                        DEBUG_STR_APPEND(foo, transmitting_timecode_time);
                        DEBUG_TRACE (DEBUG::MTC, string_compose ("%1 qfm = %2, stamp = %3\n", DEBUG_STR(foo).str(), next_quarter_frame_to_send,
                                                                 out_stamp));
@@ -644,10 +635,9 @@ Session::mmc_step_timeout ()
        return true;
 }
 
-/***********************************************************************
- OUTBOUND SYSTEM COMMON STUFF
-**********************************************************************/
-
+/* *********************************************************************
+ * OUTBOUND SYSTEM COMMON STUFF
+ **********************************************************************/
 
 void
 Session::send_song_position_pointer (samplepos_t)
@@ -702,13 +692,18 @@ Session::scene_input_port () const
        return _midi_ports->scene_input_port ();
 }
 
+boost::shared_ptr<AsyncMIDIPort>
+Session::vkbd_output_port () const
+{
+       return _midi_ports->vkbd_output_port ();
+}
+
 boost::shared_ptr<MidiPort>
 Session::midi_clock_output_port () const
 {
        return _midi_ports->midi_clock_output_port ();
 }
 
-
 boost::shared_ptr<MidiPort>
 Session::mtc_output_port () const
 {