MidiPort::~MidiPort()
{
if (_shadow_port) {
- _shadow_port->disconnect_all ();
+ AudioEngine::instance()->unregister_port (_shadow_port);
+ _shadow_port.reset ();
}
delete _buffer;
_buffer->clear ();
- if (sends_output ()) {
+ if (sends_output () && _port_handle) {
port_engine.midi_clear (port_engine.get_buffer (_port_handle, nframes));
}
pframes_t timestamp;
size_t size;
- uint8_t* buf;
+ uint8_t const* buf;
port_engine.midi_event_get (timestamp, size, &buf, buffer, i);
if (buf[0] == 0xfe) {
/* throw away active sensing */
continue;
- } else if ((buf[0] & 0xF0) == 0x90 && buf[2] == 0) {
- /* normalize note on with velocity 0 to proper note off */
- buf[0] = 0x80 | (buf[0] & 0x0F); /* note off */
- buf[2] = 0x40; /* default velocity */
}
/* check that the event is in the acceptable time range */
+ if ((timestamp < (_global_port_buffer_offset + _port_buffer_offset)) ||
+ (timestamp >= (_global_port_buffer_offset + _port_buffer_offset + nframes))) {
+ cerr << "Dropping incoming MIDI at time " << timestamp << "; offset="
+ << _global_port_buffer_offset << " limit="
+ << (_global_port_buffer_offset + _port_buffer_offset + nframes) << "\n";
+ continue;
+ }
- if ((timestamp >= (_global_port_buffer_offset + _port_buffer_offset)) &&
- (timestamp < (_global_port_buffer_offset + _port_buffer_offset + nframes))) {
- _buffer->push_back (timestamp, size, buf);
+ if ((buf[0] & 0xF0) == 0x90 && buf[2] == 0) {
+ /* normalize note on with velocity 0 to proper note off */
+ uint8_t ev[3];
+ ev[0] = 0x80 | (buf[0] & 0x0F); /* note off */
+ ev[1] = buf[1];
+ ev[2] = 0x40; /* default velocity */
+ _buffer->push_back (timestamp, size, ev);
} else {
- cerr << "Dropping incoming MIDI at time " << timestamp << "; offset="
- << _global_port_buffer_offset << " limit="
- << (_global_port_buffer_offset + _port_buffer_offset + nframes) << "\n";
+ _buffer->push_back (timestamp, size, buf);
}
}
for (MidiBuffer::iterator i = _buffer->begin(); i != _buffer->end(); ++i) {
- const Evoral::MIDIEvent<MidiBuffer::TimeType> ev (*i, false);
+ const Evoral::Event<MidiBuffer::TimeType> ev (*i, false);
if (sends_output() && _trace_on) {