Set/get trouble? (solved)

Hi all
It’s my firsttime using set/get for mixing a song.
I’m having trouble with set/get not taking effect after playthrough of knit() in line 35
What am I missing?
Kind regards
Relaxnow

Manual changing works, but it’s hard to time switching between sections, so I wanna do it auto with knit() below

/ songform change here 0-3  /
  songform = 1

Trouble spot “line 35” (set/get not working properly after knit() sequence?)

# Set/get not working properly after knit() sequence?
  puts songform = knit(3,32, 2,16).look

Whole code

# 221117 1543 Unholy (Sonic Pi cover) draft 1
# 221117 1543 saved

# Hydra:
# Visual 1 "UNHOLY | SAM SMITH | CASSIE BARTHO CHOREOGRAPHY" https://youtu.be/QjV-tNRZfeQ

# Inspiration: UNHOLY | SAM SMITH | CASSIE BARTHO CHOREOGRAPHY
# https://youtu.be/QjV-tNRZfeQ



use_bpm 131
set :metronom, 0

live_loop :time, delay: 0.01 do
  sleep 1
end

live_loop :metronom1, sync: :time do
  stop if get[:metronom]<1
  
  sample :elec_tick, amp: [1,0,0,0].tick
  sleep 1
end


live_loop :songform, sync: :time do
  tick
  / songform change here 0-3  /
  songform = 1                                  # manual changing here works but it's hard to times switching between sections
  
  
  / set get not working properly after knit() sequence ?? /
  puts songform = knit(3,32, 2,16).look
  
  
  
  case songform
  
  when 0                  # 0 stop
    set :metronom, 0
    set :choir, 0
    set :kick, 0
    set :bassshort, 0
  when 1                  # 1 choir intro
    set :choir, 1
    set :kick, 0
    set :bassshort, 0
  when 2                  # 2 drum + short bass intro
    set :choir, 0
    set :kick, 1
    set :bassshort, 1
  when 3
    set :choir, 1
    set :kick, 1
    set :bassshort, 1     # should be a longer bass with slide
  end
  
  sleep 1
end

