Add a missing #define to our MSVC project (portaudio_backend)
[ardour.git] / libs / ardour / session_midi.cc
index 6d7fea3b266e7f62743d8c155add675f56eda7cf..b0fb9460110effc126220db4244fcc1a2210689f 100644 (file)
@@ -48,7 +48,7 @@
 #include "ardour/slave.h"
 #include "ardour/ticker.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -426,13 +426,13 @@ Session::send_full_time_code (framepos_t const t, MIDI::pframes_t nframes)
        // or a new full timecode will be queued next cycle.
        while (outbound_mtc_timecode_frame < t) {
                Timecode::increment (transmitting_timecode_time, config.get_subframes_per_frame());
-               outbound_mtc_timecode_frame += _frames_per_timecode_frame;
+               outbound_mtc_timecode_frame += _samples_per_timecode_frame;
        }
 
-       double const quarter_frame_duration = ((framecnt_t) _frames_per_timecode_frame) / 4.0;
+       double const quarter_frame_duration = ((framecnt_t) _samples_per_timecode_frame) / 4.0;
        if (ceil((t - mtc_tc) / quarter_frame_duration) > 0) {
                Timecode::increment (transmitting_timecode_time, config.get_subframes_per_frame());
-               outbound_mtc_timecode_frame += _frames_per_timecode_frame;
+               outbound_mtc_timecode_frame += _samples_per_timecode_frame;
        }
 
        DEBUG_TRACE (DEBUG::MTC, string_compose ("Full MTC TC %1 (off %2)\n", outbound_mtc_timecode_frame, mtc_offset));
@@ -443,7 +443,7 @@ Session::send_full_time_code (framepos_t const t, MIDI::pframes_t nframes)
        if (((mtc_timecode_bits >> 5) != MIDI::MTC_25_FPS) && (transmitting_timecode_time.frames % 2)) {
                // start MTC quarter frame transmission on an even frame
                Timecode::increment (transmitting_timecode_time, config.get_subframes_per_frame());
-               outbound_mtc_timecode_frame += _frames_per_timecode_frame;
+               outbound_mtc_timecode_frame += _samples_per_timecode_frame;
        }
 
        next_quarter_frame_to_send = 0;
@@ -507,7 +507,7 @@ Session::send_midi_time_code_for_cycle (framepos_t start_frame, framepos_t end_f
        assert (next_quarter_frame_to_send <= 7);
 
        /* Duration of one quarter frame */
-       double const quarter_frame_duration = _frames_per_timecode_frame / 4.0;
+       double const quarter_frame_duration = _samples_per_timecode_frame / 4.0;
 
        DEBUG_TRACE (DEBUG::MTC, string_compose ("TF %1 SF %2 MT %3 QF %4 QD %5\n",
                                _transport_frame, start_frame, outbound_mtc_timecode_frame,
@@ -592,7 +592,7 @@ Session::send_midi_time_code_for_cycle (framepos_t start_frame, framepos_t end_f
                        Timecode::increment (transmitting_timecode_time, config.get_subframes_per_frame());
                        Timecode::increment (transmitting_timecode_time, config.get_subframes_per_frame());
                        // Increment timing of first quarter frame
-                       outbound_mtc_timecode_frame += 2.0 * _frames_per_timecode_frame;
+                       outbound_mtc_timecode_frame += 2.0 * _samples_per_timecode_frame;
                }
        }
 
@@ -722,3 +722,82 @@ Session::mtc_input_port () const
 {
        return _midi_ports->mtc_input_port ();
 }
+
+void
+Session::midi_track_presentation_info_changed (PropertyChange const& what_changed, boost::weak_ptr<MidiTrack> mt)
+{
+       if (!Config->get_midi_input_follows_selection()) {
+               return;
+       }
+
+       if (!what_changed.contains (Properties::selected)) {
+               return;
+       }
+
+       boost::shared_ptr<MidiTrack> new_midi_target (mt.lock ());
+
+       if (new_midi_target->presentation_info().selected()) {
+               rewire_selected_midi (new_midi_target);
+       }
+}
+
+void
+Session::rewire_selected_midi (boost::shared_ptr<MidiTrack> new_midi_target)
+{
+       if (!new_midi_target) {
+               return;
+       }
+
+       boost::shared_ptr<MidiTrack> old_midi_target = current_midi_target.lock ();
+
+       if (new_midi_target == old_midi_target) {
+               return;
+       }
+
+       vector<string> msp;
+       AudioEngine::instance()->get_midi_selection_ports (msp);
+
+       if (!msp.empty()) {
+
+               if (old_midi_target) {
+                       old_midi_target->input()->disconnect (this);
+               }
+
+               for (vector<string>::const_iterator p = msp.begin(); p != msp.end(); ++p) {
+                       /* disconnect the port from everything */
+                       AudioEngine::instance()->disconnect (*p);
+                       /* connect it to the new target */
+                       new_midi_target->input()->connect (new_midi_target->input()->nth(0), (*p), this);
+               }
+       }
+
+       current_midi_target = new_midi_target;
+}
+
+void
+Session::rewire_midi_selection_ports ()
+{
+       if (!Config->get_midi_input_follows_selection()) {
+               return;
+       }
+
+       boost::shared_ptr<MidiTrack> target = current_midi_target.lock();
+
+       if (!target) {
+               return;
+       }
+
+       vector<string> msp;
+       AudioEngine::instance()->get_midi_selection_ports (msp);
+
+       if (msp.empty()) {
+               return;
+       }
+
+       target->input()->disconnect (this);
+
+       for (vector<string>::const_iterator p = msp.begin(); p != msp.end(); ++p) {
+               AudioEngine::instance()->disconnect (*p);
+               target->input()->connect (target->input()->nth (0), (*p), this);
+       }
+}