Phrase Script Editor Range/ Multiple Octaves

Can anyone help me figure out how to use a scale over more than one octave within the new phrase script editor? For now even just having a random note emitted from say two or three octaves of the chromatic scale would be a great place to start!

I’ve gotten some cool stuff going using my own ideas and altering code from the documentation/ github page but I can’t for the life of me find out how to set a range between say c3 & b5 or just use two octaves, it always seems to be across one!

The next step would be for a pattern or pulse to stay mainly on the route note and first octave but jump up an octave or two every now and then, but I think I can hopefully figure that out once I know how to use octaves and random transposing or whatever it might be!

Thanks and sorry for the long rambling post!!

You can get a random integer between two numbers if you supply two arguments to math.random. Multiply with 12 to get octave offset from another number representing the key (C is 0, C# is 1 etc).

return pattern {
  unit = "1/8",
  event = function(context)
    local key = math.random(0, 11)
    local octave = math.random(3, 5)
    return note(key + octave * 12)
  end,
}