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 )
…and here’s the code:
# 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
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 )
Ahaha. Guess you were on the ball
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.
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.
Is there a way to see if the incoming MIDI messages are being parsed properly?
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.
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:
note, velocity = sync "/midi*/note_on"
hmmm…used a wildcard but still no audio. That tells me that midi messages are received but the sample is not being played
Either Robin or @samaaron will most likely have a better idea about what might be going on
play 60 gives you sound ?
Have you try to add
use_real_time as a first line ?
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.
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
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
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) ?
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
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!
found another topic by @robin.newman for note_off .
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:
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
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.
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.
No words. People care, and you are not alone.
Just… HUG… Okay?.