Use nframes_t for timestamps of real (jack) time MIDI events (i.e. in MidiBuffer...
[ardour.git] / libs / ardour / ardour / midi_source.h
index 997f3f9d6948a456c4d8e6ea09027978563e4dba..2126b4b162324740b9844a0c0d27c0573b6282e5 100644 (file)
@@ -39,12 +39,14 @@ using std::string;
 
 namespace ARDOUR {
 
-class MidiRingBuffer;
+template<typename T> class MidiRingBuffer;
 
 /** Source for MIDI data */
 class MidiSource : public Source
 {
   public:
+       typedef double TimeType;
+
        MidiSource (Session& session, string name);
        MidiSource (Session& session, const XMLNode&);
        virtual ~MidiSource ();
@@ -55,10 +57,10 @@ class MidiSource : public Source
        virtual uint32_t    n_channels () const { return 1; }
        
        // FIXME: integrate this with the Readable::read interface somehow
-       virtual nframes_t midi_read (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset, nframes_t negative_stamp_offset) const;
-       virtual nframes_t midi_write (MidiRingBuffer& src, nframes_t cnt);
+       virtual nframes_t midi_read (MidiRingBuffer<nframes_t>& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset, nframes_t negative_stamp_offset) const;
+       virtual nframes_t midi_write (MidiRingBuffer<nframes_t>& src, nframes_t cnt);
 
-       virtual void append_event_unlocked(EventTimeUnit unit, const MIDI::Event& ev) = 0;
+       virtual void append_event_unlocked(EventTimeUnit unit, const Evoral::Event<TimeType>& ev) = 0;
 
        virtual void mark_for_remove() = 0;
        virtual void mark_streaming_midi_write_started (NoteMode mode, nframes_t start_time);
@@ -95,11 +97,10 @@ class MidiSource : public Source
        void set_model(boost::shared_ptr<MidiModel> m) { _model = m; }
 
   protected:
-       virtual int flush_header() = 0;
-       virtual int flush_footer() = 0;
+       virtual void flush_midi() = 0;
        
-       virtual nframes_t read_unlocked (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset, nframes_t negative_stamp_offset) const = 0;
-       virtual nframes_t write_unlocked (MidiRingBuffer& dst, nframes_t cnt) = 0;
+       virtual nframes_t read_unlocked (MidiRingBuffer<nframes_t>& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset, nframes_t negative_stamp_offset) const = 0;
+       virtual nframes_t write_unlocked (MidiRingBuffer<nframes_t>& dst, nframes_t cnt) = 0;
        
        mutable Glib::Mutex _lock;
        string              _captured_for;
@@ -109,6 +110,9 @@ class MidiSource : public Source
 
        boost::shared_ptr<MidiModel> _model;
        bool                         _writing;
+       
+       mutable Evoral::Sequence<double>::const_iterator _model_iter;
+       mutable nframes_t                                _last_read_end;
 
   private:
        bool file_changed (string path);