# Exploring the Dune scale YT

1. Today I learned how to add a default parameter value to a define function
2. Today I learned how to create an array of notes and call them using notes[index] starting from 0,1,2, …
3. Today I learned to use “set_volume!” to fade out (type value + run code)
``````# 240825 2242 Exploring the Dune scale YT
# Saved 240825 2242
# https://youtu.be/QOZgCD8gYSM

# Today I learned how to add a default parameter value to a define function
# Today I learned how to create an array of notes and call them using notes[index] starting from 0,1,2, ...
# Today I learned to use "set_volume! 2" to fade out

# The 'Dune' Scale
# notes = [:c, :d, :ds, :g, :a, :as, :cs, :d, :fs, :g] #Version2(best) https://youtu.be/YkQPOtI5kKk?feature=shared&t=484

set_volume! 2

#define :s do |a,b,r|      # Original code

define :s do |a,b, *args|  # with optinal parameter on r for rotate
#                          Both notations now work fx s(3,7) or s(3,7,0)
#                          Mister Bomb - Sonic Pi Tutorial - Adding Default and Optional Parameters to Functions
#                          https://youtu.be/RpiWumugXrY?feature=shared&t=430
r = 0
r = args[0] if args.length == 1 # only looking for 1 value in args[] array

end

###notes = [:c, :d, :ds, :g, :a, :as, :cs, :d, :fs, :g]
notes = [:c2, :d2, :ds2, :g2, :a2, :as2, :cs3, :d3, :fs3, :g3]

with_fx :reverb, room: 0.98 do
live_loop :a1 do
tick

use_synth :sine

/bass notes/
## notes = [:c, :d, :ds, :g, :a, :as, :cs, :d, :fs, :g] #Version2(best) https://youtu.be/YkQPOtI5kKk?feature=shared&t=484
##play :ds2 if s(1,7,0).look
##play notes[2]-24 if s(1,7,0).look

#          2 is the second value in the notes array :ds
play notes[2+knit(0,128-16,-1,16+32).look] if s(1,7,0).look

/middle notes/
use_synth  :square
use_synth_defaults cutoff: 90
#                                             how to play        when to play
play notes.choose+24, amp: 0.3+rdist(0.15) if s(1,14,3).look and (s(0,32+16)+s(16+32,32+16)).look
play notes.choose+24, amp: 0.3+rdist(0.15) if s(1,14,6).look and (s(0,32+16,0)+s(16+32,32+16,0)).look

/high notes/
density [1,1,1,1,2,].look do
density [1,1,2,1,1,].look do
use_synth :pluck
use_synth_defaults  amp: 0.75+rdist(0.15)
#                                                             random rotate value from -3 to 3
play notes.choose+[0,12,24].choose+24, pan: rdist(1) if s(5,7,rrand_i(-3,3)).look
sleep 0.25
end
end
end

/Noise/
with_fx :distortion, mix: 0.8, distort: 0.7 do
with_fx :krush, mix: 0.8 do
#with_fx :ping_pong, mix: 0.8, feedback: 0.2 do  # A bit to much

/ manual oneshot on run /
use_synth :noise
use_synth_defaults cutoff: 50
#play :c2

/ auto noise oneshot + sweep /
live_loop :a2 do
tick

#noise = knit(2,16,1,32).look
noise = knit(0,64,1,64+16,2,16).look

case noise
when 0
sleep 0.125
when 1
/ delayed noise /
use_synth :noise
use_synth_defaults cutoff: [50,60,40].look, amp: 0.5
play  :c2 if s(1,32*2,16).look
sleep 0.125
when 2
/ noise sweep /
use_synth :noise
#use_synth_defaults cutoff: line(50,100,steps: 16).look, release: 0.005125, amp: line(0.1,0.25,steps: 7*3).look
use_synth_defaults cutoff: line(50,70,steps: 16).look, release: [0.05,0.1].choose, amp: line(0.1,1,steps: 7*3).look
play :c2
sleep 0.125
when 3
sleep 0.125
end

#end
end
end
end

end
``````
3 Likes

This is super cool. I dig the sound.
I also learned something – the *args argument! This will be useful for another project I’m working on. Thanks!

2 Likes

Yes, the Ruby operator splat is so cool, especially within Sonic Pi. Effectively, it lets us dynamically create and manipulate arrays of arbitrary length. Great for repetition and variation.

PD-Pi

Nice!
The double splat is great to pass through named args to a method. It will prove very useful for a little method I wrote to transpose samples. It calls the sample command, and it would be nice to pass arbitrary arguments to the sample command without knowing beforehand what they are.