# MIDI on RPi- notes but no sound

**URL:** <https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415>\
**Category:** Support, Help & Resources\
**Created:** [April 13, 2021, 4:21am UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415 "2021-04-13T04:21:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ergomatic](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@ergomatic](https://in-thread.sonic-pi.net/u/ergomatic)\
**Post date:** [April 13, 2021, 4:21am UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/1 "2021-04-13T04:21:49Z")

</div>

Hi all, I’m trying to use my Arturia USB MIDI controller to play samples in SPi. Audio seems to be working- I can run examples in another buffer and hear the result. My device seems to be detected properly- I can see the messages in the cue log when I press keys. BUT when I load the piano example into a buffer, I get no sound when I play keys. How can I troubleshoot this? I’m using a Raspberry Pi 400 with the latest Raspbian, and Sonic Pi 3.3.1

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [April 13, 2021, 4:25am UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/2 "2021-04-13T04:25:05Z")

</div>

Hi @ergomatic,  
It would be very helpful to see the actual code you are trying to run, if you can paste it here. (Remember, you can give it nice code highlighting by placing three backticks ``` on a line before and after the code 🙂)

---

<div class="post-metadata">

**Author:** ![ergomatic](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@ergomatic](https://in-thread.sonic-pi.net/u/ergomatic)\
**Post date:** [April 13, 2021, 4:30am UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/3 "2021-04-13T04:30:55Z")

</div>

Thanks Ethan! Here’s a screenshot:

 ![2021-04-12-212418_3840x2160_scrot](https://europe1.discourse-cdn.com/flex017/uploads/sonic_pi/original/2X/b/bc5fa35329ca9931229359b3225ad8fd4364f2d8.jpeg)

---

<div class="post-metadata">

**Author:** ![ergomatic](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@ergomatic](https://in-thread.sonic-pi.net/u/ergomatic)\
**Post date:** [April 13, 2021, 4:33am UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/4 "2021-04-13T04:33:48Z")

</div>

…and here’s the code:

```ruby
# Welcome to Sonic Pi

live_loop :midi_piano do
  note, velocity = sync "/midi:arturia_minilab_mkii_arturia_minilab_mkii_midi_1_20_0:1/note_on"
  synth :piano, note: note
end

```

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [April 13, 2021, 4:33am UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/5 "2021-04-13T04:33:49Z")

</div>

Ta. I’m not immediately sure what might be going on here, but perhaps someone else might have an idea. @robin.newman perhaps?

(Also, fyi, the reason we usually prefer code examples to be pasted as text is so that we have the opportunity to easily copy and paste your code into our own Sonic Pi apps for quick testing purposes 🙂)

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [April 13, 2021, 4:34am UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/6 "2021-04-13T04:34:16Z")

</div>

> [@ergomatic](#):
>
> …and here’s the code:

Ahaha. Guess you were on the ball 😃

---

<div class="post-metadata">

**Author:** ![ergomatic](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@ergomatic](https://in-thread.sonic-pi.net/u/ergomatic)\
**Post date:** [April 13, 2021, 4:37am UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/7 "2021-04-13T04:37:24Z")

</div>

Is it because of the weird name of my controller? I notice it seems to be long and repetitive…but that’s what appears in the cue log.

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [April 13, 2021, 4:40am UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/8 "2021-04-13T04:40:19Z")

</div>

IIRC, that is a quirk of the way that one of the software components we use to handle midi names devices/ports, so that is not necessarily an issue.

---

<div class="post-metadata">

**Author:** ![ergomatic](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@ergomatic](https://in-thread.sonic-pi.net/u/ergomatic)\
**Post date:** [April 13, 2021, 4:46am UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/9 "2021-04-13T04:46:38Z")

</div>

Is there a way to see if the incoming MIDI messages are being parsed properly?

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [April 13, 2021, 4:57am UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/10 "2021-04-13T04:57:21Z")

</div>

Not directly with Sonic Pi, but there might be packages for linux/RPi to inspect midi messages. I’m not too sure myself, as I haven’t used midi very often.

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [April 13, 2021, 4:59am UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/11 "2021-04-13T04:59:22Z")

</div>

I don’t know how useful it might be, but if you don’t necessarily care about which port or channel the messages will be arriving at, you can use a wildcard in the midi address:

```ruby
note, velocity = sync "/midi*/note_on"

```

---

<div class="post-metadata">

**Author:** ![ergomatic](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@ergomatic](https://in-thread.sonic-pi.net/u/ergomatic)\
**Post date:** [April 13, 2021, 5:02am UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/12 "2021-04-13T05:02:06Z")

</div>

hmmm…used a wildcard but still no audio. That tells me that midi messages are received but the sample is not being played

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [April 13, 2021, 5:16am UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/13 "2021-04-13T05:16:50Z")

</div>

Either Robin or @samaaron will most likely have a better idea about what might be going on 🙂

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [April 13, 2021, 6:03am UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/14 "2021-04-13T06:03:45Z")

</div>

Hi

`play 60` gives you sound ?

Have you try to add `use_real_time` as a first line ?

> [@Midi sync vs. control](https://in-thread.sonic-pi.net/t/midi-sync-vs-control/4366):
>
> This is probably an easy beginner error. This code works fine: note = 0 use\_synth :dsaw live\_loop :midi\_piano do use\_real\_time note, velocity = sync "/midi:mio:0:1/note\_on" end live\_loop :midi\_cc do use\_real\_time controller, value = sync "/midi:mio:0:1/control\_change" play note, amp: value / 127.0 if controller == 2 end But, this code doesn’t and I don’t understand why. The only difference is that it creates the play on the synth at the top as s, then uses control s to change the…

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [April 13, 2021, 7:09pm UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/15 "2021-04-13T19:09:34Z")

</div>

Your code example doesn’t work because Ruby does not seem to like the use of “controller” as a variable name. Not sure why, but it may be because controller is used in Ruby and rails. If you use a different name eg “c” things begin to happen…but The code seems a bit peculiar anyway, and it will only play a note as the controller value (for 2) is being changed. If you’re trying to set up a volume control I find that this works.

```ruby
set :value,0
use_synth :dsaw
live_loop :midi_piano do
  use_real_time
  note, velocity = sync "/midi*/note_on"
  play note,amp: get(:value)/127.0 #if velocity>0. #uncomment if note_on with velocity 0 is used for note_off
end
live_loop :midi_cc do
  use_real_time
  c, value = sync "/midi*/control_change"
  set :value,value if (c==32) #I used controller value 32 when testing
end

```

Basically the send live loop sets the value of :value whenever the controller is altered. This is then retrieved in the first loop and used to act like a volume control.  
The other potential change depends on how your midi keyboard works. If it uses separate note\_on and note\_off events it will work fine. If it uses only note\_on but sets the velocity value to 0 for when you want a note\_off event then uncomment the line indicated.

@ergomatic as far as your code is concerned, it is fine and should work. You seem to be getting the events arriving in the cue\_log.  
I assume you have tested that you do can hear audio with a loop like this

```ruby
live_loop :test_note do
   use_real_time
   note = rrand_i(50,80)
   synth :piano, note: note
   sleep 0.5
end

```

If not you have audio output problems to solve with your pi setup. Are you using the HDMI output on your Pi400, or do you have a separate usbaudio device plugged i, and selected as your audio output device by right clicking the speaker icon on the menu bar.

One simplification you could make is to use a wild card with the sync midi line using  
`note, velocity sync "/midi*/note_on"`  
That will respond to ANY midi input device connected to your Pi400

---

<div class="post-metadata">

**Author:** ![mrkarlsson](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@mrkarlsson](https://in-thread.sonic-pi.net/u/mrkarlsson)\
**Post date:** [April 23, 2022, 4:15pm UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/16 "2022-04-23T16:15:20Z")

</div>

Hi @robin.newman  
Late reply, but… your code works fine on my Arturia minilab, I just had to change the controller value to 74 to use nob no. 2. Also added velocity to the amp parameter so that volume changes when keys are pressed fast or slow.

One question is it possible to trigger a release on the synth when the key is released (note\_off event) ?

```ruby
set :value,0
use_synth :dsaw
live_loop :midi_piano do
  use_real_time
  note, velocity = sync "/midi*/note_on"
  play note, amp: velocity/127.0 * get(:value)/127.0 # if velocity>0 #uncomment if note_on with velocity 0 is used for note_off
end
live_loop :midi_cc do
  use_real_time
  c, value = sync "/midi*/control_change"
  set :value,value if (c==74) #I used controller value 74 when testing
end

```

---

<div class="post-metadata">

**Author:** ![ergomatic](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@ergomatic](https://in-thread.sonic-pi.net/u/ergomatic)\
**Post date:** [April 23, 2022, 4:37pm UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/17 "2022-04-23T16:37:18Z")

</div>

Thank you, this is awesome! Yes it’s been quite a while but I’ll pick it back up. I appreciate all these answers, very illuminating!

---

<div class="post-metadata">

**Author:** ![mrkarlsson](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@mrkarlsson](https://in-thread.sonic-pi.net/u/mrkarlsson)\
**Post date:** [April 23, 2022, 9:50pm UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/18 "2022-04-23T21:50:04Z")

</div>

Hi again,  
found another topic by @robin.newman for [note\_off](https://in-thread.sonic-pi.net/t/code-for-artiphone-instrument1/2922/3) .  
Since I get real note\_off events from the Arturia keyboard (and not only note\_on with velocity 0) I could simplify the event loops somewhat:

```ruby
set :value, 0
use_synth :dsaw
ns = []

live_loop :midi_piano do
  use_real_time
  note, velocity = sync "/midi*/note_on"
  x = play note, amp: velocity/127.0 * get(:value)/127.0, sustain: 5 # if velocity>0 #uncomment if note_on with velocity 0 is used for note_off
  ns[note] = x
end

live_loop :midi_off do
  use_real_time
  note, velocity = sync "/midi*/note_off"
  x = ns[note]
  control x, amp: 0, amp_slide: 0.25
end

live_loop :midi_cc do
  use_real_time
  c, value = sync "/midi*/control_change"
  set :value, value if (c==74) #I used controller value 74 when testing
end

```

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [April 24, 2022, 2:13pm UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/19 "2022-04-24T14:13:20Z")

</div>

Glad you found this second article. Yes that is the solution. Sorry not to have responded earlier, but my Wife passed away just over a week ago, so I’m not doing much with Sonic Pi just at present.

---

<div class="post-metadata">

**Author:** ![mrkarlsson](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@mrkarlsson](https://in-thread.sonic-pi.net/u/mrkarlsson)\
**Post date:** [April 24, 2022, 2:45pm UTC](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415/20 "2022-04-24T14:45:42Z")

</div>

Very sorry to hear about your loss Robin.  
Given that I haven’t been active here for a year I think your response is very fast.

[Next page](https://in-thread.sonic-pi.net/t/midi-on-rpi-notes-but-no-sound/5415.md?page=2)
