Skip to content

Instantly share code, notes, and snippets.

@xorik
Last active January 26, 2021 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xorik/57ecac876385ac631baa8af6142f48c2 to your computer and use it in GitHub Desktop.
Save xorik/57ecac876385ac631baa8af6142f48c2 to your computer and use it in GitHub Desktop.
Sonic pi portamento
STOP_NOTE = 60 # stop on pressing the C note, you can use another MIDI or timer event to stop the synth
live_loop :midi_keys do
use_real_time
note, velocity = sync "/midi:*:1/note_*"
if velocity > 0 && note != STOP_NOTE
if (get :current_note) == nil
use_synth :dsaw
x = play note: note, note_slide: 0.3, amp: velocity / 127.0, sustain: 300
set :current_note, x
else
control (get :current_note), note: note
end
end
end
live_loop :stop do
use_real_time
note, velocity = sync "/midi:*:1/note_*"
if note == STOP_NOTE
control (get :current_note), amp: 0, amp_slide: 0.5
sleep 0.5
kill (get :current_note)
set :current_note, nil
end
end
@xorik
Copy link
Author

xorik commented Jan 26, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment