Skip to content

Commit

Permalink
MIDI - flush unsent MIDI messages on Run Stop
Browse files Browse the repository at this point in the history
If MIDI messages are sent too quickly then they can get buffered in the sp_midi nif. This will flush these unsent and buffered messages so that they don't keep being sent as the buffer naturally empties.
  • Loading branch information
samaaron committed Jun 11, 2020
1 parent 71b437f commit 236783a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/server/ruby/lib/sonicpi/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,18 @@ def __stop_jobs
# Flush OSC messages on Erlang scheduler
__osc_flush!

# Flush MIDI messages within sp_midi nif
__midi_flush!

# Force a GC collection now everything has stopped
GC.start
GC.compact if RUBY_VERSION >= "2.7.0"
end

def __midi_flush!
@osc_client.send("/midi_flush")
end

def __midi_system_reset(silent=false)
__info "Resetting MIDI subsystems..." unless silent
__schedule_delayed_blocks_and_messages!
Expand Down

0 comments on commit 236783a

Please sign in to comment.