with_fx :level, amp: 4 do
  
  
  
  
  
  #intro short bass
  q= 0.5
  mel      = [:f4,:fs4,:gs4,:gs4,  :fs4,:gs4,:a4,:gs4,:fs4,     :f4,:fs4,:gs4,:fs4,:f4,     :cs4,:d4,:fs4,:f4,:cs4,:d4,:cs4]
  melsl    = [q  ,q   ,q+q ,q+q ,  q   ,q   ,q  ,q   ,q+q+q+q ,  q , q  , q  , q  ,q+q+q+q, q   ,q  ,q   ,q  ,q+q   ,q+q  , q+q]
  #           1   2    3 4  5 6    7    8    9  10   11 12 13 14 15 16   17   18 19 20 21 22 23  24  25  26  27 28  29 30  31 32
  
  
  lowbass  = bools(1,0,0,1, 0,0,0,0,  0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0)
  highbass = bools(0,0,0,0, 0,0,0,0,  0,0,0,0, 1,0,0,1,  0,0,0,0, 0,0,0,0,  1,0,0,1, 0,0,0,0)
  
  #kick     = bools(1,0,0,0, 0,0,0,0,  0,0,0,0, 1,0,0,1,  0,0,0,0, 0,0,0,0,  1,0,0,1, 0,0,0,0)
  kick     = bools(1,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  1,0,0,1, 0,0,0,0)
  snare    = bools(0,0,0,0, 0,0,0,0,  1,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  1,0,0,0, 0,0,0,0)
  cowbell  = bools(0,0,0,0, 1,0,0,0,  0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0)
  
  
  
  / choir /
  with_fx :level, amp: 0.5 do
    with_fx :reverb, room: 0.65 do
      with_fx :krush, mix: 0.5 do
        
        live_loop :choir1, sync: :time do
          stop if get[:choir]<1
          
          tick
          use_synth :saw
          c = line(90,115,step: 0.001).mirror.tick(:c1)
          use_synth_defaults release: 0.45, cutoff: 100 #c #100
          play mel.look
          play mel.look-12, pan: 0.5
          play mel.look+12, pan: -0.5
          
          use_synth :blade
          #play mel.look, amp: 2
          sleep melsl.look
        end
      end
    end
  end
  
  
  / kick /
  live_loop :kick1, sync: :time do
    stop if get[:kick]<1
    
    tick
    sample :bd_haus, cutoff: [70,90,50].tick(:k1), amp: 4 if kick.look
    with_fx :reverb, mix: 0.25 do
      sample :sn_dolf, finish: 0.15, rate: 2, pan: 0.5 if snare.look and one_in(2)
      sample :sn_dolf, finish: 0.125, rate: 1, pan: -0.5 if snare.look
    end
    sample :drum_cowbell, amp: rrand(0.25,0.4)+0.125, pan: rrand(-0.5,0.5) if cowbell.look
    sleep 0.25
  end
  
  
  / bass short sustain /
  with_fx :ixi_techno, phase: 32 do |ixi_techno|
    
    live_loop :bass1, sync: :time do
      stop if get[:bassshort]<1
      
      tick
      use_synth_defaults sustain: 0.5, release: 0.12, cutoff: line(60,120, step: 0.1).reflect.look
      
      
      use_synth :saw
      play :cs2, pan: 0.5      if lowbass.look
      use_synth :fm
      play :cs2+0.05, pan: -0.5 if lowbass.look
      
      use_synth :saw
      play :d2, pan: 0.5      if highbass.look
      use_synth :fm
      play :d2+0.05, pan: -0.5  if highbass.look
      
      control ixi_techno, mix: 0  # original
      #   control ixi_techno, mix: 1  # more spice
      sleep 0.25
    end
  end
  
  
end

knit produces a ring so you cant use it directly with .look
Instead add .to_a to convert it to a list, then it works
puts songform = knit(3,32, 2,16).to_a.look

EDIT

This is a gotcha which applies to several other constructs and has caught meout before.

1 Like

Hi @robin.newman
I just tried it with puts songform = knit(1,16, 2,16, 3,32).to_a.look
but it’s still not working.
It’s plays part 1, but silence at part 2 and 3


Part 2 should look like this

I think that is because your are stopping live loops as in
stop if get[:bassshort]<1
once the loop is stopped it will not start again until you rerun the program.
I think you want a conditional here which switches the loop (contents) on and off whilst leaving it running eg something like

live_loop :kick1, sync: :time do
    if get[:kick]>0
      
      tick
      sample :bd_haus, cutoff: [70,90,50].tick(:k1), amp: 4 if kick.look
      with_fx :reverb, mix: 0.25 do
        sample :sn_dolf, finish: 0.15, rate: 2, pan: 0.5 if snare.look and one_in(2)
        sample :sn_dolf, finish: 0.125, rate: 1, pan: -0.5 if snare.look
      end
      sample :drum_cowbell, amp: rrand(0.25,0.4)+0.125, pan: rrand(-0.5,0.5) if cowbell.look
    end
    sleep 0.25
    
  end

and similar for the other loops you are currently stopping. The set get logic works ok and produces correct flags to control the loops.
I inserted a line puts "gets",get(:metronom),get(:choir),get(:kick),get(:bassshort),look
at the end of the :songform live loop to check.

1 Like

Thank you so much @robin.newman. This works :smiley:

(Melody/bass seems a bit out of sync but that’s another thing. I’m looking into that.)

# 221117 2247 Unholy (Sonic Pi cover) draft 1
# 221117 2247 saved

# Hydra:
# Visual 1 "UNHOLY | SAM SMITH | CASSIE BARTHO CHOREOGRAPHY" https://youtu.be/QjV-tNRZfeQ

# Inspiration: UNHOLY | SAM SMITH | CASSIE BARTHO CHOREOGRAPHY
# https://youtu.be/QjV-tNRZfeQ


use_bpm 131
set :metronom, 1  # 0 off 1 on


live_loop :time, delay: 0.01 do
  sleep 1
end

live_loop :metronom1, sync: :time do
  if get[:metronom]>0
    tick
    #sample :elec_tick, amp: [4,0,0,0].look
    sample :elec_blip, amp: [4,0,0,0 ,0,0,0,0 ,0,0,0,0, 0,0,0,0].look
    sample :elec_tick, amp: [0,0,0,0 ,4,0,0,0 ,4,0,0,0, 4,0,0,0].look
  end
  sleep 1
end


live_loop :songform, sync: :time do
  tick
  
  / songform change here 0-3  /
  # manual changing here works but it's hard to times switching between sections
  songform = 3
  
  
  / set&get works (but something off sync with the bass&melody) /
  #puts songform = knit(1,16, 2,16, 3,32).look
  #  songform = knit(1,16, 2,16, 3,32).to_a.look  # works
  songform = knit(1,16, 2,16, 3,32).look          # works
  
  
  case songform
  
  when 0                  # 0 stop
    
    puts set :metronom, 0
    puts set :choir, 0
    puts set :kick, 0
    puts set :bassshort, 0
  when 1                  # 1 choir intro
    puts "---------------------------------"
    puts set :choir, 1
    puts set :kick, 0
    puts set :bassshort, 0
  when 2                  # 2 drum + short bass intro
    puts "///////////////"
    puts "///////////////"
    puts set :choir, 0
    puts set :kick, 1
    puts set :bassshort, 1
  when 3
    puts "#################################"
    puts "#################################"
    puts "#################################"
    puts set :choir, 1
    puts set :kick, 1
    puts set :bassshort, 1     # should be a longer bass with slide
  end
  
  sleep 1
  
end



