Set new (recorded) MIDI source length to length of entire capture (instead of length...
[ardour.git] / libs / ardour / ardour / midi_source.h
index 3bad6d6ddc871f0f7eb27c1d5724ea857b64c9e2..c58452c044e70ca1731940493c292f4252c81273 100644 (file)
@@ -23,6 +23,7 @@
 #include <string>
 #include <time.h>
 #include <glibmm/thread.h>
+#include <boost/enable_shared_from_this.hpp>
 #include "pbd/stateful.h"
 #include "pbd/xml++.h"
 #include "evoral/Sequence.hpp"
@@ -38,7 +39,7 @@ class MidiModel;
 template<typename T> class MidiRingBuffer;
 
 /** Source for MIDI data */
-class MidiSource : virtual public Source
+class MidiSource : virtual public Source, public boost::enable_shared_from_this<MidiSource>
 {
   public:
        typedef double TimeType;
@@ -58,19 +59,19 @@ class MidiSource : virtual public Source
         * \param cnt Length of range to be read (in audio frames)
         * \param tracker an optional pointer to MidiStateTracker object, for note on/off tracking
         */
-       virtual nframes_t midi_read (Evoral::EventSink<nframes_t>& dst,
-                                    framepos_t source_start,
-                                    framepos_t start, nframes_t cnt,
-                                    MidiStateTracker*,
-                                    std::set<Evoral::Parameter> const &) const;
+       virtual framecnt_t midi_read (Evoral::EventSink<framepos_t>& dst,
+                                     framepos_t source_start,
+                                     framepos_t start, framecnt_t cnt,
+                                     MidiStateTracker*,
+                                     std::set<Evoral::Parameter> const &) const;
 
-       virtual nframes_t midi_write (MidiRingBuffer<nframes_t>& src,
-                                     framepos_t source_start,
-                                     nframes_t cnt);
+       virtual framecnt_t midi_write (MidiRingBuffer<framepos_t>& src,
+                                      framepos_t source_start,
+                                      framecnt_t cnt);
 
        virtual void append_event_unlocked_beats(const Evoral::Event<Evoral::MusicalTime>& ev) = 0;
 
-       virtual void append_event_unlocked_frames(const Evoral::Event<nframes_t>& ev,
+       virtual void append_event_unlocked_frames(const Evoral::Event<framepos_t>& ev,
                        framepos_t source_start) = 0;
 
        virtual bool       empty () const;
@@ -91,14 +92,14 @@ class MidiSource : virtual public Source
 
        static PBD::Signal1<void,MidiSource*> MidiSourceCreated;
 
-       // Signal a range of recorded data is available for reading from model()
-       mutable PBD::Signal2<void,framepos_t,nframes_t> ViewDataRangeReady;
-
        XMLNode& get_state ();
        int set_state (const XMLNode&, int version);
 
        bool length_mutable() const { return true; }
 
+       void set_length_beats(double l) { _length_beats = l; }
+       double length_beats() const { return _length_beats; }
+
        virtual void load_model(bool lock=true, bool force_reload=false) = 0;
        virtual void destroy_model() = 0;
 
@@ -133,14 +134,14 @@ class MidiSource : virtual public Source
   protected:
        virtual void flush_midi() = 0;
 
-       virtual nframes_t read_unlocked (Evoral::EventSink<nframes_t>& dst,
-                                        framepos_t position,
-                                        framepos_t start, nframes_t cnt,
-                                        MidiStateTracker* tracker) const = 0;
+       virtual framepos_t read_unlocked (Evoral::EventSink<framepos_t>& dst,
+                                         framepos_t position,
+                                         framepos_t start, framecnt_t cnt,
+                                         MidiStateTracker* tracker) const = 0;
 
-       virtual nframes_t write_unlocked (MidiRingBuffer<nframes_t>& dst,
-                       framepos_t position,
-                       nframes_t cnt) = 0;
+       virtual framepos_t write_unlocked (MidiRingBuffer<framepos_t>& dst,
+                                          framepos_t position,
+                                          framecnt_t cnt) = 0;
 
        std::string      _captured_for;
        mutable uint32_t _read_data_count;  ///< modified in read()
@@ -152,7 +153,7 @@ class MidiSource : virtual public Source
        mutable Evoral::Sequence<Evoral::MusicalTime>::const_iterator _model_iter;
        mutable bool                                                  _model_iter_valid;
 
-       mutable double    _length_beats;
+       mutable double     _length_beats;
        mutable framepos_t _last_read_end;
        framepos_t         _last_write_end;