summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour/midi_buffer.h
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2013-03-27 21:50:18 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2013-03-27 21:50:18 -0400
commit4abbabdcf9c6d6d98ba261d91846577a2fa2f05e (patch)
tree5a7134ccc9508a6f1da25ef3dc6d432bdc25a04f /libs/ardour/ardour/midi_buffer.h
parent78aa7a13fd5e5abac70637ce6641b7d2e73dd541 (diff)
Squashed commit of the following:
commit fdbae82077db53add90df7448a06869dac89acc6 Author: Paul Davis <paul@linuxaudiosystems.com> Date: Wed Mar 27 21:45:28 2013 -0400 mammoth changes in basic signal flow, total redesign of MIDI channel filtering and more. commit 59343a8283698e02bc0f622313b29e98f449e4c8 Author: Paul Davis <paul@linuxaudiosystems.com> Date: Wed Mar 27 01:58:53 2013 -0400 initial working version after changes to MIDI channel filtering. may affect metering input too. testing not yet finished this commit merges many deep changes in ardour's internal architecture, combined with a total redesign of how MIDI channel filtering works. data in a track used to flow from JACK port buffers to diskstream's ringbuffers and was then copied from the ringbuffers into a BufferSet for use during Route::process_output_buffers(). The butler thread would handle the movement of data between the ringbuffers and disk. with this commit, data now flows from JACK port buffers into the BufferSet used for Route processing, and is copied from the BufferSet into the diskstream's ringbuffers (the butler thread continues to handle interactions with disk as usual). this change allowed a dramatic consolidation of code and simplification of most aspects of Track/Route::roll() and Track/Route::no_roll(). in particular, see Route::fill_buffers_with_input() which now concisely describes how we move data from JACK port buffers into the BufferSet for all Route types (including Tracks). this work was initially motivated by changing MIDI channel filtering so that we can process capture and playback independently. there is now a very clean pathway for this - see MidiTrack::roll() (NOTE: This needs implementing in the no-roll case too - a TODO item). the channel selector for MIDI tracks has been moved out of the track header and is now accessible via the context menu. more work is likely here, to make it (more) obvious to the user when filtering is going on.
Diffstat (limited to 'libs/ardour/ardour/midi_buffer.h')
-rw-r--r--libs/ardour/ardour/midi_buffer.h65
1 files changed, 56 insertions, 9 deletions
diff --git a/libs/ardour/ardour/midi_buffer.h b/libs/ardour/ardour/midi_buffer.h
index 183ca7eea9..5ef5e4c845 100644
--- a/libs/ardour/ardour/midi_buffer.h
+++ b/libs/ardour/ardour/midi_buffer.h
@@ -55,38 +55,50 @@ public:
template<typename BufferType, typename EventType>
class iterator_base {
public:
- iterator_base<BufferType, EventType>(BufferType& b, framecnt_t o) : buffer(b), offset(o) {}
+ iterator_base<BufferType, EventType>(BufferType& b, framecnt_t o)
+ : buffer(&b), offset(o) {}
+ iterator_base<BufferType, EventType>(const iterator_base<BufferType,EventType>& o)
+ : buffer (o.buffer), offset(o.offset) {}
+
+ inline iterator_base<BufferType,EventType> operator= (const iterator_base<BufferType,EventType>& o) {
+ if (&o != this) {
+ buffer = o.buffer;
+ offset = o.offset;
+ }
+ return *this;
+ }
+
inline EventType operator*() const {
- uint8_t* ev_start = buffer._data + offset + sizeof(TimeType);
+ uint8_t* ev_start = buffer->_data + offset + sizeof(TimeType);
int event_size = Evoral::midi_event_size(ev_start);
assert(event_size >= 0);
return EventType(EventTypeMap::instance().midi_event_type(*ev_start),
- *((TimeType*)(buffer._data + offset)),
+ *((TimeType*)(buffer->_data + offset)),
event_size, ev_start);
}
inline EventType operator*() {
- uint8_t* ev_start = buffer._data + offset + sizeof(TimeType);
+ uint8_t* ev_start = buffer->_data + offset + sizeof(TimeType);
int event_size = Evoral::midi_event_size(ev_start);
assert(event_size >= 0);
return EventType(EventTypeMap::instance().midi_event_type(*ev_start),
- *((TimeType*)(buffer._data + offset)),
+ *((TimeType*)(buffer->_data + offset)),
event_size, ev_start);
}
inline iterator_base<BufferType, EventType>& operator++() {
- uint8_t* ev_start = buffer._data + offset + sizeof(TimeType);
+ uint8_t* ev_start = buffer->_data + offset + sizeof(TimeType);
int event_size = Evoral::midi_event_size(ev_start);
assert(event_size >= 0);
offset += sizeof(TimeType) + event_size;
return *this;
}
inline bool operator!=(const iterator_base<BufferType, EventType>& other) const {
- return (&buffer != &other.buffer) || (offset != other.offset);
+ return (buffer != other.buffer) || (offset != other.offset);
}
inline bool operator==(const iterator_base<BufferType, EventType>& other) const {
- return (&buffer == &other.buffer) && (offset == other.offset);
+ return (buffer == other.buffer) && (offset == other.offset);
}
- BufferType& buffer;
+ BufferType* buffer;
size_t offset;
};
@@ -99,6 +111,41 @@ public:
const_iterator begin() const { return const_iterator(*this, 0); }
const_iterator end() const { return const_iterator(*this, _size); }
+ iterator erase(const iterator& i) {
+ assert (i.buffer == this);
+ uint8_t* ev_start = _data + i.offset + sizeof (TimeType);
+ int event_size = Evoral::midi_event_size (ev_start);
+
+ if (event_size < 0) {
+ /* unknown size, sysex: return end() */
+ return end();
+ }
+
+ size_t total_data_deleted = sizeof(TimeType) + event_size;
+
+ if (i.offset + total_data_deleted >= _size) {
+ _size = 0;
+ return end();
+ }
+
+ /* we need to avoid the temporary malloc that memmove would do,
+ so copy by hand. remember: this is small amounts of data ...
+ */
+ size_t a, b;
+ for (a = i.offset, b = i.offset + total_data_deleted; b < _size; ++b, ++a) {
+ _data[a] = _data[b];
+ }
+
+ _size -= total_data_deleted;
+
+ /* all subsequent iterators are now invalid, and the one we
+ * return should refer to the event we copied, which was after
+ * the one we just erased.
+ */
+
+ return iterator (*this, i.offset);
+ }
+
uint8_t* data() const { return _data; }
/**