continue with MTC debugging
[ardour.git] / libs / ardour / smf_source.cc
index 3e35e58fb95bb9a75f9aeb29e50d70bab9361b1a..f48fc301f71cd7d77de994c964814a8b91e29d06 100644 (file)
@@ -49,22 +49,24 @@ using namespace ARDOUR;
 using namespace Glib;
 
 /** Constructor used for new internal-to-session files.  File cannot exist. */
-SMFSource::SMFSource (Session& s, const ustring& path, bool embedded, Source::Flag flags)
+SMFSource::SMFSource (Session& s, const ustring& path, Source::Flag flags)
        : Source(s, DataType::MIDI, path, flags)
        , MidiSource(s, path)
-       , FileSource(s, DataType::MIDI, path, embedded, flags)
+       , FileSource(s, DataType::MIDI, path, flags)
        , Evoral::SMF()
        , _last_ev_time_beats(0.0)
        , _last_ev_time_frames(0)
        , _smf_last_read_end (0)
 {
-       if (init(_name, false)) {
+       if (init(_path, false)) {
                throw failed_constructor ();
        }
 
        if (create(path)) {
                throw failed_constructor ();
        }
+
+       load_model(true, true); // FIXME
 }
 
 /** Constructor used for existing internal-to-session files. */
@@ -80,13 +82,15 @@ SMFSource::SMFSource (Session& s, const XMLNode& node, bool must_exist)
                throw failed_constructor ();
        }
 
-       if (init(_name, true)) {
+       if (init(_path, true)) {
                throw failed_constructor ();
        }
 
        if (open(_path)) {
                throw failed_constructor ();
        }
+
+       load_model(true, true); // FIXME
 }
 
 SMFSource::~SMFSource ()
@@ -98,7 +102,7 @@ SMFSource::~SMFSource ()
 
 /** All stamps in audio frames */
 nframes_t
-SMFSource::read_unlocked (MidiRingBuffer<nframes_t>& destination, sframes_t source_start,
+SMFSource::read_unlocked (Evoral::EventSink<nframes_t>& destination, sframes_t source_start,
                          sframes_t start, nframes_t duration,
                          sframes_t stamp_offset, sframes_t negative_stamp_offset,
                          MidiStateTracker* tracker) const
@@ -116,7 +120,7 @@ SMFSource::read_unlocked (MidiRingBuffer<nframes_t>& destination, sframes_t sour
 
        size_t scratch_size = 0; // keep track of scratch to minimize reallocs
 
-       BeatsFramesConverter converter(_session, source_start);
+       BeatsFramesConverter converter(_session.tempo_map(), source_start);
 
        const uint64_t start_ticks = (uint64_t)(converter.from(start) * ppqn());
 
@@ -179,7 +183,7 @@ SMFSource::read_unlocked (MidiRingBuffer<nframes_t>& destination, sframes_t sour
                } else {
                        break;
                }
-               
+
                _read_data_count += ev_size;
 
                if (ev_size > scratch_size) {
@@ -264,6 +268,7 @@ SMFSource::write_unlocked (MidiRingBuffer<nframes_t>& source, sframes_t position
 void
 SMFSource::append_event_unlocked_beats (const Evoral::Event<double>& ev)
 {
+       assert(_writing);
        if (ev.size() == 0)  {
                return;
        }
@@ -297,6 +302,7 @@ SMFSource::append_event_unlocked_beats (const Evoral::Event<double>& ev)
 void
 SMFSource::append_event_unlocked_frames (const Evoral::Event<nframes_t>& ev, sframes_t position)
 {
+       assert(_writing);
        if (ev.size() == 0)  {
                return;
        }
@@ -310,7 +316,7 @@ SMFSource::append_event_unlocked_frames (const Evoral::Event<nframes_t>& ev, sfr
                return;
        }
 
-       BeatsFramesConverter converter(_session, position);
+       BeatsFramesConverter converter(_session.tempo_map(), position);
 
        _length_beats = max(_length_beats, converter.from(ev.time()));
 
@@ -358,6 +364,7 @@ SMFSource::set_state (const XMLNode& node, int version)
 void
 SMFSource::mark_streaming_midi_write_started (NoteMode mode, sframes_t start_frame)
 {
+       Glib::Mutex::Lock lm (_lock);
        MidiSource::mark_streaming_midi_write_started (mode, start_frame);
        Evoral::SMF::begin_write ();
        _last_ev_time_beats = 0.0;
@@ -367,6 +374,7 @@ SMFSource::mark_streaming_midi_write_started (NoteMode mode, sframes_t start_fra
 void
 SMFSource::mark_streaming_write_completed ()
 {
+       Glib::Mutex::Lock lm (_lock);
        MidiSource::mark_streaming_write_completed();
 
        if (!writable()) {
@@ -390,9 +398,9 @@ SMFSource::load_model (bool lock, bool force_reload)
                return;
        }
 
-       if (lock) {
-               Glib::Mutex::Lock lm (_lock);
-       }
+       boost::shared_ptr<Glib::Mutex::Lock> lm;
+       if (lock)
+               lm = boost::shared_ptr<Glib::Mutex::Lock>(new Glib::Mutex::Lock(_lock));
 
        if (_model && !force_reload) {
                return;
@@ -446,8 +454,6 @@ SMFSource::load_model (bool lock, bool force_reload)
        free(buf);
 }
 
-#define LINEAR_INTERPOLATION_MODE_WORKS_PROPERLY 0
-
 void
 SMFSource::set_default_controls_interpolation ()
 {
@@ -455,12 +461,7 @@ SMFSource::set_default_controls_interpolation ()
        Evoral::ControlSet::Controls controls = _model->controls();
        for (Evoral::ControlSet::Controls::iterator c = controls.begin(); c != controls.end(); ++c) {
                (*c).second->list()->set_interpolation(
-                       // to be enabled when ControlList::rt_safe_earliest_event_linear_unlocked works properly
-                       #if LINEAR_INTERPOLATION_MODE_WORKS_PROPERLY
                        EventTypeMap::instance().interpolation_of((*c).first));
-                       #else
-                       Evoral::ControlList::Discrete);
-                       #endif
        }
 }