with_fx :level, amp: 4 do
  
  #intro short bass
  q= 0.5
  mel      = [:f4,:fs4,:gs4,:gs4,  :fs4,:gs4,:a4,:gs4,:fs4,     :f4,:fs4,:gs4,:fs4,:f4,     :cs4,:d4,:fs4,:f4,:cs4,:d4,:cs4]
  melsl    = [q  ,q   ,q+q ,q+q ,  q   ,q   ,q  ,q   ,q+q+q+q ,  q , q  , q  , q  ,q+q+q+q, q   ,q  ,q   ,q  ,q+q   ,q+q  , q+q]
  #           1   2    3 4  5 6    7    8    9  10   11 12 13 14 15 16   17   18 19 20 21 22 23  24  25  26  27 28  29 30  31 32
  
  
  lowbass  = bools(1,0,0,1, 0,0,0,0,  0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0)
  highbass = bools(0,0,0,0, 0,0,0,0,  0,0,0,0, 1,0,0,1,  0,0,0,0, 0,0,0,0,  1,0,0,1, 0,0,0,0)
  
  #kick     = bools(1,0,0,0, 0,0,0,0,  0,0,0,0, 1,0,0,1,  0,0,0,0, 0,0,0,0,  1,0,0,1, 0,0,0,0)
  kick     = bools(1,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  1,0,0,1, 0,0,0,0)
  snare    = bools(0,0,0,0, 0,0,0,0,  1,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  1,0,0,0, 0,0,0,0)
  cowbell  = bools(0,0,0,0, 1,0,0,0,  0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0)
  
  
  
  / choir /
  with_fx :level, amp: 0.5 do
    with_fx :reverb, room: 0.65 do
      with_fx :krush, mix: 0.5 do
        
        live_loop :choir1, sync: :time do
          tick
          if get[:choir]>0
            use_synth :saw
            c = line(90,115,step: 0.001).mirror.tick(:c1)
            use_synth_defaults release: 0.45, cutoff: 100 #c #100
            play mel.look
            play mel.look-12, pan: 0.5
            play mel.look+12, pan: -0.5
            use_synth :blade
            #play mel.look, amp: 2
          end
          sleep melsl.look
        end
        
      end
    end
  end
  
  
  / kick /
  live_loop :kick1, sync: :time do
    #stop if get[:kick]<1
    tick
    if get[:kick]>0
      sample :bd_haus, cutoff: [70,90,50].tick(:k1), amp: 4 if kick.look
      with_fx :reverb, mix: 0.25 do
        sample :sn_dolf, finish: 0.15, rate: 2, pan: 0.5 if snare.look and one_in(2)
        sample :sn_dolf, finish: 0.125, rate: 1, pan: -0.5 if snare.look
      end
      sample :drum_cowbell, amp: rrand(0.25,0.4)+0.125, pan: rrand(-0.5,0.5) if cowbell.look
    end
    sleep 0.25
  end
  
  
  / bass short sustain /
  with_fx :ixi_techno, phase: 32 do |ixi_techno|
    
    live_loop :bass1, sync: :time do
      tick
      if get[:bassshort]>0
        
        
        
        use_synth_defaults sustain: 0.5, release: 0.12, cutoff: line(60,120, step: 0.1).reflect.look
        
        
        use_synth :saw
        play :cs2, pan: 0.5      if lowbass.look
        use_synth :fm
        play :cs2+0.05, pan: -0.5 if lowbass.look
        
        use_synth :saw
        play :d2, pan: 0.5      if highbass.look
        use_synth :fm
        play :d2+0.05, pan: -0.5  if highbass.look
        
        control ixi_techno, mix: 0  # original
        #   control ixi_techno, mix: 1  # more spice
      end
      
      sleep 0.25
    end
  end
  
  
end

Hello, …

what kind of machine are you using?

With my Core i7-3740QM(max 2.7 GHz) CPU
16GB DDR3 Memory on a Fujitsu Lifebook E752
with an EVO 860 SSD I am getting hard
dropouts and finally crashes of the
collider server after the intro
once the deep bass elements grow to overlap.

set_sched_ahead_time!  5
use_debug false
use_bpm 100 # rougthly works

Is this rational?

Could it be avoided even on this type of machine?

Thanks for a little performance study.

Cheers

Blockquote

Hi Buce
My setup

Desktop: Windows 11th Gen Intel(R) Core™ i9-11900K @ 3.50GHz, 64 GB ram (Gamer computer)
No problem keeping up with Sonic Pi + other stuff at the same time.

Dont know why, but I’m still using Sonic Pi v3.3.1 on my desktop computer, where I have to add
with_fx :level, amp: 4 do /code here/ end
To turn sound up compared to the soundlevel of what I have going besides Sonic Pi in Windows.
Perhaps something in my setup.

Laptop: Intel(R) Core™ i7-8550U CPU @ 1.80GHz 1.99 Ghz, 16 GB ram
Sonic Pi version 4.0.3
with_fx :level, amp: 4 do /code here/ end
Is way to loud, so setting amp: 1

My laptop struggle to play the code aswell.
I uncommented the

# with_fx :ixi_techno, phase: 32 do |ixi_techno|
# end

on the bass since it’s not used in the song, but something I added for fun, and the laptop could keep up without struggling.

In the beginning when you run code log says that it’s slightly behind.
I dont how to fix this except uncommenting fx effects
There are a reverb on snare drums that inside the live_loop :kick1

with_fx :reverb, mix: 0.25 do
end

That might be taking computer power
A solution could be to record a sample of the snare with reverb and then use that instead of the fx :reverb

My dogma is that I dont wanna use external samples when I recreate a song, since I learn a lot by not doing that and it’s easy to load on both desktop and laptop + post here in forum for others to explore.

