summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libs/ardour/ardour/midi_buffer.h37
-rw-r--r--libs/ardour/midi_buffer.cc49
-rw-r--r--libs/midi++2/midi++/event.h1
3 files changed, 39 insertions, 48 deletions
diff --git a/libs/ardour/ardour/midi_buffer.h b/libs/ardour/ardour/midi_buffer.h
index 812f697aa3..2a368673a9 100644
--- a/libs/ardour/ardour/midi_buffer.h
+++ b/libs/ardour/ardour/midi_buffer.h
@@ -46,29 +46,24 @@ public:
void resize(size_t);
bool merge(const MidiBuffer& a, const MidiBuffer& b);
- bool merge_in_place( const MidiBuffer &other );
+ bool merge_in_place(const MidiBuffer &other);
- struct iterator {
- iterator(MidiBuffer& b, size_t i) : buffer(b), index(i) {}
-
- inline Evoral::MIDIEvent& operator*() const { return buffer[index]; }
- inline iterator& operator++() { ++index; return *this; } // prefix
- inline bool operator!=(const iterator& other) const { return index != other.index; }
+ template<typename B, typename E>
+ struct iterator_base {
+ iterator_base<B,E>(B& b, size_t i) : buffer(b), index(i) {}
+
+ inline E& operator*() const { return buffer[index]; }
+ inline iterator_base<B,E>& operator++() { ++index; return *this; } // prefix
+ inline bool operator!=(const iterator_base<B,E>& other) const {
+ return index != other.index;
+ }
- MidiBuffer& buffer;
- size_t index;
+ B& buffer;
+ size_t index;
};
- struct const_iterator {
- const_iterator(const MidiBuffer& b, size_t i) : buffer(b), index(i) {}
-
- inline const Evoral::MIDIEvent& operator*() const { return buffer[index]; }
- inline const_iterator& operator++() { ++index; return *this; } // prefix
- inline bool operator!=(const const_iterator& other) const { return index != other.index; }
-
- const MidiBuffer& buffer;
- size_t index;
- };
+ typedef iterator_base<MidiBuffer, Evoral::MIDIEvent> iterator;
+ typedef iterator_base<const MidiBuffer, const Evoral::MIDIEvent> const_iterator;
iterator begin() { return iterator(*this, 0); }
iterator end() { return iterator(*this, _size); }
@@ -78,8 +73,8 @@ public:
private:
- friend class iterator;
- friend class const_iterator;
+ friend class iterator_base<MidiBuffer, Evoral::MIDIEvent>;
+ friend class iterator_base<const MidiBuffer, const Evoral::MIDIEvent>;
const Evoral::MIDIEvent& operator[](size_t i) const { assert(i < _size); return _events[i]; }
Evoral::MIDIEvent& operator[](size_t i) { assert(i < _size); return _events[i]; }
diff --git a/libs/ardour/midi_buffer.cc b/libs/ardour/midi_buffer.cc
index 1f5b0c5fa9..51f7dd43e6 100644
--- a/libs/ardour/midi_buffer.cc
+++ b/libs/ardour/midi_buffer.cc
@@ -35,10 +35,9 @@ MidiBuffer::MidiBuffer(size_t capacity)
: Buffer(DataType::MIDI, capacity)
, _events(0)
, _data(0)
-// , _owns_data(false)
{
if (capacity) {
- resize (_capacity);
+ resize(_capacity);
silence(_capacity);
}
}
@@ -54,7 +53,7 @@ MidiBuffer::~MidiBuffer()
}
void
-MidiBuffer::resize (size_t size)
+MidiBuffer::resize(size_t size)
{
assert(size > 0);
@@ -62,13 +61,8 @@ MidiBuffer::resize (size_t size)
return;
}
- if (_data) {
- free (_data);
- }
-
- if (_events) {
- free (_events);
- }
+ free(_data);
+ free(_events);
_size = 0;
_capacity = size;
@@ -116,7 +110,7 @@ MidiBuffer::read_from(const Buffer& src, nframes_t nframes, nframes_t offset)
}
// FIXME: slow
- for (size_t i=0; i < msrc.size(); ++i) {
+ for (size_t i = 0; i < msrc.size(); ++i) {
const Evoral::MIDIEvent& ev = msrc[i];
//cout << "MidiBuffer::read_from event type: " << int(ev.type())
// << " time: " << ev.time() << " buffer size: " << _size << endl;
@@ -220,8 +214,9 @@ MidiBuffer::reserve(double time, size_t size)
return 0;
}
- if (_size == _capacity)
+ if (_size == _capacity) {
return 0;
+ }
uint8_t* const write_loc = _data + (_size * MAX_EVENT_SIZE);
@@ -251,27 +246,28 @@ MidiBuffer::silence(nframes_t dur, nframes_t offset)
}
bool
-MidiBuffer::merge_in_place( const MidiBuffer &other )
+MidiBuffer::merge_in_place(const MidiBuffer &other)
{
- if( other.size() == 0 )
+ if (other.size() == 0) {
return true;
+ }
- if( this->size() == 0 ) {
- copy( other );
+ if (this->size() == 0) {
+ copy(other);
return true;
}
{
- MidiBuffer merge_buffer( 0 );
+ MidiBuffer merge_buffer(0);
Evoral::MIDIEvent onstack_events[_capacity];
- uint8_t onstack_data[_capacity * MAX_EVENT_SIZE];
+ uint8_t onstack_data[_capacity * MAX_EVENT_SIZE];
merge_buffer._events = onstack_events;
merge_buffer._data = onstack_data;
merge_buffer._size = 0;
- bool retval = merge_buffer.merge( *this, other );
+ bool retval = merge_buffer.merge(*this, other);
- copy( merge_buffer );
+ copy(merge_buffer);
// set pointers to zero again, so destructor
// does not end in calling free() for memory
@@ -293,13 +289,14 @@ bool
MidiBuffer::merge(const MidiBuffer& a, const MidiBuffer& b)
{
_size = 0;
+
+ if (this == &a) {
+ merge_in_place(b);
+ }
- // This is mostly the case :(
- if( this == &a )
- merge_in_place( b );
-
- if( this == &b )
- merge_in_place( a );
+ if (this == &b) {
+ merge_in_place(a);
+ }
size_t a_index = 0;
size_t b_index = 0;
diff --git a/libs/midi++2/midi++/event.h b/libs/midi++2/midi++/event.h
index 24a8db37ee..d9b5333904 100644
--- a/libs/midi++2/midi++/event.h
+++ b/libs/midi++2/midi++/event.h
@@ -1,6 +1,5 @@
/*
Copyright (C) 2007 Paul Davis
- Author: Dave Robillard
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by