Imaginary Gamelan

Hey @robin.newman, sorry for never giving feedback on this, I just tested your suggestion in a simplified context and yes, it works fine. Thanks!

#MarkovChains Freequencies
#Robin Newman fix test

use_random_seed 1


live_loop :temp do
  set :temp, 60
  sleep 10
end


#Setting the pitches to be used
set :eins, 60
set :zwei, 62
set :drei, 63
set :vier, 65
set :fünf, 67


#Setting the rhythmic values to be used
RHYTHMIC_VALUES = [0.125, 0.5, 1, 2].pick(6)
INTERONSET=INTERONSET1=INTERNOSET2=RHYTHMIC_VALUES #set intial values for all outside liveloops

#initial state
set :current_state, 0

live_loop :rhythmic_levels do
  define :rset do |values| #function to scale INTERONSET values
    sc=[1,2,4,8].choose
    vout=[]
    values.each do |x|
      vout << x*sc
    end
    return vout
  end
  sleep (ring 4, 8, 16).choose
end

#Setting the actual notes to be used; in this case, the fifth note is omitted while the first and third each occur twice
NOTES = [get[:eins], get[:zwei], get[:drei], get[:vier], get[:fünf], get[:zwei]]

#Multiplying the rhythmic values to achieve different rhythmic levels - not sure if this actually works?!
live_loop :rhythm do
  INTERONSET = rset(RHYTHMIC_VALUES)
  puts "INTERONSET = #{INTERONSET}"
  sleep rrand_i(4, 64)
end

# State machine rules
RULES = {
  0 => [1],
  1 => [2],
  2 => [3, 3, 0],
  3 => [1, 2, 4, 4],
  4 => [5, 0],
  5 => [1]
}


with_fx :reverb, mix: 0.1 do
  
  live_loop :update_state do
    # get current state value -- 0 on the first run
    use_bpm get[:temp]
    s = get[:current_state]
    play NOTES[s] -12, amp: rrand(0.2, 0.8), sustain: 0.8, release: rrand(0.2, 0.3), pan: -0.3
    sleep INTERONSET[s]
    
    # update to next state
    set :current_state, RULES[s].choose
    
  end
  
  #initial state for the second voice
  set :current_state1, 0
  
  #As above
  live_loop :rhythm1 do
    INTERONSET1 = rset(RHYTHMIC_VALUES)
    puts "INTERONSET1 = #{INTERONSET1}"
    sleep rrand_i(4, 64)
  end
  
  
  live_loop :update_state1 do
    # get current state value for second voice -- 0 on the first run
    use_bpm get[:temp]
    s = get[:current_state1]
    play NOTES[s], amp: rrand(0.2, 0.8), sustain: 0.8, release: rrand(0.2, 0.3), pan: 0
    sleep INTERONSET1[s]
    
    # update to next state for second voice
    set :current_state1, RULES[s].choose
    
  end
  
  
  set :current_state2, 0
  
  live_loop :rhythm2 do
    INTERONSET2 = rset(RHYTHMIC_VALUES)
    puts "INTERONSET1 = #{INTERONSET2}"
    sleep rrand_i(4, 64)
  end
  
  
  live_loop :update_state2 do
    use_bpm get[:temp]
    s = get[:current_state2]
    play NOTES[s] + 12, amp: rrand(0.2, 0.8), sustain: 0.8, release: rrand(0.2, 0.3), pan: 0.3
    sleep INTERONSET2[s]
    
    set :current_state2, RULES[s].choose
    
  end
  
end