How to make a count-in before code start to play?


#1

Hi there :

I was trying to make a count-in of 4 beats,before code start to play

(1 pre-count bar).

I use to record my loops on Audacity via USB.

Want that Sonic Pi counts one bar,before i hit Rec on Audacity.

As far i know, it can be achieved using “get”,so i built a “condicional metronome”,

and tried to use “get” to held the code for one beat,but it’s not what happened.

Please,take a read on this code below :

Count In (Not Finished II)


use_bpm 100

# Sound Out

with_fx :sound_out_stereo, mix: 0 do
  
  count_in = (line 0, 4, steps: 4)
  
  live_loop :metro do
    if count_in.tick == 0
      play 70
    else
      play 70,pitch: -12
    end
    sleep 1
  end
  
  set :metro,4
  
  
  live_loop :sample do
    sample :loop_industrial,rate: 1
    sleep sample_duration(:loop_industrial)
  end
end

How can i achieve a count-in metronome ?

Thank you again !


#2

Hi GW,

I suppose the simplest way to delay the start of the song would be
tp use the ‘delay’ built into live_loop, like so:

use_bpm 100

# Sound Out
with_fx :sound_out_stereo, mix: 0 do
  
  live_loop :sample, delay: 4 do
    sample :loop_industrial,rate: 1
    sleep sample_duration(:loop_industrial)
  end
end

But you’ve specified a count-in so perhaps this
might be better suited:

use_bpm 100
x=0

live_loop :count_in do
  4.times do
    if x < 4
      play 70
    else
      play 58
      cue :go
      stop
    end
    x=x+1
    sleep 1
  end
end


# Sound Out
with_fx :sound_out_stereo, mix: 0 do
  
  
  live_loop :sample, sync: :go do
    sample :loop_industrial,rate: 1
    sleep sample_duration(:loop_industrial)
  end
end

Eli…


#3

You could just explicitly write it at the beginning of the program. Commands such as sleep written into the global scope will delay the start of any live_loops until the script actually gets to it.

4.times do
  play [70, 58, 58, 58].tick(:metro), release: 0.125
  sleep 0.5
end

live_loop :drums do
  sample [:bd_ada, :sn_dolf].ring.tick
  4.times do
    sample :drum_cymbal_closed, release: 0.003
    sleep 0.125
  end
end

#4

You’re a genius !
So simple,so good !
Thank you again.


#5

You’re quite welcome. I have to give my students some credit though, I was putting delays and stops on everything until I saw the way a few of them had constructed their own pieces.


#6

Hi Eli :

Your two counters works well.

The first one, gave me an idea on how to leave a gap between samples.

Thank you very much !