Cool, something like a CSV file would be super easy to work with
Probably the workflow I’d wind up with is as follows:
- Read in the data into an internal Array. I’d probably use an array of associative maps with a key such as
:timestamp
and then other appropriate keys for the data values you want to work with. - Map over the array to create a new array with modified values (this is where you’d munge the values where necessary - unless this munging has happened prior to storing the values as a CSV file or whatever you wind up with)
- Iterate over the (new) array and for each value do something - this might be to
sleep
for some amount of time with respect to the:timestamp
and/or it might be to play a note, etc.
Doing things like looking up notes of a scale with an index is pretty simple:
# Get the 4th element from an E minor pentatonic scale
(scale :e3, :minor_pentatonic, num_octaves: 3)[3]
Changing the current chord could be as simple as having the root of the scale be read from Sonic Pi’s timestate, which can be modified either whilst iterating through the notes, say every nth value, or via a separate thread running in a live_loop
. Reading from Time State is done via the get
function such as:
# Read root note from Time State and store in a local variable
root = get[:root_note]
(scale root, :minor_pentatonic, num_octaves: 3)[3]
Elsewhere you can call set :root_note, :e4
to set it. Note that using get
and set
is completely thread safe and deterministic, so you’ll always get the same musical output regardless of race conditions
With respect to other options:
- I’m pretty confident that anything you can do in Python you’ll be able to do in Sonic Pi - only Sonic Pi will also give you the added bonus of having very easy access to well-timed, thread-safe sound generation.
- The Teensy is amazing hardware, but you’re likely to have to talk serial to get the data to it and either work with someone elses synth code or design your own.
- Pd is also amazing but is pretty low level (it’s kind of like a code version of a modular synth) and I dont’ think it has many particularly high-level constructs for easily working with external data (although I’m sure it must be possible).
Whatever you end up with, I’d love to hear what you do and whether or not Sonic Pi helped in any way. All feedback helps inform how Sonic Pi will continue to evolve in the future.