Uncomment ixi code here (Something is still not properly synced musically between liveloops)

# 221117 0058 Unholy (Sonic Pi cover) draft 1
# 221117 0058 saved

# Hydra:
# Visual 1 "UNHOLY | SAM SMITH | CASSIE BARTHO CHOREOGRAPHY" https://youtu.be/QjV-tNRZfeQ

# Inspiration: UNHOLY | SAM SMITH | CASSIE BARTHO CHOREOGRAPHY
# https://youtu.be/QjV-tNRZfeQ


use_bpm 131
set :metronom, 0  # 0 off 1 on


live_loop :time, delay: 0.01 do
  sleep 1
end

live_loop :metronom1, sync: :time do
  if get[:metronom]>0
    tick
    #sample :elec_tick, amp: [4,0,0,0].look
    sample :elec_blip, amp: [4,0,0,0 ,0,0,0,0 ,0,0,0,0, 0,0,0,0].look
    sample :elec_tick, amp: [0,0,0,0 ,4,0,0,0 ,4,0,0,0, 4,0,0,0].look
  end
  sleep 1
end


live_loop :songform, sync: :time do
  tick
  
  / songform change here 0-3  /
  # manual changing here works but it's hard to times switching between sections
  songform = 3
  
  
  / set&get works (but something off sync with the bass&melody) /
  #  songform = knit(1,16, 2,16, 3,32).to_a.look  # works
  songform = knit(1,16, 2,16, 3,32).look          # works
  
  
  case songform
  
  when 0                  # 0 stop
    
    puts set :metronom, 0
    puts set :choir, 0
    puts set :kick, 0
    puts set :bassshort, 0
  when 1                  # 1 choir intro
    puts "---------------------------------"
    puts set :choir, 1
    puts set :kick, 0
    puts set :bassshort, 0
  when 2                  # 2 drum + short bass intro
    puts "///////////////"
    puts "///////////////"
    puts set :choir, 0
    puts set :kick, 1
    puts set :bassshort, 1
  when 3
    puts "#################################"
    puts "#################################"
    puts "#################################"
    puts set :choir, 1
    puts set :kick, 1
    puts set :bassshort, 1     # should be a longer bass with slide
  end
  
  sleep 1
  
end



