Use Ruby Array Methods in Sonic PI


#1

#29Nov2018

#Using Ruby array methods with SonicPI
# Google ruby array methods
# not every Ruby method is implemented in Sonic PI
# https://ruby-doc.org/core-2.2.0/Array.html

use_synth :piano
rel= 1.5 # note release
nle=[0.125] # note length
nle=nle.ring
amplitude= 1
key= 'C4'
scaletype='major'
cscale=knit(key,16)

with_fx :level, amp: amplitude do
  play_pattern_timed cscale.zip(scale(key,scaletype)+scale(key,scaletype).
                                reverse).flatten,nle,release: nle[0]*rel
end

with_fx :level, amp: amplitude do
  play_pattern_timed cscale.zip(scale(key,scaletype)+scale(key,scaletype).
                                reverse),nle,release: nle[0]*rel
end

#2

I’ve taken the liberty of editing your post and adding ``` before and after the code.
As you had it before, just pasting the code in directly, the single quotes around C4 had been converted to smart quotes.
If you precede and follow your code with three reverse ticks then it posts correctly. It also has the bonus of
added colour to show the syntax.
PS it sounds nice :grinning: