# How to stop midi instrument when STOP doesn't work

**URL:** <https://in-thread.sonic-pi.net/t/how-to-stop-midi-instrument-when-stop-doesnt-work/9656>\
**Category:** Support, Help & Resources\
**Created:** [April 25, 2025, 9:21pm UTC](https://in-thread.sonic-pi.net/t/how-to-stop-midi-instrument-when-stop-doesnt-work/9656 "2025-04-25T21:21:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rebelcello](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/rebelcello/32/2602_2.png) [@rebelcello](https://in-thread.sonic-pi.net/u/rebelcello)\
**Post date:** [April 25, 2025, 9:21pm UTC](https://in-thread.sonic-pi.net/t/how-to-stop-midi-instrument-when-stop-doesnt-work/9656/1 "2025-04-25T21:21:02Z")

</div>

Hello, I’m trying the Berlin Free Orchestra midi instruments linked here (thank you - they’re amazing!)

> [@Free resource Berlin Free Orchestra by Orchestral Instruments](https://in-thread.sonic-pi.net/t/free-resource-berlin-free-orchestra-by-orchestral-instruments/9597):
>
> If you like using/hearing the instruments used in a Symphony Orchestra you might like to take a look at this new FREE resource recently released by Orchestral Instruments called the Berlin Free Orchestra. It uses the free SINE player and can be driven by a midi source such as Sonic Pi. You can play the output direct, or feed it back into sonic pi as an audio feed. Articulations for the instruments are included and by selected using keyswitches or midi\_cc or can be linked dynamically to velocity…

When I play the code below, sustained notes ring on indefinitely (Sonic Pi STOP button doesn’t stop them). I can only stop sound by switching off the config on/off settings in the SINE player.

Think I need some kind of panic/stop in Sonic Pi? But can’t work out how to do this. Forgive what may be an obvious Q, am MIDI beginner, have added info below for other newbs.

```ruby
notes = [:c4, :e4, :g4, :b4]

# strings (channel 1)
live_loop :strings do
  notes.each do |n|
    midi_note_on n, port: "iac_driver_bus_1", channel: 1
    sleep 0.4
    midi_note_off n, port: "iac_driver_bus_1", channel: 1
  end
  sleep 1
end

# trumpets (channel 2)
live_loop :trumpets do
  notes.reverse.each do |n|
    midi_note_on n, port: "iac_driver_bus_1", channel: 2
    sleep 0.25
    midi_note_off n, port: "iac_driver_bus_1", channel: 2
  end
  sleep 1
end

```

To get the SINE player to work on Mac:

- switch on IAC driver on the mac (in MIDI Audio Devices)
- open SINE player, switch on IAC Driver Bus under Options/Midi devices, switch on config/output channels
- Then open Sonic Pi I/O and check MIDI IN-OUT is switched on. SP needs to be opened after SINE.
- PS the horn section is a free library of big band sounds, Rotary

---

<div class="post-metadata">

**Author:** ![emlyn](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/emlyn/32/1460_2.png) [@emlyn](https://in-thread.sonic-pi.net/u/emlyn)\
**Post date:** [April 25, 2025, 11:04pm UTC](https://in-thread.sonic-pi.net/t/how-to-stop-midi-instrument-when-stop-doesnt-work/9656/2 "2025-04-25T23:04:39Z")

</div>

I think it’s because you’re sending the midi note on and note off as separate commands. If you use the `midi` command with a `sustain` parameter for the note length, then I think Sonic Pi should send the note off when you press the stop button.  
You can also use `use_midi_defaults` to set the default port so that you don’t have to specify it each time.

```ruby
notes = [:c4, :e4, :g4, :b4]
use_midi_defaults port: "iac_driver_bus_1"

# strings (channel 1)
live_loop :strings do
  notes.each do |n|
    midi n, channel: 1, sustain: 0.4
  end
  sleep 1
end

# trumpets (channel 2)
live_loop :trumpets do
  notes.reverse.each do |n|
    midi n, channel: 2, sustain: 0.25
  end
  sleep 1
end

```

---

<div class="post-metadata">

**Author:** ![rebelcello](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/rebelcello/32/2602_2.png) [@rebelcello](https://in-thread.sonic-pi.net/u/rebelcello)\
**Post date:** [April 26, 2025, 9:37am UTC](https://in-thread.sonic-pi.net/t/how-to-stop-midi-instrument-when-stop-doesnt-work/9656/3 "2025-04-26T09:37:41Z")

</div>

Thanks @emlyn - this worked and is far tidier. This gives me a way to make horn stabs with Sonic Pi - woohooo! I’m not a keyboard player and also daw-avoidant, so this is v cool

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [May 6, 2025, 5:48pm UTC](https://in-thread.sonic-pi.net/t/how-to-stop-midi-instrument-when-stop-doesnt-work/9656/4 "2025-05-06T17:48:56Z")

</div>

Hi there,

many MIDI synths respond to the CC message 123 which is “all sounds off”. Sonic Pi has the function `midi_all_notes_off` which will send this message to all connected MIDI devices on all channels which can be a useful way of requesting total silence on all devices (which honour this cc message). You can also scope to a specific MIDI device and channel if desired.

---

<div class="post-metadata">

**Author:** ![rebelcello](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/rebelcello/32/2602_2.png) [@rebelcello](https://in-thread.sonic-pi.net/u/rebelcello)\
**Post date:** [May 6, 2025, 7:23pm UTC](https://in-thread.sonic-pi.net/t/how-to-stop-midi-instrument-when-stop-doesnt-work/9656/5 "2025-05-06T19:23:57Z")

</div>

Thank you, Sam - much appreciated. The horn stabs worked!
