# MIDI Keyboard with Sonic Pi No Audio

**URL:** <https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202>\
**Category:** Support, Help & Resources\
**Created:** [July 14, 2020, 5:18pm UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202 "2020-07-14T17:18:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahuffman24](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@ahuffman24](https://in-thread.sonic-pi.net/u/ahuffman24)\
**Post date:** [July 14, 2020, 5:18pm UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/1 "2020-07-14T17:18:30Z")

</div>

Hi,

I have my midi keyboard (keystation 88) connected to my computer. I would like to use it with Sonic Pi, but I cannot hear anything when I play the keyboard. I have followed the instructions for MIDI In provided by Sam Aaron in the Sonic Pi app, and everything seems to be connected correctly. I’ve provided a screenshot of what I see on my screen.  
Also, I know it is not an issue with my speakers because I can play something simple (such as “play :C4”), and I hear that just fine. If someone could help me figure out what I’m doing wrong, I would greatly appreciate it!

 ![Screenshot (60)](https://europe1.discourse-cdn.com/flex017/uploads/sonic_pi/original/2X/7/7f3377c8a830527ab081a298f4736768050756b4.png)

---

<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:** [July 14, 2020, 5:34pm UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/2 "2020-07-14T17:34:50Z")

</div>

It looks to me from the cues window that all the notes are coming in with velocity 0, so it will play the synth with amp 0 too. Try ignoring the velocity and just setting the amp to 1 in the synth call.

---

<div class="post-metadata">

**Author:** ![ahuffman24](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@ahuffman24](https://in-thread.sonic-pi.net/u/ahuffman24)\
**Post date:** [July 14, 2020, 5:42pm UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/3 "2020-07-14T17:42:00Z")

</div>

Hi Emlyn, thanks for getting back to me. I tried setting the amp to 1 and deleting the velocity part, but I still don’t hear anything. I also am noticing in the cues now that when I press one of the keys down, it registers the note and the correct velocity, but when I release the key, another cue comes up with the correct note but with a velocity of 0. So it looks as though there are two cues per key press, one for when its pressed and one for when its released. I’m not sure if that matters, but I included a picture of the cues as I repeatedly press note 86 for you to see.

 ![Screenshot (61)](https://europe1.discourse-cdn.com/flex017/uploads/sonic_pi/original/2X/6/6618ba7eca0836303ea7a51f83435416c3733d53.png)

---

<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:** [July 14, 2020, 6:07pm UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/4 "2020-07-14T18:07:58Z")

</div>

Ah yes, it’s true that some (most?) keyboards send a note\_on with velocity 0 instead of a note\_off.  
In that case I think that probably the midi message is not triggering the sync command for some reason, so the synth command never gets called.  
What about it you change the sync to: `sync "/midi*note_on"`?

There’s another thread here that looks similar and might give some clues: [Midi in events not triggering](https://in-thread.sonic-pi.net/t/midi-in-events-not-triggering/3492/10)

---

<div class="post-metadata">

**Author:** ![ahuffman24](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@ahuffman24](https://in-thread.sonic-pi.net/u/ahuffman24)\
**Post date:** [July 14, 2020, 6:14pm UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/5 "2020-07-14T18:14:51Z")

</div>

Changing the sync to midi\*note\_on did not work either. Looking at that other thread, it seems that some people were having issues with this in version 3.2 but not 3.1. I will download 3.1 now and see if I can get it to work. Thank you for your help!

---

<div class="post-metadata">

**Author:** ![ahuffman24](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@ahuffman24](https://in-thread.sonic-pi.net/u/ahuffman24)\
**Post date:** [July 14, 2020, 6:34pm UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/6 "2020-07-14T18:34:07Z")

</div>

I was able to get it to work in version 3.1. Must be a bug in version 3.2. Thank you again for your help!

---

<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:** [July 14, 2020, 7:04pm UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/7 "2020-07-14T19:04:59Z")

</div>

good evening @ahuffman24,

Maybe add `use_real_time` at the start of your live\_loop.

```ruby
live_loop :fromMidiDevice do
  
  use_real_time
  n, vel = sync "/midi:apc_key_25_midi_1:4:2/note_on"
  synth :piano, note: n, amp: 1 
  
end

```

my midi keyboard sends `note_off` when a key is released so i can’t test as with your own keyboard.  
Just to warn you that for me the latence is too big to play “live”.

---

<div class="post-metadata">

**Author:** ![ahuffman24](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@ahuffman24](https://in-thread.sonic-pi.net/u/ahuffman24)\
**Post date:** [July 14, 2020, 7:46pm UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/8 "2020-07-14T19:46:07Z")

</div>

I will try this in version 3.2 and see if it works. And I agree, even when using “use\_real\_time” in version 3.1, the latency is too big. Thank you!

---

<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:** [July 14, 2020, 7:57pm UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/9 "2020-07-14T19:57:39Z")

</div>

@ahuffman24: just to clarify, when you refer to 3.2, do you mean 3.2.2? (This is the latest release for Sonic Pi).

---

<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:** [July 14, 2020, 9:18pm UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/10 "2020-07-14T21:18:52Z")

</div>

emlyn you need `"/midi*/note_on"``"/midi*note_on"` will not work

I would use something like this.

```ruby
use_synth :piano
live_loop :midi_piano do
  use_real_time
  n,v = sync "/midi*/note_on"
  play n,amp: v/127.0,sustain: 0.2 if v>0
end

```

This works fine on 3.2.2 on my Pi4

---

<div class="post-metadata">

**Author:** ![ahuffman24](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@ahuffman24](https://in-thread.sonic-pi.net/u/ahuffman24)\
**Post date:** [July 14, 2020, 11:28pm UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/11 "2020-07-14T23:28:09Z")

</div>

Yes, I meant version 3.2.2! My bad!

---

<div class="post-metadata">

**Author:** ![ahuffman24](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@ahuffman24](https://in-thread.sonic-pi.net/u/ahuffman24)\
**Post date:** [July 14, 2020, 11:28pm UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/12 "2020-07-14T23:28:29Z")

</div>

Great! I will give that a try

---

<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:** [July 15, 2020, 9:33am UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/13 "2020-07-15T09:33:06Z")

</div>

Hi @robin.newman

your code works perfectly for me on windows 10 with sonic pi 3.2.2 and the latency is weak so i can really play via the midi keyboard  
Now i wonder why the following code is not working

```ruby
live_loop :fromMidiDevice do
  
  use_real_time
  n, vel = sync "/midi*/note_on"
  synth :dsaw, note: n, amp: 1
  
end

```

Thanks

---

<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:** [July 15, 2020, 10:42am UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/14 "2020-07-15T10:42:52Z")

</div>

Hmm. It works for me on 3.2.2 on a Windows 10 machine. I would suggest however that you add `if vel > 0` at the end of the play line. Otherwise you will get a double note as many keyboards use note\_on with velocity 0 when the key is released. Using the test eliminates the cue when the note is released.

```ruby
live_loop :fromMidiDevice do
  
  use_real_time
  n, vel = sync "/midi*/note_on"
  synth :dsaw, note: n, amp: 1 if vel > 0
  
end

```

---

<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:** [July 15, 2020, 11:01am UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/15 "2020-07-15T11:01:46Z")

</div>

ok my bad. it works. Have tested too fast 🙂. sorry for the inconvenience…

---

<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:** [July 15, 2020, 11:12am UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/16 "2020-07-15T11:12:06Z")

</div>

There is currently a bug in v3.2 when using multiple `:` in a sync path. This has been fixed on the main branch and will be fixed in the upcoming betas and next release. Apologies.

Until then, you can use the `*` fix as detailed above to mask the error 🙂

---

<div class="post-metadata">

**Author:** ![antiphase](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@antiphase](https://in-thread.sonic-pi.net/u/antiphase)\
**Post date:** [September 16, 2020, 3:33am UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/17 "2020-09-16T03:33:27Z")

</div>

Thanks, Robin!  
Works with my [yamaha 88](https://primesound.org/best-digital-piano-with-weighted-keys/#product_1)

---

<div class="post-metadata">

**Author:** ![gedobbles](https://avatars.discourse-cdn.com/v4/letter/g/eb9ed0/32.png) [@gedobbles](https://in-thread.sonic-pi.net/u/gedobbles)\
**Post date:** [September 21, 2020, 6:01pm UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/18 "2020-09-21T18:01:19Z")

</div>

```ruby
use_real_time

in_thread do
  while(1) do
      note, vel = sync "/midi:midi_through_port-0:0:8/note_on"
      play note, amp: vel/127.0
    end
  end

```

works for me on v3.2.2, Linux 5.4.0-47-generic #51~18.04.1-Ubuntu x86\_64 but obviously there are several colons `:` in the sync path. Am I missing something?

---

<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:** [September 21, 2020, 6:54pm UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/19 "2020-09-21T18:54:18Z")

</div>

looking at your code  
`sync "/midi:midi_through_port-0:0:8/note_on"`  
This will sync to a midi cue on port midi\_through\_port-0 which has an id 0 and is on channel 8  
If you don’t care about the port, or the (related) id number or the channel using  
`sync "/midi*/note_on"` to respond to a note\_on command received on ANY connected port on ANY connected channel.  
You could use  
`sync "/midi*:2/midi_on"` to react to a midi\_on command on ANY port but ONLY on channel 2  
or `sync "/midi:usb_oxygen_8_v2:*/note_on"` to react to midi input on ANY channel but only from my oxygen 8 midi keyboard.  
Thus in most simple setups the `sync "/midi*/note_on"` will suffice

---

<div class="post-metadata">

**Author:** ![gedobbles](https://avatars.discourse-cdn.com/v4/letter/g/eb9ed0/32.png) [@gedobbles](https://in-thread.sonic-pi.net/u/gedobbles)\
**Post date:** [September 21, 2020, 6:56pm UTC](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/20 "2020-09-21T18:56:14Z")

</div>

Thats right, I just wondered about the fact that Sam said there was a bug with several colons but it works for me.

[Next page](https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202.md?page=2)
