Replace a bunch of potential crashes with graceful handling of the situation.
[ardour.git] / libs / ardour / midi_port.cc
index 6d09ddb52c142ff8fdd515246150ff546b30bc49..cc72eabba49ed67f6e9d03ef198882da8dd0ef4a 100644 (file)
@@ -47,8 +47,6 @@ MidiPort::cycle_start (pframes_t nframes)
 
        _buffer->clear ();
 
-       assert (_buffer->size () == 0);
-
        if (sends_output ()) {
                jack_midi_clear_buffer (jack_port_get_buffer (_jack_port, nframes));
        }
@@ -68,8 +66,6 @@ MidiPort::get_midi_buffer (pframes_t nframes)
                        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
                        */
@@ -128,10 +124,9 @@ MidiPort::cycle_split ()
 void
 MidiPort::resolve_notes (void* jack_buffer, MidiBuffer::TimeType when)
 {
-
        for (uint8_t channel = 0; channel <= 0xF; channel++) {
 
-               uint8_t ev[3] = { MIDI_CMD_CONTROL | channel, MIDI_CTL_SUSTAIN, 0 };
+               uint8_t ev[3] = { ((uint8_t) (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
@@ -171,11 +166,6 @@ MidiPort::flush_buffers (pframes_t nframes)
 
                        assert (ev.time() < (nframes + _global_port_buffer_offset + _port_buffer_offset));
 
-                       if (ev.event_type() == LoopEventType) {
-                               resolve_notes (jack_buffer, ev.time());
-                               continue;
-                       }
-
                        if (ev.time() >= _global_port_buffer_offset + _port_buffer_offset) {
                                if (jack_midi_event_write (jack_buffer, (jack_nframes_t) ev.time(), ev.buffer(), ev.size()) != 0) {
                                        cerr << "write failed, drop flushed note off on the floor, time "
@@ -189,6 +179,12 @@ MidiPort::flush_buffers (pframes_t nframes)
        }
 }
 
+void
+MidiPort::require_resolve ()
+{
+       _resolve_required = true;
+}
+
 void
 MidiPort::transport_stopped ()
 {