X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fmidi_port.cc;h=0f91dd3e362d5543e047b88901f00c9ff282767a;hb=204baa31d842d4c2f833d319b6fa55e402a1bfb8;hp=a8bff5bfa704a188d7a33baa67506dd88c81984f;hpb=a473d630eb165272992e90f8d854b1d66ec0be63;p=ardour.git diff --git a/libs/ardour/midi_port.cc b/libs/ardour/midi_port.cc index a8bff5bfa7..0f91dd3e36 100644 --- a/libs/ardour/midi_port.cc +++ b/libs/ardour/midi_port.cc @@ -30,6 +30,7 @@ MidiPort::MidiPort (const std::string& name, Flags flags) : Port (name, DataType::MIDI, flags) , _has_been_mixed_down (false) , _resolve_required (false) + , _input_active (true) { _buffer = new MidiBuffer (AudioEngine::instance()->raw_buffer_size (DataType::MIDI)); } @@ -62,36 +63,42 @@ MidiPort::get_midi_buffer (pframes_t nframes) if (receives_input ()) { - void* jack_buffer = jack_port_get_buffer (_jack_port, nframes); - const pframes_t event_count = jack_midi_get_event_count (jack_buffer); - - assert (event_count < _buffer->capacity()); - - /* suck all relevant MIDI events from the JACK MIDI port buffer - into our MidiBuffer - */ - - for (pframes_t i = 0; i < event_count; ++i) { - - jack_midi_event_t ev; - - jack_midi_event_get (&ev, jack_buffer, i); - - if (ev.buffer[0] == 0xfe) { - /* throw away active sensing */ - continue; - } - - /* check that the event is in the acceptable time range */ + if (_input_active) { + + void* jack_buffer = jack_port_get_buffer (_jack_port, nframes); + const pframes_t event_count = jack_midi_get_event_count (jack_buffer); + + assert (event_count < _buffer->capacity()); + + /* suck all relevant MIDI events from the JACK MIDI port buffer + into our MidiBuffer + */ + + for (pframes_t i = 0; i < event_count; ++i) { + + jack_midi_event_t ev; + + jack_midi_event_get (&ev, jack_buffer, i); + + if (ev.buffer[0] == 0xfe) { + /* throw away active sensing */ + continue; + } + + /* check that the event is in the acceptable time range */ + + if ((ev.time >= (_global_port_buffer_offset + _port_buffer_offset)) && + (ev.time < (_global_port_buffer_offset + _port_buffer_offset + nframes))) { + _buffer->push_back (ev); + } else { + cerr << "Dropping incoming MIDI at time " << ev.time << "; offset=" + << _global_port_buffer_offset << " limit=" + << (_global_port_buffer_offset + _port_buffer_offset + nframes) << "\n"; + } + } - if ((ev.time >= (_global_port_buffer_offset + _port_buffer_offset)) && - (ev.time < (_global_port_buffer_offset + _port_buffer_offset + nframes))) { - _buffer->push_back (ev); - } else { - cerr << "Dropping incoming MIDI at time " << ev.time << "; offset=" - << _global_port_buffer_offset << " limit=" - << (_global_port_buffer_offset + _port_buffer_offset + nframes) << "\n"; - } + } else { + _buffer->silence (nframes); } } else { @@ -121,20 +128,16 @@ MidiPort::cycle_split () void MidiPort::resolve_notes (void* jack_buffer, MidiBuffer::TimeType when) { - uint8_t ev[3]; - - ev[2] = 0; for (uint8_t channel = 0; channel <= 0xF; channel++) { - ev[0] = (MIDI_CMD_CONTROL | channel); + + uint8_t ev[3] = { MIDI_CMD_CONTROL | channel, MIDI_CTL_SUSTAIN, 0 }; /* we need to send all notes off AND turn the * sustain/damper pedal off to handle synths * that prioritize sustain over AllNotesOff */ - ev[1] = MIDI_CTL_SUSTAIN; - if (jack_midi_event_write (jack_buffer, when, ev, 3) != 0) { cerr << "failed to deliver sustain-zero on channel " << channel << " on port " << name() << endl; } @@ -148,7 +151,7 @@ MidiPort::resolve_notes (void* jack_buffer, MidiBuffer::TimeType when) } void -MidiPort::flush_buffers (pframes_t nframes, framepos_t time) +MidiPort::flush_buffers (pframes_t nframes, framepos_t /*time*/) { if (sends_output ()) { @@ -157,7 +160,7 @@ MidiPort::flush_buffers (pframes_t nframes, framepos_t time) if (_resolve_required) { /* resolve all notes at the start of the buffer */ resolve_notes (jack_buffer, 0); - _resolve_required= false; + _resolve_required = false; } for (MidiBuffer::iterator i = _buffer->begin(); i != _buffer->end(); ++i) { @@ -179,8 +182,8 @@ MidiPort::flush_buffers (pframes_t nframes, framepos_t time) << ev.time() << " > " << _global_port_buffer_offset + _port_buffer_offset << endl; } } else { - cerr << "drop flushed event on the floor, time " << ev.time() - << " < " << _global_port_buffer_offset + _port_buffer_offset << endl; + cerr << "drop flushed event on the floor, time " << ev + << " to early for " << _global_port_buffer_offset + _port_buffer_offset << endl; } } } @@ -205,3 +208,9 @@ MidiPort::reset () delete _buffer; _buffer = new MidiBuffer (AudioEngine::instance()->raw_buffer_size (DataType::MIDI)); } + +void +MidiPort::set_input_active (bool yn) +{ + _input_active = yn; +}