SonicPiで曲作り 4

use_bpm 45
use_random_seed 1

index = -1
s_index = 0
b_index = 0

s = [
  0,1,2,3,4,5,6
  ##| 0,1,2,3,4,5,3,4,1,2,5,6
];

c = []

##| sc_name =  :minor_pentatonic
sc_name = :dorian

c[0] = [
  [scale(:Es4 ,sc_name) ,0.125,32],
  [scale(:As4 ,sc_name) ,0.125,32],
  [scale(:Ds4 ,sc_name) ,0.125,32],
  [scale(:Es4 ,sc_name) ,0.125,32],
]
c[1]=[
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:Ds3 ,sc_name) ,0.25,16],
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:As3 ,sc_name) ,0.25,16],
]
c[2]=[
  [scale(:Ds3 ,sc_name) ,0.25,16],
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:As3 ,sc_name) ,0.25,16],
  [scale(:Ds3 ,sc_name) ,0.25,16],
]
c[3]=[
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:Ds4 ,sc_name) ,0.25,16],
  [scale(:Es4 ,sc_name) ,0.25,16],
  [scale(:As3 ,sc_name) ,0.25,16],
]
c[4]=[
  [scale(:Ds3 ,sc_name) ,0.25,16],
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:As3 ,sc_name) ,0.25,16],
  [scale(:Ds4 ,sc_name) ,0.25,16],
]
c[5]=[
  [scale(:Es4 ,sc_name) ,0.25,16],
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:Ds3 ,sc_name) ,0.25,16],
  [scale(:As3 ,sc_name) ,0.25,16],
]
c[6]=[
  [scale(:Es4 ,sc_name) ,0.125,32],
  [scale(:Es3 ,sc_name) ,0.125,32],
  [scale(:Ds3 ,sc_name) ,0.125,32],
  [scale(:As3 ,sc_name) ,0.125,32],
]

a = c[0][0]

with_fx :reverb, room: 0.99, mix: 0.7 do
  live_loop :loop0 do
    use_octave 1
    cue :loop0
    
    index = index+1
    if(index >= c[s[s_index]].length)
      index = 0
      s_index = s_index + 1
      if(s_index >= s.length)
        s_index = 0
      end
    end
    a =  c[s[s_index]][index]
    
    
    a[2].times do
      print "index ",index, "s ", s[s_index],"t ",(s_index*4+index)
      synth :sine ,
        note: a[0].shuffle.take(2),
        attack: 0, release: 0.1, amp: 0.5, pan: rrand(-0.7, 0.7)
      if((s_index*4+index) >=4)
        cue :bd
        b_index = 0
      end
      sleep a[1]
    end
  end
end

with_fx :reverb, room: 0.99, mix: 0.7 do
  live_loop :loop2 do
    sync "/live_loop/loop0"
    use_octave 1
    synth :piano , note: a[0].shuffle.take(2), attack: 0.125, release: 2.15, amp: 0.8
    sleep 1;
  end
end


with_fx :reverb, room: 0.99, mix: 0.7 do
  live_loop :loop5  do
    use_synth :saw;
    play note: a[0].pick(2), attack: 0.5, release: 8, amp: 0.1, vibrato_rate: rand(0.01..2)
    play note: a[0].pick(2)-12, attack: 0.25, release: 8, amp: 0.1, vibrato_rate: rand(0.01..2)
    sleep 2;
  end
end


with_fx :reverb, room: 0.7, mix: 0.7 do
  live_loop :base do
    sync "/live_loop/loop0"
    sync "/cue/bd"
    4.times do
      use_octave 1
      synth :piano ,
        note: a[0].pick(b_index % 4),
        attack: 0.2, release: 0.25, amp: 0.5
      b_index = b_index + 1
      sleep a[1]/2
    end
  end
end


live_loop :bd1 do
  sync "/live_loop/loop0"
  sync "/cue/bd"
  sample :bd_ada, amp: 0.8
  sleep 0.5
  sleep 0.25
  sample :bd_ada, amp: 0.4
  sleep 0.25
  sample :bd_ada, amp: 0.4
  sleep 0.25
  sample :bd_ada, amp: 0.4
  sleep 0.25
end
live_loop :bd2 do
  sync "/live_loop/loop0"
  sync "/cue/bd"
  sleep 2
  sample :bd_ada, amp: 0.6
  sleep 0.5
  sleep 0.25
  sample :bd_ada, amp: 0.2
  sleep 0.25
  sample :bd_ada, amp: 0.2
  sleep 0.25
  sample :bd_ada, amp: 0.2
  sleep 0.25
end