summaryrefslogtreecommitdiff
path: root/libs/ardour/midi_port.cc
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2006-08-16 20:36:14 +0000
committerDavid Robillard <d@drobilla.net>2006-08-16 20:36:14 +0000
commit7250433f50236a05fc652fa41c23bf53fbf6a0fd (patch)
tree0371dfe1b6ce5a9eb1769d10505a6ca658ca1a7b /libs/ardour/midi_port.cc
parent5952c48a848926edb02b5d630e36cc461c893964 (diff)
Progress on the disk side of things:
- MidiRingBuffer implementation - MidiDiskstream reading from playlists - MidiPlaylist reading from regions - MidiRegions returning random notes for the time being, but the inter-thread stuff works.. Horrible awful mess, not really commit worthy, but I need to move machines. Nothing to see here.. :) git-svn-id: svn://localhost/ardour2/branches/midi@835 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/midi_port.cc')
-rw-r--r--libs/ardour/midi_port.cc40
1 files changed, 26 insertions, 14 deletions
diff --git a/libs/ardour/midi_port.cc b/libs/ardour/midi_port.cc
index 83322dedb6..f4d1912061 100644
--- a/libs/ardour/midi_port.cc
+++ b/libs/ardour/midi_port.cc
@@ -26,7 +26,7 @@ using namespace std;
MidiPort::MidiPort(jack_port_t* p)
: Port(p)
- , _buffer(NULL)
+ , _buffer(4096) // FIXME FIXME FIXME Jack needs to tell us this
, _nframes_this_cycle(0)
{
DataType dt(_type);
@@ -34,22 +34,25 @@ MidiPort::MidiPort(jack_port_t* p)
reset();
- _buffer = new MidiBuffer(4096); // FIXME FIXME FIXME
+
}
MidiPort::~MidiPort()
{
- delete _buffer;
}
void
MidiPort::cycle_start (jack_nframes_t nframes)
{
+ _buffer.clear();
+ assert(_buffer.size() == 0);
+
_nframes_this_cycle = nframes;
if (_flags & JackPortIsOutput) {
- _buffer->set_size(0);
+ _buffer.silence(nframes);
+ assert(_buffer.size() == 0);
return;
}
@@ -60,21 +63,26 @@ MidiPort::cycle_start (jack_nframes_t nframes)
const jack_nframes_t event_count
= jack_midi_port_get_info(jack_buffer, nframes)->event_count;
- assert(event_count < _buffer->capacity());
+ assert(event_count < _buffer.capacity());
+ MidiEvent ev;
+
+ // FIXME: too slow, event struct is copied twice (here and MidiBuffer::push_back)
for (jack_nframes_t i=0; i < event_count; ++i) {
- jack_midi_event_t* const ev = &_buffer->data()[i];
- jack_midi_event_get(ev, jack_buffer, i, nframes);
+ // This will fail to compile if we change MidiEvent to our own class
+ jack_midi_event_get(static_cast<jack_midi_event_t*>(&ev), jack_buffer, i, nframes);
+
+ _buffer.push_back(ev);
// Convert note ons with velocity 0 to proper note offs
// FIXME: Jack MIDI should guarantee this - does it?
//if (ev->buffer[0] == MIDI_CMD_NOTE_ON && ev->buffer[2] == 0)
// ev->buffer[0] = MIDI_CMD_NOTE_OFF;
}
- _buffer->set_size(event_count);
-
- //if (_buffer->size() > 0)
+ assert(_buffer.size() == event_count);
+
+ //if (_buffer.size() > 0)
// cerr << "MIDIPort got " << event_count << " events." << endl;
}
@@ -82,7 +90,7 @@ void
MidiPort::cycle_end()
{
if (_flags & JackPortIsInput) {
- _nframes_this_cycle = 0; // catch any oopses
+ _nframes_this_cycle = 0;
return;
}
@@ -90,13 +98,17 @@ MidiPort::cycle_end()
void* jack_buffer = jack_port_get_buffer(_port, _nframes_this_cycle);
- const jack_nframes_t event_count = _buffer->size();
+ const jack_nframes_t event_count = _buffer.size();
+
+ //if (event_count > 0)
+ // cerr << "MIDIPort writing " << event_count << " events." << endl;
jack_midi_clear_buffer(jack_buffer, _nframes_this_cycle);
for (jack_nframes_t i=0; i < event_count; ++i) {
- const jack_midi_event_t& ev = _buffer->data()[i];
+ const jack_midi_event_t& ev = _buffer[i];
+ assert(ev.time < _nframes_this_cycle);
jack_midi_event_write(jack_buffer, ev.time, ev.buffer, ev.size, _nframes_this_cycle);
}
- _nframes_this_cycle = 0; // catch oopses
+ _nframes_this_cycle = 0;
}