Remove random access interface from MidiBuffer, towards killing fixed/limited event size assumption.
git-svn-id: svn://localhost/ardour2/trunk@2159 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
58d8a71597
commit
823a1d36c1
@ -393,8 +393,8 @@ MidiStreamView::update_rec_regions (boost::shared_ptr<MidiBuffer> data, nframes_
|
||||
|
||||
/* draw events */
|
||||
MidiRegionView* mrv = (MidiRegionView*)iter->second;
|
||||
for (size_t i = 0; i < data->size(); ++i) {
|
||||
const MidiEvent& ev = (*data.get())[i];
|
||||
for (MidiBuffer::iterator i = data->begin(); i != data->end(); ++i) {
|
||||
const MidiEvent& ev = *i;
|
||||
mrv->add_event(ev);
|
||||
mrv->extend_active_notes();
|
||||
}
|
||||
|
@ -43,12 +43,44 @@ public:
|
||||
bool push_back(const jack_midi_event_t& event);
|
||||
Byte* reserve(double time, size_t size);
|
||||
|
||||
bool merge(const MidiBuffer& a, const MidiBuffer& b);
|
||||
|
||||
struct iterator {
|
||||
iterator(MidiBuffer& b, size_t i) : buffer(b), index(i) {}
|
||||
|
||||
inline MidiEvent& operator*() const { return buffer[index]; }
|
||||
inline iterator& operator++() { ++index; return *this; } // prefix
|
||||
inline bool operator!=(const iterator& other) const { return index != other.index; }
|
||||
|
||||
MidiBuffer& buffer;
|
||||
size_t index;
|
||||
};
|
||||
|
||||
struct const_iterator {
|
||||
const_iterator(const MidiBuffer& b, size_t i) : buffer(b), index(i) {}
|
||||
|
||||
inline const 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;
|
||||
};
|
||||
|
||||
iterator begin() { return iterator(*this, 0); }
|
||||
iterator end() { return iterator(*this, _size); }
|
||||
|
||||
const_iterator begin() const { return const_iterator(*this, 0); }
|
||||
const_iterator end() const { return const_iterator(*this, _size); }
|
||||
|
||||
private:
|
||||
|
||||
friend class iterator;
|
||||
friend class const_iterator;
|
||||
|
||||
const MidiEvent& operator[](size_t i) const { assert(i < _size); return _events[i]; }
|
||||
MidiEvent& operator[](size_t i) { assert(i < _size); return _events[i]; }
|
||||
|
||||
bool merge(const MidiBuffer& a, const MidiBuffer& b);
|
||||
|
||||
private:
|
||||
// FIXME: Jack needs to tell us this
|
||||
static const size_t MAX_EVENT_SIZE = 4; // bytes
|
||||
|
||||
|
@ -47,9 +47,8 @@ PeakMeter::run (BufferSet& bufs, nframes_t start_frame, nframes_t end_frame, nfr
|
||||
|
||||
// GUI needs a better MIDI meter, not much information can be
|
||||
// expressed through peaks alone
|
||||
const unsigned n_events = bufs.get_midi(n).size();
|
||||
for (size_t i=0; i < n_events; ++i) {
|
||||
const MidiEvent& ev = bufs.get_midi(n)[i];
|
||||
for (MidiBuffer::iterator i = bufs.get_midi(n).begin(); i != bufs.get_midi(n).end(); ++i) {
|
||||
const MidiEvent& ev = *i;
|
||||
if ((ev.buffer[0] & 0xF0) == MIDI_CMD_NOTE_ON) {
|
||||
const float this_vel = log(ev.buffer[2] / 127.0 * (M_E*M_E-M_E) + M_E) - 1.0;
|
||||
//printf("V %d -> %f\n", (int)((Byte)ev.buffer[2]), this_vel);
|
||||
|
@ -540,9 +540,12 @@ MidiDiskstream::process (nframes_t transport_frame, nframes_t nframes, nframes_t
|
||||
size_t num_events = _source_port->get_midi_buffer().size();
|
||||
size_t to_write = std::min(_capture_buf->write_space(), num_events);
|
||||
|
||||
MidiBuffer::iterator port_iter = _source_port->get_midi_buffer().begin();
|
||||
|
||||
for (size_t i=0; i < to_write; ++i) {
|
||||
MidiEvent& ev = _source_port->get_midi_buffer()[i];
|
||||
const MidiEvent& ev = *port_iter;
|
||||
_capture_buf->write(ev.time + transport_frame, ev.size, ev.buffer);
|
||||
++port_iter;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -83,9 +83,9 @@ MidiModel::end_write(bool delete_stuck)
|
||||
*/
|
||||
void
|
||||
MidiModel::append(const MidiBuffer& buf)
|
||||
{
|
||||
for (size_t i=0; i < buf.size(); ++i) {
|
||||
const MidiEvent& ev = buf[i];
|
||||
{
|
||||
for (MidiBuffer::const_iterator i = buf.begin(); i != buf.end(); ++i) {
|
||||
const MidiEvent& ev = *i;
|
||||
|
||||
assert(_notes.empty() || ev.time >= _notes.back().start);
|
||||
|
||||
|
@ -93,14 +93,14 @@ MidiPort::cycle_end()
|
||||
|
||||
void* jack_buffer = jack_port_get_buffer(_port, _nframes_this_cycle);
|
||||
|
||||
const nframes_t event_count = _buffer.size();
|
||||
|
||||
//const nframes_t event_count = _buffer.size();
|
||||
//if (event_count > 0)
|
||||
// cerr << "MIDIPort writing " << event_count << " events." << endl;
|
||||
|
||||
jack_midi_clear_buffer(jack_buffer);
|
||||
for (nframes_t i=0; i < event_count; ++i) {
|
||||
const MidiEvent& ev = _buffer[i];
|
||||
|
||||
for (MidiBuffer::iterator i = _buffer.begin(); i != _buffer.end(); ++i) {
|
||||
const MidiEvent& ev = *i;
|
||||
// event times should be frames, relative to cycle start
|
||||
assert(ev.time >= 0);
|
||||
assert(ev.time < _nframes_this_cycle);
|
||||
|
@ -380,8 +380,8 @@ SMFSource::write_unlocked (MidiRingBuffer& src, nframes_t cnt)
|
||||
const double frames_per_beat = _session.tempo_map().tempo_at(_timeline_position).frames_per_beat(
|
||||
_session.engine().frame_rate());
|
||||
|
||||
for (size_t i=0; i < buf.size(); ++i) {
|
||||
MidiEvent& ev = buf[i];
|
||||
for (MidiBuffer::iterator i = buf.begin(); i != buf.end(); ++i) {
|
||||
MidiEvent& ev = *i;
|
||||
assert(ev.time >= _timeline_position);
|
||||
ev.time -= _timeline_position;
|
||||
assert(ev.time >= _last_ev_time);
|
||||
|
Loading…
Reference in New Issue
Block a user