From 15cdf454ea5a1460b41cb462c35f1ffb853a0764 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 10 Oct 2008 00:39:29 +0000 Subject: Apply MIDI looping patch from torbenh, with minor changes. General idea: use internal events to mark loop boundaries in MIDI buffers so readers can make sense of timestamps. git-svn-id: svn://localhost/ardour2/branches/3.0@3905 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/event_type_map.h | 4 ++++ libs/ardour/ardour/midi_diskstream.h | 8 ++++++-- libs/ardour/ardour/midi_ring_buffer.h | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) (limited to 'libs/ardour/ardour') diff --git a/libs/ardour/ardour/event_type_map.h b/libs/ardour/ardour/event_type_map.h index 99911121c5..dfa11d6408 100644 --- a/libs/ardour/ardour/event_type_map.h +++ b/libs/ardour/ardour/event_type_map.h @@ -46,6 +46,10 @@ private: static EventTypeMap event_type_map; }; +enum InternalEventType { + LoopEventType = 1000 +}; + } // namespace ARDOUR #endif /* __ardour_event_type_map_h__ */ diff --git a/libs/ardour/ardour/midi_diskstream.h b/libs/ardour/ardour/midi_diskstream.h index 28e80816a8..a3d4d6d0a4 100644 --- a/libs/ardour/ardour/midi_diskstream.h +++ b/libs/ardour/ardour/midi_diskstream.h @@ -46,6 +46,7 @@ #include #include #include +#include struct tm; @@ -68,7 +69,7 @@ class MidiDiskstream : public Diskstream float playback_buffer_load() const; float capture_buffer_load() const; - void get_playback(MidiBuffer& dst, nframes_t start, nframes_t end); + void get_playback(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t offset); void set_record_enabled (bool yn); @@ -170,13 +171,16 @@ class MidiDiskstream : public Diskstream void engage_record_enable (); void disengage_record_enable (); - + void check_note_onoffs(Evoral::MIDIEvent &event); + void emit_pending_note_offs(MidiBuffer &dst, nframes_t time); + MidiRingBuffer* _playback_buf; MidiRingBuffer* _capture_buf; MidiPort* _source_port; boost::shared_ptr _write_source; nframes_t _last_flush_frame; NoteMode _note_mode; + MidiStateTracker _midistate_tracker; }; }; /* namespace ARDOUR */ diff --git a/libs/ardour/ardour/midi_ring_buffer.h b/libs/ardour/ardour/midi_ring_buffer.h index d1acb9b235..6e827d2852 100644 --- a/libs/ardour/ardour/midi_ring_buffer.h +++ b/libs/ardour/ardour/midi_ring_buffer.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -148,6 +149,18 @@ MidiRingBuffer::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t continue; } + // This event marks a loop happening. this means that + // the next events timestamp will be non-monotonic. + if (ev_type == LoopEventType) { + ev_time -= start; + Evoral::MIDIEvent loopevent(LoopEventType, ev_time); + dst.push_back(loopevent); + + // We can safely return, without reading the data, because + // a LoopEvent does not have data. + return count + 1; + } + uint8_t status; success = full_peek(sizeof(uint8_t), &status); assert(success); // If this failed, buffer is corrupt, all hope is lost @@ -168,6 +181,7 @@ MidiRingBuffer::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t assert(ev_time >= start); ev_time -= start; + ev_time += offset; uint8_t* write_loc = dst.reserve(ev_time, ev_size); if (write_loc == NULL) { -- cgit v1.2.3