From 6e167cb1a835cb0b44990cc4c2b2a47db9dd2b9e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 28 Jul 2007 07:09:21 +0000 Subject: Playback from MIDI model, playback of clicked-in events. Note the diskstream chunk size affects reading of clicked-in, so you may need to seek away and back again to have new events read (this will be fixed). git-svn-id: svn://localhost/ardour2/trunk@2183 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/midi_model.h | 49 +++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 9 deletions(-) (limited to 'libs/ardour/ardour/midi_model.h') diff --git a/libs/ardour/ardour/midi_model.h b/libs/ardour/ardour/midi_model.h index 49ef21b26f..a2e2275157 100644 --- a/libs/ardour/ardour/midi_model.h +++ b/libs/ardour/ardour/midi_model.h @@ -25,6 +25,7 @@ #include #include #include +#include namespace ARDOUR { @@ -40,25 +41,46 @@ class Session; class MidiModel : public boost::noncopyable { public: struct Note { - Note(double s=0, double d=0, uint8_t n=0, uint8_t v=0) - : start(s), duration(d), note(n), velocity(v) {} + Note(double time=0, double dur=0, uint8_t note=0, uint8_t vel=0x40); + Note(const Note& copy); inline bool operator==(const Note& other) - { return start == other.start && note == other.note; } + { return time() == other.time() && note() == other.note(); } - double start; - double duration; - uint8_t note; - uint8_t velocity; + inline double time() const { return _on_event.time; } + inline double end_time() const { return _off_event.time; } + inline uint8_t note() const { return _on_event.note(); } + inline uint8_t velocity() const { return _on_event.velocity(); } + inline double duration() const { return _off_event.time - _on_event.time; } + + inline void set_duration(double d) { _off_event.time = _on_event.time + d; } + + inline MidiEvent& on_event() { return _on_event; } + inline MidiEvent& off_event() { return _off_event; } + + inline const MidiEvent& on_event() const { return _on_event; } + inline const MidiEvent& off_event() const { return _off_event; } + + private: + MidiEvent _on_event; + MidiEvent _off_event; + Byte _on_event_buffer[3]; + Byte _off_event_buffer[3]; }; MidiModel(Session& s, size_t size=0); void clear() { _notes.clear(); } + NoteMode note_mode() const { return _note_mode; } + void set_note_mode(NoteMode mode) { _note_mode = mode; } + void start_write(); + bool currently_writing() const { return _writing; } void end_write(bool delete_stuck=false); + size_t read (MidiRingBuffer& dst, nframes_t start, nframes_t nframes, nframes_t stamp_offset) const; + /** Resizes vector if necessary (NOT realtime safe) */ void append(const MidiBuffer& data); @@ -72,9 +94,16 @@ public: typedef std::vector Notes; inline static bool note_time_comparator (const Note& a, const Note& b) { - return a.start < b.start; + return a.time() < b.time(); } + struct LaterNoteEndComparator { + typedef const Note* value_type; + inline bool operator()(const Note* const a, const Note* const b) { + return a->end_time() > b->end_time(); + } + }; + inline Notes& notes() { return _notes; } inline const Notes& notes() const { return _notes; } @@ -115,10 +144,12 @@ private: Session& _session; - Notes _notes; + Notes _notes; + NoteMode _note_mode; typedef std::vector WriteNotes; WriteNotes _write_notes; + bool _writing; MidiEditCommand* _command; ///< In-progress command }; -- cgit v1.2.3