LiveOSC (Sonic Pi -> Ableton Live)

That looks good.
One or two comments.
First, you can already get tempo data and set tempo with the built in support for Ableton Link in Sonic Pi.

secondly, do you need to stop the live_loops? They wont consume many resources, but can be used for subsequent calls when they will update the data whenever it changes. Downside, you do have to prsss stop to completely finish the program.

You can however change them to stop once they have acquired their data. I usually do this by creating functions as below. This means you can use them wherever they are needed on your program, and that the liveloop will automatically restart if needed more than once. The results are updated to the time liene using set commands, from where you can subsequently retrive the data.

Here is the whole program, with the input OSC data from Live simulated at the end of the program.

#turn off some logging
use_debug false
use_osc_logging false

#define functions to set up live_loops to receive OSC data
define :getTempo do
  live_loop :getTempoLoop do
    t = sync "/osc*/live/song/get/tempo"
    ##| puts "tempo is: #{t[0]}"
    set :tempo,t[0]
    stop 
  end
end

define :getTrackNames do
  live_loop :getTrackNamesLoop do
    tn = sync "/osc*/live/song/get/track_names"
    ##| tn.length.times do |x|
    ##|   puts "track_name #{x+1} is #{tn[x]}"
    ##| end
    set :trackNames, tn
    stop #the live_loop
  end
end

define :listTrackNames do
  tn=get :trackNames
  tn.length.times do |x|
    puts "track_name #{x+1} is #{tn[x]}"
  end
end


#initiate the flive_loops
getTempo
getTrackNames


#simulate OSC data coming from Live
use_osc "localhost",4560
osc "/live/song/get/tempo",60
osc "/live/song/get/track_names","1-Selector Kit Wars",
  "2-Grand Piano Single Sample",
  "3,Basic Electric Drum Bass",
  "4-Drum Rack",
  "5-voix femenines",
  "6-Awakening Pad"

#check that data received and stored in time state
puts "Retrieved tempo is",get(:tempo)
puts "Retrieved track names list is",get(:trackNames)
puts "Track names are:"
listTrackNames

EDIT
produces this output:

=> Starting run 40

=> Redefining fn :getTempo

=> Redefining fn :getTrackNames

=> Redefining fn :listTrackNames

=> Redefining fn :live_loop_getTempoLoop

=> Redefining fn :live_loop_getTrackNamesLoop

{run: 40, time: 0.0}
 ├─ "Retrieved tempo is" 60
 ├─ "Retrieved track names list is" ["1-Selector Kit Wars", "2-Grand Piano Single Sample", "3,Basic Electric Drum Bass", "4-Drum Rack", "5-voix femenines", "6-Awakening Pad"]
 ├─ "Track names are:"
 ├─ "track_name 1 is 1-Selector Kit Wars"
 ├─ "track_name 2 is 2-Grand Piano Single Sample"
 ├─ "track_name 3 is 3,Basic Electric Drum Bass"
 ├─ "track_name 4 is 4-Drum Rack"
 ├─ "track_name 5 is 5-voix femenines"
 └─ "track_name 6 is 6-Awakening Pad"
 
=> Stopping thread :live_loop_getTrackNamesLoop

=> Stopping thread :live_loop_getTempoLoop

=> Completed run 40

=> All runs completed

=> Pausing SuperCollider Audio Server
1 Like

very elegant ! as usual !
thank you again and again