Skip to content

Instantly share code, notes, and snippets.

@xavriley
Created March 12, 2015 18:24
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 xavriley/a78ad033c43672ad9932 to your computer and use it in GitHub Desktop.
Save xavriley/a78ad033c43672ad9932 to your computer and use it in GitHub Desktop.
Melody maker in sonic pi
uncomment do
define :pad_times do |target_length, time_values|
if time_values.reduce(:+) < target_length
return time_values << (target_length - time_values.reduce(:+))
else
truncated_times = time_values.take_while.with_index {|x,i|
time_values[0..i].reduce(:+) < target_length
}
return truncated_times << (target_length - truncated_times.reduce(:+))
end
end
use_bpm 120
live_loop(:mel) do
use_random_seed 500
use_synth :pulse
init_time_values = [0.25, 0.5, 1].cycle.take(24)
time_values = pad_times(8, init_time_values)
s = scale(:c2, :minor_pentatonic, :num_octaves => 2).cycle.take(time_values.length).shuffle
play_pattern_timed s, time_values, release: 0.25
end
live_loop :bd do
sync :arp
4.times do
sample :bd_haus
sleep 1
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment