Eliminate circular dependency kludge for control_protocol/smpte.o.
[ardour.git] / libs / ardour / smf_source.cc
index 322c4dff9703396b148756fc0d9fad4fc9c3f778..78c3e558113339e97d18fa86c7192fddf97d5acd 100644 (file)
@@ -53,13 +53,15 @@ using namespace PBD;
 SMFSource::SMFSource (Session& s, const string& path, Source::Flag flags)
        : Source(s, DataType::MIDI, path, flags)
        , MidiSource(s, path)
-       , FileSource(s, DataType::MIDI, path, flags)
+       , FileSource(s, DataType::MIDI, path, string(), flags)
        , Evoral::SMF()
        , _last_ev_time_beats(0.0)
        , _last_ev_time_frames(0)
        , _smf_last_read_end (0)
        , _smf_last_read_time (0)
 {
+        /* note that origin remains empty */
+
        if (init(_path, false)) {
                throw failed_constructor ();
        }
@@ -67,8 +69,6 @@ SMFSource::SMFSource (Session& s, const string& path, Source::Flag flags)
        if (create(path)) {
                throw failed_constructor ();
        }
-
-       load_model(true, true); // FIXME
 }
 
 /** Constructor used for existing internal-to-session files. */
@@ -92,8 +92,6 @@ SMFSource::SMFSource (Session& s, const XMLNode& node, bool must_exist)
        if (open(_path)) {
                throw failed_constructor ();
        }
-
-       load_model(true, true); // FIXME
 }
 
 SMFSource::~SMFSource ()
@@ -104,9 +102,9 @@ SMFSource::~SMFSource ()
 }
 
 /** All stamps in audio frames */
-nframes_t
-SMFSource::read_unlocked (Evoral::EventSink<nframes_t>& destination, framepos_t const source_start,
-                         framepos_t start, nframes_t duration,
+framecnt_t
+SMFSource::read_unlocked (Evoral::EventSink<framepos_t>& destination, framepos_t const source_start,
+                         framepos_t start, framecnt_t duration,
                          MidiStateTracker* tracker) const
 {
        int      ret  = 0;
@@ -205,12 +203,12 @@ SMFSource::read_unlocked (Evoral::EventSink<nframes_t>& destination, framepos_t
  *  @param source Buffer to read from.
  *  @param position This source's start position in session frames.
  */
-nframes_t
-SMFSource::write_unlocked (MidiRingBuffer<nframes_t>& source, framepos_t position, nframes_t duration)
+framecnt_t
+SMFSource::write_unlocked (MidiRingBuffer<framepos_t>& source, framepos_t position, framecnt_t duration)
 {
        _write_data_count = 0;
 
-       nframes_t         time;
+       framepos_t        time;
        Evoral::EventType type;
        uint32_t          size;
 
@@ -221,7 +219,7 @@ SMFSource::write_unlocked (MidiRingBuffer<nframes_t>& source, framepos_t positio
                _model->start_write();
        }
 
-       Evoral::MIDIEvent<nframes_t> ev;
+       Evoral::MIDIEvent<framepos_t> ev;
 
        while (true) {
                bool ret = source.peek_time(&time);
@@ -266,8 +264,6 @@ SMFSource::write_unlocked (MidiRingBuffer<nframes_t>& source, framepos_t positio
        Evoral::SMF::flush();
        free(buf);
 
-       ViewDataRangeReady (_last_write_end, duration); /* EMIT SIGNAL */
-
        return duration;
 }
 
@@ -315,9 +311,9 @@ SMFSource::append_event_unlocked_beats (const Evoral::Event<double>& ev)
 
 }
 
-/** Append an event with a timestamp in frames (nframes_t) */
+/** Append an event with a timestamp in frames (framepos_t) */
 void
-SMFSource::append_event_unlocked_frames (const Evoral::Event<nframes_t>& ev, framepos_t position)
+SMFSource::append_event_unlocked_frames (const Evoral::Event<framepos_t>& ev, framepos_t position)
 {
        assert(_writing);
        if (ev.size() == 0)  {
@@ -367,7 +363,9 @@ SMFSource::append_event_unlocked_frames (const Evoral::Event<nframes_t>& ev, fra
 XMLNode&
 SMFSource::get_state ()
 {
-       return MidiSource::get_state();
+        XMLNode& node = MidiSource::get_state();
+        node.add_property (X_("origin"), _origin);
+        return node;
 }
 
 int
@@ -440,8 +438,8 @@ SMFSource::load_model (bool lock, bool force_reload)
                return;
        }
 
-       if (! _model) {
-               _model = boost::shared_ptr<MidiModel>(new MidiModel(this));
+       if (!_model) {
+               _model = boost::shared_ptr<MidiModel> (new MidiModel (shared_from_this ()));
        } else {
                _model->clear();
        }