Composition : Multidimendional Repetitions

# Title: Multidimendional Repetitions
# Artist: Mattia Giovanetti
# Date: 26/06/2019
#
# Sonic Pi v3.1

x = 0
y = 0
z = 0
c = 0

define :mg_basso do |i|
  i.times do
    use_synth :sine
    x = x + 1
    play (ring 48,34,65,51,34,57,54)[x], release: 0.25, pan: -0.5, amp: 0.5
    sleep 0.25
    if x > 5 then x = -1 end
  end
end

define :mg_synth do |i|
  i.times do
    use_synth :sine
    y = y + 1
    play (ring 34,35,36,37,37,38,39,30,58,34,64,58)[y], release: 0.25, pan: 0.5, amp: 0.5
    sleep 0.25
    if y > 10 then y = -1 end
  end
end

define :mg_arpeggio do |i|
  with_fx :echo, decay: 4 do
    i.times do
      use_synth :sine
      z = z + 1
      c = c + 1
      play (ring 60,61,43,54,66,38,44)[z], release: 0.25, amp: 0.4, pitch: 12, pan: 0.33
      sleep 0.125
      play (ring 61,43,60,54,38,44)[c], release: 0.25, amp: 0.4, pitch: 12, pan: -0.33
      sleep 0.125
      if z > 5 then z = -1 end
      if c > 4 then c = -1 end
    end
  end
end

define :mg_pad do |i|
  i.times do
    with_fx :flanger, depth: 1, phase: 1 do
      with_fx :tremolo, phase: 0.5, depth: 1 do
        use_synth :tri
        play_chord [60,67], release: 6
        play_chord [60,67], release: 8, pitch: -12
        sleep 8
        play_chord [58,65], release: 6
        play_chord [58,65], release: 8, pitch: -12
        sleep 8
        play_chord [57,64], release: 6
        play_chord [57,64], release: 8, pitch: -12
        sleep 8
        play_chord [58,65], release: 6
        play_chord [58,65], release: 8, pitch: -12
        sleep 8
      end
    end
  end
end


##FORMA
use_bpm 40
with_fx :reverb, damp: 1, room: 0.75, mix: 0.45, amp: 1 do
  print "PRIMA PARTE"
  2.times do
    in_thread do mg_basso 16 end
    in_thread do mg_synth 16 end
    sleep (16*0.25)
    sleep 1
  end
  print "SECONDA PARTE"
  in_thread do mg_basso 32 end
  in_thread do mg_synth 32 end
  in_thread do mg_arpeggio 32 end
  sleep (32*0.25)
  sleep 1
  print "TERZA PARTE"
  in_thread do mg_basso 64*4 end
  in_thread do mg_synth 64*4 end
  in_thread do mg_arpeggio 64*4 end
  in_thread do mg_pad 2 end
  sleep 64
  sleep 1
  print "QUARTA PARTE"
  in_thread do mg_basso 32 end
  in_thread do mg_synth 32 end
  in_thread do mg_arpeggio 32 end
  sleep (32*0.25)
  sleep 1
  print "FINALE"
  in_thread do mg_basso 32 end
  in_thread do mg_synth 32 end
  sleep (32*0.25)
  sleep 1
  in_thread do mg_basso 1 end
  in_thread do mg_synth 1 end
end