Help a newbie with OSC - IN

HI there
I had a play with the problems you list and attach possible answers to most of them.
I used a test TouchOSC template shown below.

The top section is a rotary slider address /test/wave
This is surrounded by three LEDS addresses /test/led0 to /test/led2 These are lit by my program to indicate the current value of the waveopt.
Underneath these in the middle of the screen is a two way push switch with 1 column and two rows.
The two switch array has address ‘/test/chord’ with the two individual switches at /test/chord/1/1 and
/test/chord/1/2 These are used to control which of the two chords Cs3:minor and Fs3:minor should be played.
The bottom section is a single toggle switch address /test/mute which is used to mute a running live_loop.

Your question 1 I use the rotary and decode whereabout in its range it is. values <0.3 select 0 for the waveopt, values from 0.3 to 0.6 select 1 and values over 0.6 select value 2. These values are saved and then applied via use_merge_synth_defaults commands where required.

Your question 2 could be answered in a similar fashion although I haven’t implemented it.

Your question 3 I am not sure if you just want to switch the volume on or off, or to sync the start of your loop as well.
If the former then I have given an example of using an fx :level effect to control the volume of an embedded live loop. You could have more than one live loop command inside the fx :level wrapper and they would all be effected.
If you want to sync the start of the live loop as well, then some of the code from my loop_controller program which is described here http://in-thread.sonic-pi.net/t/osc-loop-machine-makeymakey/850/20?u=robin.newman might help

Your question 4 I thinkI need more detail to know how to help here.

Your question 5 I detect which of the two linked pushbuttons /test/chord have been pushed and then play the appropriate chord.

My code is shown below

use_osc "172.20.10.5",9000 #address of TouchOSC pad
set :waveopt,0 #initialise waveopt setting
osc "/test/led0",1 #initialise feedback leds
osc "/test/led1",0
osc "/test/led2",0
osc "/test/wave",0.2
live_loop :getwaveopt do #live loop to update waveopt setting
  use_real_time
  b= sync "/osc/test/wave"
  if b[0] < 0.3
    set :waveopt,0
    osc "/test/led0",1
    osc "/test/led1",0
    osc "/test/led2",0
  elsif b[0] <0.6
    set :waveopt,1
    osc "/test/led0",0
    osc "/test/led1",1
    osc "/test/led2",0
  else
    set :waveopt,2
    osc "/test/led0",0
    osc "/test/led1",0
    osc "/test/led2",1
  end
end

define:parse_sync_address do |address| # used to decode wild cards
  v= get_event(address).to_s.split(",")[6]
  if v != nil
    return v[3..-2].split("/")
  else
    return ["error"]
  end
end

use_synth :tb303

live_loop :selectchord do #select one of two chords to play
  use_real_time
  b= sync "/osc/test/chord/1/*" # * is either 1 or 2
  if b[0]==1
    switch=parse_sync_address("/osc/test/chord/1/*")[4].to_i
   #the parse function gives output like  ["osc", "test", "chord", "1", "2"]
   #I then select the 5th entry using [4] and convert to integer from a string
    puts switch
    use_merged_synth_defaults wave: get(:waveopt)
    play_chord (chord :Cs3,:minor),release: 0.4,amp: 1 if switch==1
    play_chord (chord :Fs3,:minor),release: 0.4,amp: 1 if switch==2
  end
end

#next section uses fx_level to control volume in a live loop
with_fx :level, amp: 0 do |v|
  set :val,v #store reference to fx command
  live_loop :getVol do
    use_real_time
    b= sync "/osc/test/mute" #get state of mute toggle switch
    levelVol=b[0]
    puts levelVol
    control get(:val),amp: levelVol,amp_slide: 0.1 #adjust level
  end
  
  live_loop :controlledVolume do
    n=(chord :Cs3,:minor).tick
    use_merged_synth_defaults wave: get(:waveopt)
    play n,amp: 0.7,release: 0.2 #amp setting is modified by enveloping level value
    sleep 0.2
  end
end
1 Like