Sonic Pi auto-inserts incoming MIDI events into Time State, enabling sync and get on them
Once a MIDI device is connected and visible in Preferences, Sonic Pi automatically adds incoming MIDI messages to the Time State with OSC-style paths. Code uses standard sync and get calls for MIDI exactly as for any other event. use_real_time disables the default 0.5s scheduling look-ahead for live loops driven by MIDI, removing audible latency. MIDI velocity (0-127) can be normalised to 0-1 amplitude by dividing by 127.0.
Examples
live_loop :midi_piano do use_real_time note, velocity = sync “/midi:nanokey2:0:1/note_on” synth :piano, note: note, amp: velocity / 127.0 end
Assessment
Build a MIDI-driven live_loop that responds to note_on events with velocity-mapped amplitude. Explain why use_real_time is needed.