Last active
April 26, 2019 14:51
-
-
Save Arkham/3dbb1ec1d260868f21717c60740aad7f to your computer and use it in GitHub Desktop.
Sonic PI experiments
This file contains hidden or 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
# HI! I'm Ju. You can find me online as @arkh4m | |
# Download Sonic PI here: http://sonic-pi.net | |
def p(note, s: 1) | |
play note, release: s, cutoff: rrand(80,110) | |
sleep s | |
end | |
def fra_martino | |
2.times do | |
p :c4 | |
p :d4 | |
p :e4 | |
p :c4 | |
end | |
2.times do | |
p :e4 | |
p :f4 | |
p :g4, s: 2 | |
end | |
2.times do | |
p :g4, s: 0.5 | |
p :a4, s: 0.5 | |
p :g4, s: 0.5 | |
p :f4, s: 0.5 | |
p :e4, s: 1 | |
p :c4, s: 1 | |
end | |
2.times do | |
p :c4 | |
p :g3 | |
p :c4, s: 2 | |
end | |
end | |
use_bpm 100 | |
def modern_fra_martino | |
use_synth :tb303 | |
with_fx :reverb do | |
fra_martino | |
end | |
live_loop :music do | |
use_synth :tb303 | |
with_fx :distortion do | |
with_fx :reverb do | |
play scale(:g3, :major).choose, cutoff: rrand(70, 80), release: 0.25 | |
sleep 0.25 | |
end | |
end | |
end | |
end | |
def live_loops_fun | |
live_loop :music do | |
use_synth :zawa | |
play scale(:e3, :minor_pentatonic).choose, release: 0.5 | |
sleep 0.5 | |
end | |
live_loop :drums do | |
sync :music | |
sample :drum_tom_hi_soft, amp: 0.5 | |
sleep 0.25 | |
sample :drum_tom_hi_hard, amp: 0.5 | |
sleep 0.25 | |
end | |
end |
This file contains hidden or 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
# More ringtones here: http://nokia.nigelcoldwell.co.uk/tunes.html | |
use_bpm 140 | |
song = "4a1 4#a1 8g1 8#a1 8c2 8f1 8a1 4#a1 8g1 8#a1 8d2 4#d2 8d2 | |
8c2 4#a1 8g1 8#a1 8c2 8f1 8a1 4#a1 8g1 8#a1 8d2 4#d2 8d2 8c2 4#a1 8g1 8#a1 8c2 | |
8f1 8a1 4#a1 8g1 8#a1 8d2 4#d2 8d2 8c2 4#a1 8g1 8#a1 8a1 8f1 8f1 2g1" | |
class NokringParser | |
DURATION_REGEX = /(?<duration>1|2|4|8|16|32)?(?<dotted>\.)?/ | |
NOTE_REGEX = /^#{DURATION_REGEX}(?<sharp>\#)?(?<note>[cdefgab])(?<octave>[1234])?$/ | |
PAUSE_REGEX = /^#{DURATION_REGEX}\-$/x | |
attr_reader :default_duration, :default_octave | |
def initialize(default_duration: 4, default_octave: 2) | |
@default_duration = default_duration | |
@default_octave = default_octave | |
end | |
def parse(expr) | |
if match = expr.match(NOTE_REGEX) | |
octave = match[:octave] || default_octave | |
octave = octave.to_i + 2 | |
note = match[:note] | |
note += 's' if match[:sharp] | |
[:note, "#{note}#{octave}".to_sym, parse_duration(match)] | |
elsif match = expr.match(PAUSE_REGEX) | |
[:pause, parse_duration(match)] | |
else | |
[:error, expr] | |
end | |
end | |
private | |
def parse_duration(match) | |
duration = match[:duration] || default_duration | |
duration = 4.0 / duration.to_i | |
duration *= 1.5 if match[:dotted] | |
duration | |
end | |
end | |
def play_tokens(tokens) | |
tokens.each do |result| | |
case result.first | |
when :note | |
_, note, duration = result | |
play note, release: duration * 1.1 | |
sleep duration | |
when :pause | |
_, duration = result | |
sleep duration | |
else | |
_, error = result | |
puts "Error, couldn't parse expression: #{error}" | |
end | |
end | |
end | |
parser = NokringParser.new | |
live_loop :nokia do | |
play_tokens song.split(" ").map{|e| parser.parse(e)} | |
end |
This file contains hidden or 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
use_bpm 100 | |
use_synth :pulse | |
use_synth_defaults release: 0.2, mod_rate: 5, amp: 0.6 | |
define :structure do |i,a,b,c,d| | |
1.times { i.call } | |
loop do | |
2.times { a.call } | |
2.times { b.call } | |
1.times { c.call } | |
2.times { a.call } | |
2.times { d.call } | |
1.times { c.call } | |
1.times { d.call } | |
end | |
end | |
in_thread do | |
intro = -> { play_pattern_timed([:e5,:e5,nil,:e5,nil,:c5,:e5,nil, | |
:g5,nil,nil,nil,nil,nil,nil,nil], [0.25]) } | |
theme_a = -> { | |
play_pattern_timed([:c5,nil,nil,:g4,nil,nil,:e4,nil, | |
nil,:a4,nil,:b4,nil,:Bb4,:a4,nil], [0.25]) | |
play_pattern_timed([:g4,:e5,:g5], [1/3.0]) # minim triplets | |
play_pattern_timed([:a5,nil,:f5,:g5, | |
nil,:e5,nil,:c5, | |
:d5,:b4,nil,nil], [0.25]) } | |
theme_b = -> { | |
play_pattern_timed([nil,nil,:g5,:fs5,:f5,:ds5,nil,:e5, | |
nil,:gs4,:a4,:c5,nil,:a4,:c5,:d5, | |
nil,nil,:g5,:fs5,:f5,:ds5,nil,:e5, | |
nil,:c6,nil,:c6,:c6,nil,nil,nil, | |
nil,nil,:g5,:fs5,:f5,:ds5,nil,:e5, | |
nil,:gs4,:a4,:c5,nil,:a4,:c5,:d5, | |
nil,nil,:ds5,nil,nil,:d5,nil,nil, | |
:c5,nil,nil,nil,nil,nil,nil,nil], [0.25]) } | |
theme_c = -> { | |
play_pattern_timed([:c5,:c5,nil,:c5,nil,:c5,:d5,nil, | |
:e5,:c5,nil,:a4,:g4,nil,nil,nil, | |
:c5,:c5,nil,:c5,nil,:c5,:d5,:e5, | |
nil,nil,nil,nil,nil,nil,nil,nil, | |
:c5,:c5,nil,:c5,nil,:c5,:d5,nil, | |
:e5,:c5,nil,:a4,:g4,nil,nil,nil, | |
:e5,:e5,nil,:e5,nil,:c5,:e5,nil, | |
:g5,nil,nil,nil,nil,nil,nil,nil], [0.25]) } | |
theme_d = -> { | |
play_pattern_timed([:e5,:c5,nil,:g4,nil,nil,:gs4,nil, | |
:a4,:f5,nil,:f5,:a4,nil,nil,nil], [0.25]) | |
play_pattern_timed([:b4,:a5,:a5, | |
:a5,:g5,:f5], [1/3.0]) | |
play_pattern_timed([:e5,:c5,nil,:a4,:g4,nil,nil,nil], [0.25]) | |
play_pattern_timed([:e5,:c5,nil,:g4,nil,nil,:gs4,nil, | |
:a4,:f5,nil,:f5,:a4,nil,nil,nil, | |
:b4,:f5,nil,:f5], [0.25]) | |
play_pattern_timed([:f5,:e5,:d5], [1/3.0]) | |
play_pattern_timed([:g5,:e5,nil,:e5,:c5,nil,nil,nil], [0.25]) } | |
structure(intro, theme_a, theme_b, theme_c, theme_d) | |
end | |
in_thread do | |
intro = -> { play_pattern_timed([:fs4,:fs4,nil,:fs4,nil,:fs4,:fs4,nil, | |
:b4,nil,nil,nil,:g4,nil,nil,nil], [0.25]) } | |
theme_a = -> { | |
play_pattern_timed([:e4,nil,nil,:c4,nil,nil,:g3,nil, | |
nil,:c4,nil,:d4,nil,:Db4,:c4,nil], [0.25]) | |
play_pattern_timed([:c4,:g4,:b4], [1/3.0]) | |
play_pattern_timed([:c5,nil,:a4,:b4, | |
nil,:a4,nil,:e4, | |
:f4,:d4,nil,nil], [0.25]) } | |
theme_b = -> { | |
play_pattern_timed([nil,nil,:e5,:ds5,:d5,:b4,nil,:c5, | |
nil,:e4,:f4,:g4,nil,:c4,:e4,:f4, | |
nil,nil,:e5,:ds5,:d5,:b4,nil,:c5, | |
nil,:f5,nil,:f5,:f5,nil,nil,nil, | |
nil,nil,:e5,:ds5,:d5,:b4,nil,:c5, | |
nil,:e4,:f4,:g4,nil,:c4,:e4,:f4, | |
nil,nil,:gs4,nil,nil,:f4,nil,nil, | |
:e4,nil,nil,nil,nil,nil,nil,nil], [0.25]) } | |
theme_c = -> { | |
play_pattern_timed([:gs4,:gs4,nil,:gs4,nil,:gs4,:as4,nil, | |
:g4,:e4,nil,:e4,:c4,nil,nil,nil, | |
:gs4,:gs4,nil,:gs4,nil,:gs4,:as4,:g4, | |
nil,nil,nil,nil,nil,nil,nil,nil, | |
:gs4,:gs4,nil,:gs4,nil,:gs4,:as4,nil, | |
:g4,:e4,nil,:e4,:c4,nil,nil,nil, | |
:fs4,:fs4,nil,:fs4,nil,:fs4,:fs4,nil, | |
:b4,nil,nil,nil,:g4,nil,nil,nil], [0.25]) } | |
theme_d = -> { | |
play_pattern_timed([:c5,:a4,nil,:e4,nil,nil,:e4,nil, | |
:f4,:c5,nil,:c5,:f4,nil,nil,nil], [0.25]) | |
play_pattern_timed([:g4,:f5,:f5, | |
:f5,:e5,:d5], [1/3.0]) | |
play_pattern_timed([:c5,:a4,nil,:f4,:e4,nil,nil,nil], [0.25]) | |
play_pattern_timed([:c5,:a4,nil,:e4,nil,nil,:e4,nil, | |
:f4,:c5,nil,:c5,:f4,nil,nil,nil, | |
:g4,:d5,nil,:d5], [0.25]) | |
play_pattern_timed([:d5,:c5,:b4], [1/3.0]) | |
play_pattern_timed([:c5,nil,nil,nil,nil,nil,nil,nil], [0.25]) } | |
structure(intro, theme_a, theme_b, theme_c, theme_d) | |
end | |
in_thread do | |
use_synth :tri | |
use_synth_defaults attack: 0, sustain: 0.1, decay: 0.1, release: 0.1, amp: 0.4 | |
intro = -> { play_pattern_timed([:D4,:D4,nil,:D4,nil,:D4,:D4,nil, | |
:G3,nil,nil,nil,:G4,nil,nil,nil], [0.25]) } | |
theme_a = -> { | |
play_pattern_timed([:G4,nil,nil,:E4,nil,nil,:C4,nil, | |
nil,:F4,nil,:G4,nil,:Gb4,:F4,nil], [0.25]) | |
play_pattern_timed([:E4,:C4,:E4], [1/3.0]) | |
play_pattern_timed([:F4,nil,:D4,:E4, | |
nil,:C4,nil,:A3, | |
:B3,:G3,nil,nil], [0.25]) } | |
theme_b = -> { | |
play_pattern_timed([:C3,nil,nil,:G3,nil,nil,:C3,nil, | |
:F3,nil,nil,:C3,:C3,nil,:F3,nil, | |
:C3,nil,nil,:E3,nil,nil,:G3,:C3, | |
nil,:G2,nil,:G2,:G2,nil,:G4,nil, | |
:C3,nil,nil,:G3,nil,nil,:C3,nil, | |
:F3,nil,nil,:C3,:C3,nil,:F3,nil, | |
:C3,nil,:Ab3,nil,nil,:Bb3,nil,nil, | |
:C3,nil,nil,:G2,:G2,nil,:C3,nil], [0.25]) } | |
theme_c = -> { | |
3.times { | |
play_pattern_timed([:gs4,nil,nil,:ds4,nil,nil,:gs4,nil, | |
:g4,nil,nil,:c4,nil,nil,:g4,nil], [0.25]) | |
} | |
play_pattern_timed([:D4,:D4,nil,:D4,nil,:D4,:D4,nil, | |
:G3,nil,nil,nil,:G4,nil,nil,nil], [0.25]) } | |
theme_d = -> { | |
play_pattern_timed([:C3,nil,nil,:fs3,:g3,nil,:C3,nil, | |
:F3,nil,:F3,nil,:C3,:C3,:F3,nil, | |
:D3,nil,nil,:F3,:G3,nil,:B3,nil, | |
:G3,nil,:G3,nil,:C3,:C3,:G3,nil, | |
:C3,nil,nil,:fs3,:g3,nil,:C3,nil, | |
:F3,nil,:F3,nil,:C3,:C3,:F3,nil, | |
:G3,nil,nil,:G3], [0.25]) | |
play_pattern_timed([:G3,:A3,:B3], [1/3.0]) | |
play_pattern_timed([:C4,nil,:G3,nil,:C4,nil,nil,nil], [0.25]) } | |
structure(intro, theme_a, theme_b, theme_c, theme_d) | |
end | |
in_thread do | |
use_synth :fm | |
use_synth_defaults divisor: 1.6666, attack: 0.0, depth: 1500, sustain: 0.05, release: 0.0 | |
ll = -> { play :a, sustain: 0.1; sleep 0.75 } | |
l = -> { play :a, sustain: 0.1; sleep 0.5 } | |
s = -> { play :a; sleep 0.25 } | |
define :drum_pattern_a do | |
[l,s,l,s,l,ll,l,s,s,s].map(&:call) | |
end | |
define :drum_pattern_b do | |
play :b | |
sleep 0.5 | |
play :a6 | |
sleep 0.3 | |
play :a7 | |
sleep 0.2 | |
play :a, sustain: 0.1 | |
sleep 0.5 | |
play :a6 | |
sleep 0.3 | |
play :a7 | |
sleep 0.2 | |
end | |
define :drum_pattern_c do | |
[ll,s,l,l].map(&:call) | |
end | |
with_fx :level, amp: 0.5 do | |
1.times { drum_pattern_a } | |
loop do | |
24.times { drum_pattern_b } | |
4.times { drum_pattern_a } | |
8.times { drum_pattern_b } | |
16.times { drum_pattern_c } | |
4.times { drum_pattern_a } | |
8.times { drum_pattern_b } | |
end | |
end | |
end |
This file contains hidden or 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
# From https://aimxhaisse.com/aerodynamic-en.html | |
use_bpm 123 | |
maquillage = "~/code/sonic-pi/daft-punk/il-macquillage-lady.wav" # https://aimxhaisse.com/public/misc/il-macquillage-lady.wav | |
aerodynamic = "~/code/sonic-pi/daft-punk/funk.wav" # https://aimxhaisse.com/public/misc/funk.wav | |
load_sample maquillage | |
load_sample aerodynamic | |
define :sample_chunk do |what, beat, dur, delay| | |
beat = beat / 16.0 | |
dur = dur / 16.0 | |
sample what, beat_stretch: 16, start: beat, finish: beat + dur | |
sleep delay | |
end | |
define :funk do | |
# sample_chunk(aerodynamic, 0.0, 4.0, 4.0) | |
sample_chunk(maquillage, 0.0, 0.5, 0.5) | |
sample_chunk(maquillage, 2.5, 1.0, 0.25) | |
sample_chunk(maquillage, 3.5, 0.5, 0.75) | |
sample_chunk(maquillage, 0.0, 0.5, 0.5) | |
sample_chunk(maquillage, 8.5, 0.5, 0.5) | |
sample_chunk(maquillage, 2.5, 1.0, 1.0) | |
sample_chunk(maquillage, 7.5, 0.5, 0.5) | |
# sample_chunk(aerodynamic, 4.0, 4.0, 4.0) | |
sample_chunk(maquillage, 3.5, 0.5, 0.5) | |
sample_chunk(maquillage, 2.5, 1.0, 1.0) | |
sample_chunk(maquillage, 7.5, 0.5, 0.5) | |
sample_chunk(maquillage, 8.5, 0.5, 0.5) | |
sample_chunk(maquillage, 2.5, 1.0, 1.0) | |
sample_chunk(maquillage, 7.5, 0.5, 0.5) | |
# sample_chunk(aerodynamic, 8.0, 4.0, 4.0) | |
sample_chunk(maquillage, 0.0, 0.5, 0.5) | |
sample_chunk(maquillage, 2.5, 1.0, 0.25) | |
sample_chunk(maquillage, 3.5, 0.5, 0.75) | |
sample_chunk(maquillage, 0.0, 0.5, 0.5) | |
sample_chunk(maquillage, 8.5, 0.5, 0.5) | |
sample_chunk(maquillage, 2.5, 1.0, 1.0) | |
sample_chunk(maquillage, 7.5, 0.5, 0.5) | |
# sample_chunk(aerodynamic, 12.0, 4.0, 4.0) | |
sample_chunk(maquillage, 3.5, 0.5, 0.5) | |
sample_chunk(maquillage, 8.5, 0.25, 0.0) | |
sample_chunk(maquillage, 2.5, 1.0, 0.25) | |
sample_chunk(maquillage, 3.5, 0.5, 0.5) | |
sample_chunk(maquillage, 8.5, 0.25, 0.25) | |
sample_chunk(maquillage, 3.5, 0.5, 0.5) | |
sample_chunk(maquillage, 8.5, 0.5, 0.5) | |
sample_chunk(maquillage, 2.5, 1.0, 1.0) | |
sample_chunk(maquillage, 7.5, 0.5, 0.5) | |
end | |
# Live loops | |
live_loop :main do | |
sleep 4 | |
end | |
live_loop :funk do | |
sync :main | |
with_fx :ixi_techno, mix: 0.1, phase: 8, cutoff_min: 90, cutoff_max: 120, res: 0.9, amp: 1 do | |
with_fx :bpf, mix: 0, res: 0.00001, centre: :B8, amp: 2 do | |
funk | |
end | |
end | |
end | |
live_loop :solo do | |
sync :main | |
use_synth :zawa | |
use_synth_defaults attack: 0.05, sustain: 0.15, release: 0.125 | |
phases = [ | |
[:D4, :Fs3, :B3, :Fs3], | |
[:D4, :Gs3, :B3, :Gs3], | |
[:G4, :B3, :E4, :B3], | |
[:E4, :A3, :Cs4, :A3], | |
[:D4, :Fs4, :B3, :Fs4], | |
[:D4, :Gs4, :B3, :Gs4], | |
[:G4, :B3, :E4, :B3], | |
[:E4, :A3, :Cs4, :A3], | |
] | |
phases.each do |notes| | |
4.times do | |
notes.each do |n| | |
play n | |
sleep 0.25 | |
end | |
end | |
end | |
end | |
live_loop :extra_beat do | |
sync :main | |
32.times do | |
tick | |
sample :bd_fat, amp: 2 if spread(1, 16).look | |
sample :bd_fat, amp: 1.5 if spread(1, 32).rotate(4).look | |
synth :cnoise, release: 0.6, cutoff: 130, env_curve: 7, amp: 1 if spread(1, 16).rotate(8).look | |
synth :cnoise, release: 0.1, cutoff: 130, env_curve: 7, amp: 0.25 if spread(1, 2).look | |
sleep 0.125 | |
end | |
end | |
live_loop :intro do | |
stop # remove me if you want bells | |
sync :main | |
use_synth :pretty_bell | |
use_synth_defaults release: 9 | |
with_fx :level, amp: 0.5 do | |
4.times do | |
with_fx :gverb, room: 20 do | |
play :A1, amp: 0.25 | |
play :A2, amp: 0.5 | |
play :A3, amp: 1.5 | |
play :A4, amp: 0.75 | |
play :A5, amp: 0.5 | |
sleep 8 | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment