A 4 voices counterpoint

If you have ideas and advices to improve it, thanks! :grinning:

use_bpm 100

cells = [
  [2],
  [1,1],
  [1,0.5,0.5],
  [0.5,0.5,1],
  [0.5,0.5,0.5,0.5],
  [0.75,0.25, 0.75,0.25],
  [0.25,0.25, 0.25,0.25, 0.25,0.25,0.25,0.25],
  [1, 0.25,0.25,0.25,0.25],
  [0.25,0.75, 0.25,0.75],
  [0.5,1,0.5],
  [1.5,0.5],
  [0.5,1.5]
]


live_loop :rythm do
  ##| stop
  with_fx :reverb do
    use_synth :pluck
    n = rand_i(cells.length)
    puts n
    cells[n].length.times do
      play scale(:d4,:major).choose,release: cells[n].tick
      sleep cells[n].look
    end
  end
end

cells2 = [
  [2],
  [1,1],
  [1,0.5,0.5],
  [0.5,0.5,1],
  [0.5,0.5,0.5,0.5],
  [0.75,0.25, 0.75,0.25],
  [0.25,0.25, 0.25,0.25, 0.25,0.25,0.25,0.25],
  [1, 0.25,0.25,0.25,0.25],
  [0.25,0.75, 0.25,0.75],
  [0.5,1,0.5],
  [1.5,0.5],
  [0.5,1.5]
]


live_loop :rythm2, delay: 8 do
  ##| stop
  with_fx :reverb do
    
    use_synth :bass_foundation
    n = rand_i(cells2.length)
    puts n
    cells2[n].length.times do
      play scale(:d4,:major).choose,release: cells2[n].tick, cutof: rrand(40,120), amp: 0.5, pan: rrand(-1.0,1.0)
      sleep cells2[n].look
    end
  end
end

cells3 = [
  [2],
  [1,1],
  [1,0.5,0.5],
  [0.5,0.5,1],
  [0.5,0.5,0.5,0.5],
  [0.75,0.25, 0.75,0.25],
  [0.25,0.25, 0.25,0.25, 0.25,0.25,0.25,0.25],
  [1, 0.25,0.25,0.25,0.25],
  [0.25,0.75, 0.25,0.75],
  [0.5,1,0.5],
  [1.5,0.5],
  [0.5,1.5]
]


live_loop :rythm3, delay: 16  do
  ##| stop
  with_fx :reverb do
    use_synth :bass_foundation
    n = rand_i(cells2.length)
    puts n
    cells3[n].length.times do
      play scale(:d4,:major).choose,release: cells3[n].tick, cutof: rrand(40,120), amp: 0.5, pitch: -12
      sleep cells3[n].look
    end
  end
end

cells4 = [
  [2],
  [1,1],
  [1,0.5,0.5],
  [0.5,0.5,1],
  [0.5,0.5,0.5,0.5],
  [0.75,0.25, 0.75,0.25],
  [0.25,0.25, 0.25,0.25, 0.25,0.25,0.25,0.25],
  [1, 0.25,0.25,0.25,0.25],
  [0.25,0.75, 0.25,0.75],
  [0.5,1,0.5],
  [1.5,0.5],
  [0.5,1.5]
]


live_loop :rythm4, delay: 24  do
  ##| stop
  with_fx :reverb do
    use_synth :piano
    n = rand_i(cells2.length)
    puts n
    cells4[n].length.times do
      play scale(:d4,:major).choose,release: cells3[n].tick, amp: 0.5, pitch: -24, amp: 1
      sleep cells4[n].look
    end
  end
end

2 Likes

I liked this piece. Well done!
I think there are several changes you can make.
First you only look up values from the cells arrays, and they are all identical, so I think you can use one definition for all the four live loops ie just use cells[ ].
Secondly It is more efficient to use one external fx :reverb around all four live loops rather than using one inside each live_loop.
Third I think you misspelt cutof: in a couple of places. It should be cutoff: The former speliing would have no effect and the parameter would be igonored.
Finally I think rythm is spelt rhythm. I haven’t altered these though as the live_loop names can be anything you like (As all four are different).

So my changes would give this:

use_bpm 100

cells = [
  [2],
  [1,1],
  [1,0.5,0.5],
  [0.5,0.5,1],
  [0.5,0.5,0.5,0.5],
  [0.75,0.25, 0.75,0.25],
  [0.25,0.25, 0.25,0.25, 0.25,0.25,0.25,0.25],
  [1, 0.25,0.25,0.25,0.25],
  [0.25,0.75, 0.25,0.75],
  [0.5,1,0.5],
  [1.5,0.5],
  [0.5,1.5]
]

