Send an array through OSC

Thanks @robin.newman

When I ran the first block of code I got this error message:

Here is the exact code I ran:

live_loop :getOsc do
  b = sync "/osc/wek/outputs"
  puts b[0]
  notes= eval b[0] #this turns "[.......]" into [.......]
  puts notes
  play_pattern_timed notes,[0.2],release: 0.2
end

However, I am no longer having the original issue for some reason. Now the entire array is stored in that variable. In fact, I am sending 3 different arrays over OSC which get sent as one long array, so I am using the each_slice method to separate them into 3 arrays which is working fine.

Here is a simplified version of the code I’m using

live_loop :getOsc do
  b = sync "/osc/wek/outputs"
  use_synth :saw
  notes, dur, time = b.each_slice((b.length/3.0).round).to_a
  notes.length.times do
    play notes.ring.tick, release: dur.ring.look
    sleep dur.ring.look
  end
end

Just to give you some insight into what I’m doing:
I’ve been playing around with standalone apps that were just released by the Magenta project by Google which is a Creative Machine Learning project built with Tensorflow.

One of the apps generates 8 measure melodies into a midi file. I’ve been converting those midi files into JSON files and playing around with them in p5.js

I wanted to try and play some of these melodies in Sonic Pi but I have no clue how to work with data files in Ruby, so I just made a script in Javascript to push the pertinent info (notes, duration, start times) into arrays and send them via OSC into Sonic Pi. The code I put above does the trick although it doesn’t account for rests or melodies that don’t start right at 0, but I’ve been playing around with that.

I intend to look deeper into this thread about playing Midi files in Sonic Pi, but since I already had a program in p5 and feel more comfortable working in javascript, I’m just happy to get the melodies to play for now.

Thanks again for your help!