From 7ff7f4013dfbbf18d08e397230ad2486fa7ff58f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 9 Jun 2007 02:07:59 +0000 Subject: Use double MIDI timestamps (towards tempo based time, and more-than-sample-accurate LV2 MIDI plugin application). Eliminate double iteration over MIDIRingBuffer read to translate timestamps. git-svn-id: svn://localhost/ardour2/trunk@1981 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/buffer.cc | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'libs/ardour/buffer.cc') diff --git a/libs/ardour/buffer.cc b/libs/ardour/buffer.cc index 0328122940..2ab70cc96b 100644 --- a/libs/ardour/buffer.cc +++ b/libs/ardour/buffer.cc @@ -153,6 +153,35 @@ MidiBuffer::push_back(const MidiEvent& ev) } +/** Push an event into the buffer. + * + * Note that the raw MIDI pointed to by ev will be COPIED and unmodified. + * That is, the caller still owns it, if it needs freeing it's Not My Problem(TM). + * Realtime safe. + * @return false if operation failed (not enough room) + */ +bool +MidiBuffer::push_back(const jack_midi_event_t& ev) +{ + if (_size == _capacity) + return false; + + Byte* const write_loc = _data + (_size * MAX_EVENT_SIZE); + + memcpy(write_loc, ev.buffer, ev.size); + _events[_size].time = (double)ev.time; + _events[_size].size = ev.size; + _events[_size].buffer = write_loc; + ++_size; + + //cerr << "MidiBuffer: pushed, size = " << _size << endl; + + _silent = false; + + return true; +} + + /** Reserve space for a new event in the buffer. * * This call is for copying MIDI directly into the buffer, the data location @@ -161,7 +190,7 @@ MidiBuffer::push_back(const MidiEvent& ev) * location, or the buffer will be corrupted and very nasty things will happen. */ Byte* -MidiBuffer::reserve(nframes_t time, size_t size) +MidiBuffer::reserve(double time, size_t size) { assert(size < MAX_EVENT_SIZE); -- cgit v1.2.3