I have a midi keyboard - on entering a key it outputs a midi message containing [note, velocity]. On release it sends [note,0]. I found this out by using a node red midi-in to debug. (this is on my pi c.local (a v3))… sending this to sonic on g.local (a pi v4) allows me to play the keyboard into sonic-pi (via midi via osc) . Then I added some buttons to the node red dashboard for a few notes demo.
live_loop :listen do
use_real_time
a,b = sync "/osc*/play_note"
if b
if b > 0
synth :prophet, note: a, velocity: b
#synth :hoover, note: a, velocity: b
#synth :blade, note: a, velocity: b
end
end
else
puts " b is null"
end
I can now hit one of the buttons on the node-red dashboard (needs formatting to look like a keyboard) or play on the real keyboard. Here is the node-red code :-
[
{"id":"19a0a22b.040276","type":"tab","label":"Flow 2","disabled":false,"info":""},
{"id":"f7ae16f8.ccb0c8","type":"midi in","z":"19a0a22b.040276","name":"","midiport":"1","x":90,"y":200,"wires":[["3404345a.3a5434","7046104.ba7f9f","88000eb7.32c38"]]},
{"id":"7046104.ba7f9f","type":"ui_text","z":"19a0a22b.040276","group":"226ff5c9.c476ba","order":6,"width":0,"height":0,"name":"","label":"keyboard","format":"{{msg.payload}}","layout":"row-spread","x":430,"y":200,"wires":[]},
{"id":"3404345a.3a5434","type":"debug","z":"19a0a22b.040276","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":460,"y":280,"wires":[]},
{"id":"88000eb7.32c38","type":"osc","z":"19a0a22b.040276","name":"OSC /play_note","path":"/play_note","metadata":false,"x":430,"y":340,"wires":[["86ea6742.25437"]]},
{"id":"86ea6742.25437","type":"udp out","z":"19a0a22b.040276","name":"","addr":"g.local","iface":"","port":"4560","ipv":"udp4","outport":"4561","base64":false,"multicast":"false","x":690,"y":340,"wires":[]},{"id":"5ba6d45a.9c161c","type":"ui_button","z":"19a0a22b.040276","name":"button : 60","group":"226ff5c9.c476ba","order":0,"width":0,"height":0,"passthru":false,"label":"60","tooltip":"","color":"","bgcolor":"","icon":"","payload":"[60, 50]","payloadType":"json","topic":"","x":130,"y":320,"wires":[["88000eb7.32c38"]]},
{"id":"b7c80f78.4ee298","type":"ui_button","z":"19a0a22b.040276","name":"button : 70","group":"226ff5c9.c476ba","order":0,"width":0,"height":0,"passthru":false,"label":"70","tooltip":"","color":"","bgcolor":"","icon":"","payload":"[70, 50]","payloadType":"json","topic":"","x":130,"y":360,"wires":[["88000eb7.32c38"]]},
{"id":"8e46ef41.e71588","type":"ui_button","z":"19a0a22b.040276","name":"button : 80","group":"226ff5c9.c476ba","order":0,"width":0,"height":0,"passthru":false,"label":"80","tooltip":"","color":"","bgcolor":"","icon":"","payload":"[80,50]","payloadType":"json","topic":"","x":130,"y":400,"wires":[["88000eb7.32c38"]]},
{"id":"1a86de94.2c7619","type":"ui_button","z":"19a0a22b.040276","name":"button : 90","group":"226ff5c9.c476ba","order":0,"width":0,"height":0,"passthru":false,"label":"90","tooltip":"","color":"","bgcolor":"","icon":"","payload":"[ 90,50 ]","payloadType":"json","topic":"","x":130,"y":440,"wires":[["88000eb7.32c38"]]},
{"id":"226ff5c9.c476ba","type":"ui_group","z":"","name":"Default","tab":"7ab897c5.a3168","order":1,"disp":true,"width":"6","collapse":false},
{"id":"7ab897c5.a3168","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}
]
Interesting thing is that the dashboard could be anywhere that supports a browser( mobile, tablet…)