with_fx :reverb do
  live_loop :rythm do
    ##| stop
    use_synth :pluck
    n = rand_i(cells.length)
    puts n
    cells[n].length.times do
      play scale(:d4,:major).choose,release: cells[n].tick
      sleep cells[n].look
    end
  end
  
  
  live_loop :rythm2, delay: 8 do
    ##| stop
    use_synth :bass_foundation
    n = rand_i(cells.length)
    puts n
    cells[n].length.times do
      play scale(:d4,:major).choose,release: cells[n].tick, cutoff: rrand(40,120), amp: 0.5, pan: rrand(-1.0,1.0)
      sleep cells[n].look
    end
  end
  
  
  live_loop :rythm3, delay: 16  do
    ##| stop
    use_synth :bass_foundation
    n = rand_i(cells.length)
    puts n
    cells[n].length.times do
      play scale(:d4,:major).choose,release: cells[n].tick, cutoff: rrand(40,120), amp: 0.5, pitch: -12
      sleep cells[n].look
    end
  end
  
  
  live_loop :rythm4, delay: 24  do
    ##| stop
    use_synth :piano
    n = rand_i(cells.length)
    puts n
    cells[n].length.times do
      play scale(:d4,:major).choose,release: cells[n].tick, amp: 0.5, pitch: -24, amp: 1
      sleep cells[n].look
    end
  end
end #reverb

you could also perhaps try a little more reverb eg
with_fx :reverb, room: 0.6, mix: 0.7 do
for example

1 Like

Hello Robin and thanks for your advices…you are right for the cells, it’s a unique one dispatched in each live_loop…but i was not sure, thinking that i had to place my variable “cells” everywhere…ok for the fx outside for the 4 blocks! :+1:.
And you are also right for the cutoff ! and also for the name “rhythm” (confusion each time with the french term “rythme” :expressionless:
To close the counterpoint, I wanted to code a sort of fading out for the entire patch or for each block individually…How can I do this, with a line f.i: amp: (line 2, 0.1, steps: 6, inclusive: false)? :face_with_raised_eyebrow:
Thanks for your precious help! :grinning:

I prefer to make use of the :level fx. This makes it easy to control the fade out.
I have introduced two variables fadeInitiate and fadeTime to let you specify when the fade starts and how long it takes. I’ve also used the flag :kill to enable you to stop the live_loops runnning once the fade out is complete. (They are still playing silent notes)
I use the rt() function so you can set the times independnet of the bmp used.
The live loops have a line stop if get(:kill) added to each and I’ve commented out the puts n statements.
with_fx :level,amp: 1 do |v|
....
end
is added
The fade is controlled by

at fadeInitiate do #at specified time control fade out via pointer v
      puts "Fadeout started"
      control v,amp: 0,amp_slide: fadeTime
      sleep fadeTime
      puts "Fade complete: stopping live loops"
      set :kill,true #set kill flag which will stop the live loops
    end

The complete program is below

use_bpm 100
set :kill,false #flag used to stop live_loops
fadeInitiate = rt(5) #use rt( ) function to set time independent of bpm
fadeTime = rt(5)
use_debug false #remove printout of synths playing
cells = [
  [2],
  [1,1],
  [1,0.5,0.5],
  [0.5,0.5,1],
  [0.5,0.5,0.5,0.5],
  [0.75,0.25, 0.75,0.25],
  [0.25,0.25, 0.25,0.25, 0.25,0.25,0.25,0.25],
  [1, 0.25,0.25,0.25,0.25],
  [0.25,0.75, 0.25,0.75],
  [0.5,1,0.5],
  [1.5,0.5],
  [0.5,1.5]
]

with_fx :reverb do
  with_fx :level,amp: 1 do|v| #use fx level to control fade out
    at fadeInitiate do #at specified time control fade out via pointer v
      puts "Fadeout started"
      control v,amp: 0,amp_slide: fadeTime
      sleep fadeTime
      puts "Fade complete: stopping live loops"
      set :kill,true #set kill flag which will stop the live loops
    end
    
    live_loop :rythm do
      ##| stop
      use_synth :pluck
      n = rand_i(cells.length)
      #puts n
      cells[n].length.times do
        stop if get(:kill)
        play scale(:d4,:major).choose,release: cells[n].tick
        sleep cells[n].look
      end
    end
    
    
    
    live_loop :rythm2, delay: 8 do
      ##| stop
      use_synth :bass_foundation
      n = rand_i(cells.length)
      #puts n
      cells[n].length.times do
        stop if get(:kill)
        play scale(:d4,:major).choose,release: cells[n].tick, cutoff: rrand(40,120), amp: 0.5, pan: rrand(-1.0,1.0)
        sleep cells[n].look
      end
    end
    
    
    
    live_loop :rythm3, delay: 16  do
      ##| stop
      use_synth :bass_foundation
      n = rand_i(cells.length)
      #puts n
      cells[n].length.times do
        stop if get(:kill)
        play scale(:d4,:major).choose,release: cells[n].tick, cutoff: rrand(40,120), amp: 0.5, pitch: -12
        sleep cells[n].look
      end
    end
    
    
    
    live_loop :rythm4, delay: 24  do
      ##| stop
      use_synth :piano
      n = rand_i(cells.length)
      #puts n
      cells[n].length.times do
        stop if get(:kill)
        play scale(:d4,:major).choose,release: cells[n].tick, amp: 0.5, pitch: -24, amp: 1
        sleep cells[n].look
      end
    end
  end#level
end#reverb
1 Like

Great Robin, Thanks a lot, it will be useful for future projects…i changed the "rt(5) to 30 in the initial bloc and the decrescendo works perfectly. The initial bloc is no so easy to understand but your comments make it clear! so, thanks once again! :grinning: