Created
July 8, 2017 20:20
-
-
Save xavriley/b5f925daa1195dc6ef686297a3016c3d to your computer and use it in GitHub Desktop.
live_sample definition for Sonic Pi v2.13 and above
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# place in ~/.sonic-pi/init.rb to autoload | |
def live_sample(name=nil, *args) | |
raise ArgumentError, "live_sample needs to have a unique name. For example: live_sample :foo" unless name | |
raise ArgumentError, "live_sample's name needs to be a string or symbol, got: #{name.inspect}. Example usage: live_sample :foo" unless (name.is_a?(Symbol) || name.is_a?(String)) | |
ls_name = "live_sample_#{name}".to_sym | |
args_h = resolve_synth_opts_hash_or_array(args) | |
click = args_h[:click] || 4 | |
dur = args_h[:dur] | |
auto_cue = args_h[:auto_cue] || args_h[:sync] | |
if dur | |
buf = buffer[name, dur] | |
else | |
# don't wipe a named buf by providing a dur arg | |
buf = buffer[name] | |
dur = 8 | |
end | |
defonce ls_name do | |
sync auto_cue if auto_cue | |
click.times do | |
synth :saw, release: 0.1, amp: 1 | |
sleep 1 | |
end | |
with_fx :record, buffer: buf do | |
with_fx :compressor, pre_amp: 4, amp: 2 do | |
live_audio :live_sample | |
end | |
sleep dur | |
end | |
end | |
cue name | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment