Skip to content

Instantly share code, notes, and snippets.

@alistairstead3408
Last active August 29, 2015 14:10
Show Gist options
  • Save alistairstead3408/00af717cb1c95872655a to your computer and use it in GitHub Desktop.
Save alistairstead3408/00af717cb1c95872655a to your computer and use it in GitHub Desktop.
define :test do
with_bpm 120 do
use_synth :saw
31.times do
use_synth :prophet
play 49, release: 0.6
sleep 0.3
end
12.times do
use_synth :prophet
play 44, release: 0.6
sleep 0.3
end
end
end
with_bpm 120 do
#first bit
play_pattern_timed [77, 77, 77], [0.3, 0.3, 0.3], release: 0.3
play_pattern_timed [75, 75, 75], [0.3, 0.3, 0.3], release: 0.3
play_pattern_timed [72, 72, 72], [0.3, 0.3, 0.3], release: 0.3
play_pattern_timed [70, 70, 70], [0.3, 0.3, 0.3], release: 0.3
play_pattern_timed [68, 68, 68], [0.3, 0.3, 0.3], release: 0.3
play 65, release: 3
in_thread do
test
end
sleep 3
#second bit
play_pattern_timed [77, 77, 77], [0.3, 0.3, 0.3], release: 0.3
play_pattern_timed [75, 75, 75], [0.3, 0.3, 0.3], release: 0.3
play_pattern_timed [72, 72, 72], [0.3, 0.3, 0.3], release: 0.3
play_pattern_timed [70, 70, 70], [0.3, 0.3, 0.3], release: 0.3
play_pattern_timed [68, 68, 68], [0.3, 0.3, 0.3], release: 0.3
play 65, release: 1
sleep 0.9
play 63, release: 1
sleep 0.9
play 68, release: 3
sleep 0.9
end
define :drum_one do
sample :drum_bass_hard
sample :drum_cymbal_pedal
sleep 0.9
sample :drum_cymbal_pedal
sleep 0.9
sample :drum_snare_hard
sample :drum_cymbal_pedal
sleep 0.9
sample :drum_cymbal_pedal
sample :drum_cymbal_open if one_in(6)
sleep 0.9
end
sleep 1.2
use_synth :saw
with_bpm 120 do
in_thread do
8.times do
drum_one
end
end
in_thread do
2.times do
8.times do
play_pattern_timed [49, 53, 56], [0.3, 0.3, 0.3], release: 0.4
end
4.times do
play_pattern_timed [44, 48, 56], [0.3, 0.3, 0.3], release: 0.4
end
4.times do
play_pattern_timed [49, 53, 56], [0.3, 0.3, 0.3], release: 0.4
end
end
end
end
@rbnpi
Copy link

rbnpi commented Dec 2, 2014

Hi Alistair
I liked this. Thought I would produce a more compact version which follows. Does exactly the same, if you change the very last sleep in yours to 3 instead of 0.9. It uses a technique I use a lot which is to put the notes and the durations into separate lists and then use the defined procedure pl to play. The two arrays ar zipped together and then traversed using the construct
notelist.zip(durationlist).each do |n,d|
This feeds corresponding elements in turn to the variables n and d and the are played with the following play command in the loop below. Hope you find it useful. I also removed some extraneous use_synth and with_bpm commands.

========================Program follows===========================

more compact version by Robin Newman

define :test do
use_synth :prophet #just scopes inside the test definition. Remainder uses :beep
32.times do
play 49, release: 0.6
sleep 0.3
end
8.times do
play 44, release: 0.6
sleep 0.3
end
end
n1=[77]_3+[75]_3+[72]_3+[70]_3+[68]_3+[65] #put all notes into a list
d1=[0.3]_15+[3] #put corresponding note durations into a list
n2=n1+[63,68] #repeat for second half: almost the same apart from 2 extra notes
d2=d1[0..-2]+[0.9]*2+[3] #d2 almost same: remove last duration from d1 and add three more
define :pl do |notes,durations| #define a function to play notes given notes and duration lists
notes.zip(durations).each do |n,d| #this line zips the lists together and then traverses correspnding elements in pairs
play n,release: d #play the note and release with the correspnding duration
sleep d #sleep for the given duration
end
end

with_bpm 120 do
#first bit
pl(n1,d1) #play first part
in_thread do #run test in a thread
test
end
sleep 3
pl(n2,d2) #play the second half
end

@alistairstead3408
Copy link
Author

Awesome - thanks for this Robin. It's interesting to see how a seasoned SonicPier does it!

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