Rewrote MidiRingBuffer to more efficiently pack data (flat pack stamps, sizes, and...
[ardour.git] / libs / ardour / ardour / midi_source.h
index 735ebba44732391c49146b29f18920cf75a329d7..dec9536c741c84f2eebe222fe61f0ae9aa503524 100644 (file)
 
 #include <ardour/source.h>
 #include <ardour/ardour.h>
-#include <ardour/stateful.h>
+#include <ardour/buffer.h>
+#include <pbd/stateful.h>
 #include <pbd/xml++.h>
 
 using std::string;
 
 namespace ARDOUR {
 
-/** Source for raw MIDI data */
+class MidiRingBuffer;
+
+/** Source for MIDI data */
 class MidiSource : public Source
 {
   public:
-       MidiSource (string name);
-       MidiSource (const XMLNode&);
+       MidiSource (Session& session, string name);
+       MidiSource (Session& session, const XMLNode&);
        virtual ~MidiSource ();
-
-       /* returns the number of items in this `midi_source' */
-
-       // Applicable to MIDI?  With what unit? [DR]
-       virtual jack_nframes_t length() const {
-               return _length;
-       }
-
-       virtual jack_nframes_t read (unsigned char *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
-       virtual jack_nframes_t write (unsigned char *src, jack_nframes_t cnt, char * workbuf);
+       
+       virtual nframes_t read (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset) const;
+       virtual nframes_t write (MidiRingBuffer& src, nframes_t cnt);
 
        virtual void mark_for_remove() = 0;
        virtual void mark_streaming_write_completed () {}
 
-       void set_captured_for (string str) { _captured_for = str; }
        string captured_for() const { return _captured_for; }
+       void   set_captured_for (string str) { _captured_for = str; }
 
-       uint32_t read_data_count() const { return _read_data_count; }
+       uint32_t read_data_count()  const { return _read_data_count; }
        uint32_t write_data_count() const { return _write_data_count; }
 
        static sigc::signal<void,MidiSource*> MidiSourceCreated;
               
-       mutable sigc::signal<void>  PeaksReady;
-       mutable sigc::signal<void,jack_nframes_t,jack_nframes_t>  PeakRangeReady;
+       // The MIDI equivalent to "peaks"
+       mutable sigc::signal<void,boost::shared_ptr<MidiBuffer>,nframes_t,nframes_t> ViewDataRangeReady;
        
        XMLNode& get_state ();
        int set_state (const XMLNode&);
 
   protected:
-       jack_nframes_t   _length;
-       string           _captured_for;
-
-       mutable uint32_t _read_data_count;  // modified in read()
-       mutable uint32_t _write_data_count; // modified in write()
-
-       virtual jack_nframes_t read_unlocked (unsigned char *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const = 0;
-       virtual jack_nframes_t write_unlocked (unsigned char *dst, jack_nframes_t cnt, char * workbuf) = 0;
+       virtual nframes_t read_unlocked (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset) const = 0;
+       virtual nframes_t write_unlocked (MidiRingBuffer& dst, nframes_t cnt) = 0;
        
-       void update_length (jack_nframes_t pos, jack_nframes_t cnt);
+       mutable Glib::Mutex _lock;
+       string              _captured_for;
+       mutable uint32_t    _read_data_count;  ///< modified in read()
+       mutable uint32_t    _write_data_count; ///< modified in write()
 
   private:
        bool file_changed (string path);