with_fx :level, amp: 4 do
  
  #intro short bass
  q= 0.5
  mel      = [:f4,:fs4,:gs4,:gs4,  :fs4,:gs4,:a4,:gs4,:fs4,     :f4,:fs4,:gs4,:fs4,:f4,     :cs4,:d4,:fs4,:f4,:cs4,:d4,:cs4]
  melsl    = [q  ,q   ,q+q ,q+q ,  q   ,q   ,q  ,q   ,q+q+q+q ,  q , q  , q  , q  ,q+q+q+q, q   ,q  ,q   ,q  ,q+q   ,q+q  , q+q]
  #           1   2    3 4  5 6    7    8    9  10   11 12 13 14 15 16   17   18 19 20 21 22 23  24  25  26  27 28  29 30  31 32
  
  
  lowbass  = bools(1,0,0,1, 0,0,0,0,  0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0)
  highbass = bools(0,0,0,0, 0,0,0,0,  0,0,0,0, 1,0,0,1,  0,0,0,0, 0,0,0,0,  1,0,0,1, 0,0,0,0)
  
  #kick     = bools(1,0,0,0, 0,0,0,0,  0,0,0,0, 1,0,0,1,  0,0,0,0, 0,0,0,0,  1,0,0,1, 0,0,0,0)
  kick     = bools(1,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  1,0,0,1, 0,0,0,0)
  snare    = bools(0,0,0,0, 0,0,0,0,  1,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  1,0,0,0, 0,0,0,0)
  cowbell  = bools(0,0,0,0, 1,0,0,0,  0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0)
  
  
  
  / choir /
  with_fx :level, amp: 0.5 do
    with_fx :reverb, room: 0.65 do
      with_fx :krush, mix: 0.5 do
        
        live_loop :choir1, sync: :time do
          tick
          if get[:choir]>0
            use_synth :saw
            c = line(90,115,step: 0.001).mirror.tick(:c1)
            use_synth_defaults release: 0.45, cutoff: 100 #c #100
            play mel.look
            play mel.look-12, pan: 0.5
            play mel.look+12, pan: -0.5
            use_synth :blade
            #play mel.look, amp: 2
          end
          sleep melsl.look
        end
        
      end
    end
  end
  
  
  / kick /
  live_loop :kick1, sync: :time do
    #stop if get[:kick]<1
    tick
    if get[:kick]>0
      sample :bd_haus, cutoff: [70,90,50].tick(:k1), amp: 4 if kick.look
      with_fx :reverb, mix: 0.25 do
        sample :sn_dolf, finish: 0.15, rate: 2, pan: 0.5 if snare.look and one_in(2)
        sample :sn_dolf, finish: 0.125, rate: 1, pan: -0.5 if snare.look
      end
      sample :drum_cowbell, amp: rrand(0.25,0.4)+0.125, pan: rrand(-0.5,0.5) if cowbell.look
    end
    sleep 0.25
  end
  
  
  / bass short sustain /
  #with_fx :ixi_techno, phase: 32 do |ixi_techno|
  
  live_loop :bass1, sync: :time do
    tick
    if get[:bassshort]>0
      
      
      
      use_synth_defaults sustain: 0.5, release: 0.12, cutoff: line(60,120, step: 0.1).reflect.look
      
      
      use_synth :saw
      play :cs2, pan: 0.5      if lowbass.look
      use_synth :fm
      play :cs2+0.05, pan: -0.5 if lowbass.look
      
      use_synth :saw
      play :d2, pan: 0.5      if highbass.look
      use_synth :fm
      play :d2+0.05, pan: -0.5  if highbass.look
      
      #control ixi_techno, mix: 0  # original
      #   control ixi_techno, mix: 1  # more spice
    end
    
    sleep 0.25
  end
  #end
  
  
end

Hello … ultra quick response …
For my HW-configuration not more than the following fx-removal in kick seems to be sufficient:

  / kick /
  live_loop :kick1, sync: :time do
    #stop if get[:kick]<1
    tick
    if get[:kick]>0
      sample :bd_haus, cutoff: [70,90,50].tick(:k1), amp: 4 if kick.look
      #with_fx :reverb, mix: 0.25 do
      sample :sn_dolf, finish: 0.15, rate: 2, pan: 0.5 if snare.look and one_in(2)
      sample :sn_dolf, finish: 0.125, rate: 1, pan: -0.5 if snare.look
      #end
      sample :drum_cowbell, amp: rrand(0.25,0.4)+0.125, pan: rrand(-0.5,0.5) if cowbell.look
    end
    sleep 0.25
  end

The rest remained as in the original.
extra reverb and aditionally pan seems a bit hard to me as well

Can’t you do the reverb on all the live loops together sourrounding them?

  with_fx :reverb, mix: 0.25 do
    / kick /
    live_loop :kick1, sync: :time do
      #stop if get[:kick]<1
      tick
      if get[:kick]>0
        sample :bd_haus, cutoff: [70,90,50].tick(:k1), amp: 4 if kick.look
        
        sample :sn_dolf, finish: 0.15, rate: 2, pan: 0.5 if snare.look and one_in(2)
        sample :sn_dolf, finish: 0.125, rate: 1, pan: -0.5 if snare.look
        
        sample :drum_cowbell, amp: rrand(0.25,0.4)+0.125, pan: rrand(-0.5,0.5) if cowbell.look
      end
      sleep 0.25
    end
  end

Is doing well with my HW.

Thanks and good night …

1 Like