Need explanation ring


#1

Hi,

This is a simple code but the run is strange no ?

use_bpm 60

progression = (ring   (chord :c3, :major), (chord :d4, :major), (chord :e3, :major), (chord :gs3, 'major') )

# mémorise l'accord en cours dans une variable
accord_en_cours = progression[0]

define :instrument do | instru="piano", volume = 1, a=0, d=1, s=1,r=1|
  use_synth instru
  use_synth_defaults  amp: volume, attack: a, delay: d, sustain: s,release: r
end


live_loop :accords do
  instrument 'prophet'
  play_chord accord_en_cours
  sleep 4
  # next chord
  accord_en_cours = progression.tick
end

Why do the first chord is played twice the first time ???

Thanks for your help


#2

Hey @nlb. The reason that is happening is because when you call tick during a run, the first time it is called it returns 0. (Or in the case of .tick, returns the first element in the array/ring).
One of the ways you could make it play the progression correctly would be to remove the accord_en_cours variable and simply tick through the progression at the same place you play it:

live_loop :accords do
  instrument 'prophet'
  play_chord progression.tick
  sleep 4
end

Hope that helps!


#3

hi @ethancrawford !
merci !

a bit of code to practice scales with another instrument i.e. guitar :slight_smile:

# tempo à 60 battements par minute - pulsation à la seconde
use_bpm 60

progression = (ring   (chord :c3, :major), (chord :d4, :major), (chord :e3, :major), (chord :gs3, 'major') )

# mémorise l'accord en cours dans une variable
accord_en_cours = progression[0]

define :instrument do | instru="piano", volume = 1, a=0, d=1, s=1,r=1|
  use_synth instru
  use_synth_defaults  amp: volume, attack: a, delay: d, sustain: s,release: r
end


live_loop :accords do
  instrument 'prophet'
# the ".tick" call gives the first element of the ring and then goes the next one
  play_chord progression.tick
  sleep 4
end

uncomment do
  live_loop :gamme do
    instrument
    gammeNotes = scale accord_en_cours[0], :major, num_octaves: 1
    puts 'Nombre de notes jouées ' + gammeNotes.length.to_s
    puts 'notes de la gamme en cours ' + gammeNotes.to_s
    
    8.times do
      play gammeNotes.tick
      sleep 0.5
    end
    
  end
end