Chords progression triggered via Tick

Hi,

Try to play 4 chords of Am, then 4 chords of F Major, one beat each.

try with tick

progression = (ring (chord :a, 'minor'), (chord :f, 'major'))

live_loop :chords do
  tick(:foo) # to count the number of chords played 0 1 2 3
  if look(:foo) == 3 then
    puts "tick value : "+ look(:foo).to_s
    tick(:next)
    tick_reset(:foo)
  end
  
  play progression.look(:next)
  sleep 1
end

Is there somebody to explain why it doen’t do what i expect ? i must miss something.
Thanks

1 Like

If you put :wink: a few extra puts lines in that code, it becomes a little clearer:

progression = (ring (chord :a, 'minor'), (chord :f, 'major'))

live_loop :chords do
  tick(:foo) # to count the number of chords played 0 1 2 3
  puts "foo: #{look(:foo)}"
  if look(:foo) == 3 then
    puts "tick value : "+ look(:foo).to_s
    tick(:next)
    tick_reset(:foo)
  end
  puts "next: #{look(:next)}"
  play progression.look(:next)
  sleep 1
end

Which gives the following output in the Log panel:

{run: 75, time: 0.0, thread: :live_loop_chords}
 β”œβ”€ "foo: 0"
 β”œβ”€ "next: 0"
 └─ synth :beep, {note: [69.0, 72.0, 76.0]}
 
{run: 75, time: 1.0, thread: :live_loop_chords}
 β”œβ”€ "foo: 1"
 β”œβ”€ "next: 0"
 └─ synth :beep, {note: [69.0, 72.0, 76.0]}
 
{run: 75, time: 2.0, thread: :live_loop_chords}
 β”œβ”€ "foo: 2"
 β”œβ”€ "next: 0"
 └─ synth :beep, {note: [69.0, 72.0, 76.0]}
 
{run: 75, time: 3.0, thread: :live_loop_chords}
 β”œβ”€ "foo: 3"
 β”œβ”€ "tick value : 3"
 β”œβ”€ "next: 0"
 └─ synth :beep, {note: [69.0, 72.0, 76.0]}
 
{run: 75, time: 4.0, thread: :live_loop_chords}
 β”œβ”€ "foo: 0"
 β”œβ”€ "next: 0"
 └─ synth :beep, {note: [69.0, 72.0, 76.0]}
 
{run: 75, time: 5.0, thread: :live_loop_chords}
 β”œβ”€ "foo: 1"
 β”œβ”€ "next: 0"
 └─ synth :beep, {note: [69.0, 72.0, 76.0]}
 
{run: 75, time: 6.0, thread: :live_loop_chords}
 β”œβ”€ "foo: 2"
 β”œβ”€ "next: 0"
 └─ synth :beep, {note: [69.0, 72.0, 76.0]}
 
{run: 75, time: 7.0, thread: :live_loop_chords}
 β”œβ”€ "foo: 3"
 β”œβ”€ "tick value : 3"
 β”œβ”€ "next: 1"
 └─ synth :beep, {note: [65.0, 69.0, 72.0]}

Now, looking at that, you’ll notice that yes, your code calls tick(:next) when look(:foo) == 3, but even then, the first time around, look(:next) still only equals 0. Meaning that it will still play A min.
Then, tick(:foo) continues to increment :foo up to 3 a second time, and once look(:foo) == 3 the second time around, look(:next) ends up as 1, and F Maj is played.

Hope that makes sense! :slight_smile:

Here’s two examples of ways you could achieve what you want:

progression = (ring (chord :a, 'minor'), (chord :f, 'major'))

live_loop :chords do
  tick(:foo)
  tick(:next) if look(:foo) % 4 == 0
  play progression.look(:next)
  sleep 1
end

Or,

progression = (ring (chord :a, 'minor'), (chord :f, 'major'))

live_loop :chords do |i|
  tick(:next) if i % 4 == 0
  play progression.look(:next)
  sleep 1
  i += 1
end

(They are almost identical - the second increments a counter manually rather than using a second tick/look pair)

3 Likes

now everything is clear and I feel a bit idiot now that i read again my code…
my preference goes to your first version.
thanks a lot !

1 Like

Another way, simpler:

progression = (ring (chord :a, 'minor'), (chord :f, 'major'),
               ( ring :c4, :f4, :a4, :d5 ), # cool we can create our own chords
               ( ring :d4, :g4, :a4, :d5 ) 
               )


use_bpm 120

live_loop :chords_progression_02 do
  
  current = progression.tick
  4.times do
    play current
    sleep 0.5
  end
end
3 Likes

That works too :smile: There’s also using progression = (ring ...).stretch(4) and playing every list item once instead of four times :slight_smile:

2 Likes

Good idea @ethancrawford
so

progression = ( ring 
                                (chord :a, 'minor'), 
                                (chord :f, 'major'),
                                ( ring :c4, :f4, :a4, :d5 ), # cool we can create our own chords
                               ( ring :d4, :g4, :a4, :d5 ) 
        )

live_loop :strech_way do
  whole_progression = (progression).stretch(4)
  play whole_progression.tick
  sleep 1
end
1 Like

As far as chords progression is concerned, do not miss this piece of code http://sonic-pi.mehackit.org/exercises/en/04-generate-sounds/04-chord-progressions.html