OSC - Offbeat Series of Complications

Hello community!
Im struggeling with a few problems with OSC messages and i coulnd find simmular cases on the forum.
Im sending osc messages from distance sensor via python script to sonic pi, but with touchOSC i have the same problems, so probably its on the side of my code//settings in sonic pi

Everythings looks fine, messages are coming and working good. For example -

a = sync "/osc/note" etc.
play a

BUT…

Sometimes :

  1. When i do sync - for example:
a = sync "/osc/oi"

and try to start loop —> the program does not start, but when i cancel the code with “#” it starts normally.

  1. When im trying to use osc message (in that case in range 0-1)

error1
get the error like this:

“Runtime Error”
Thread death ±-> :live_loop_alla
unable to normalise argument with key :amp and value [0.2434298403294823]

  1. And in case of attempt to control cutoff parameter:

Runtime Error: […] - NoMethoodError
Thread death
undefined method ‘>=’ for nill:NilClass

Probably im overlooking something obvious but i really can’t find what it is…

The same problem is on Rpi and the laptop.
I would be really glad for any help in that issues.

Greetings!

hi,

You can make test with sending osc message from sonic pi to sonic pi to see if your spi code works.

os version ? sonic pi version ? Raspberry pi version ?

You have to check the value received
puts d
and maybe have to round the value you want to use :
amp:d.round(2)

Another point, using keywords reserved by sonic pi as do is not a good idea in general. so name your live_loop :something. and to finish, please copy / paste your code to help us to copy / paste the problematic code into our sonic pi.
Cheers

Hi, thanks for feedback!
Versions:
Raspbian GNU/Linux 10 (buster), Release 10 , Sonic Pi v3.1, Raspberry pi 3b+
on laptop - windows 10

edit:
iI just tried sendning osc from sonic pi to sonic pi and it’s working only on “localhost” if i try use ip of another computer i doesnt sending any message

with puts d i get:
2020-04-14 09_17_17-Sonic Pi

with amp: d.round(2) - gives back error :

code:

use_osc "192.168.1.3", 4559
osc "/hello/world"
live_loop :oscheck do
  use_real_time
  a = sync "/osc/note"
  d = sync "/osc/oi"
  puts d
  sample :ambi_piano, amp: d.round(2), cutoff: a
  sleep 1
end

Hi @zwrok,

untested guess: You might want to try control:

live_loop :do do
  use_real_time
  d = sync "/osc/oi"
  s = sample :ambi_choir
  control s, amp: d
  sleep 1
end

Another way to achieve what you want and decouple listening to osc commands on the one hand and working with the results on the other:

live_loop :listen do
  use_real_time
  d = sync "/osc/oi"
  control get(:ambi_sample), amp: d # use reference to change running sample
  set :vol, d
  # here you can put more ears for other osc messages ...
  # see e. g. https://github.com/mbutz/monome-lmq/blob/master/monome-lmq-34.rb#L35
end

live_loop :do do
  s = sample :ambi_choir, amp: get(:vol)
  set :ambi_sample, s # reference to running sample
  sleep 1
end

EDIT: Well, probably not a good idea to type code from my bad memory… :wink: I think, this should work after some changes … will check later …

On which os do you encounter the problem ? WIndows 10 or with sonic pi v3.1 on raspberry pi ?

this following code works

# test on spi 3.2.2 on ubuntu-18.04.04
# nlb - 14042020

use_osc "localhost", 4560


##| n = 0.565656
##| puts n.round(2)
##| n_string = "0.98989989898"
##| n_float = n_string.to_f
##| sample :ambi_piano, amp: n_float


live_loop :sendMe do
  osc "/osc/note", (line 60, 120, steps: 4, inclusive: true).tick
  osc "/osc/oi", (ring 0.5, 1, 1.5, 2).tick('amp')
  sleep 1
  
end

live_loop :oscheck do
  use_real_time
  c_value = sync "/osc:127.0.0.1:4560/osc/note"
  amp_value = sync "/osc:127.0.0.1:4560/osc/oi"
  sample :ambi_piano, amp: amp_value[0], cutoff: c_value[0]
end

Could you try it and tell us if you solve your problem ?

@Martin thank you, i tried to make it that way :slight_smile: it play the sample once , and when it’s coming to line with “control” it gives back same errors.

@nlb the errors are not apearing anymore with your code! :sunny: but the sound is not generated. This is weird becouse i have the same problems on Rpi and on laptop with win10 on both i have sonic pi v3.1

log

ok so uncomment the firsr part of my code

##| n = 0.565656
##| puts n.round(2)
##| n_string = "0.98989989898"
##| n_float = n_string.to_f
##| sample :ambi_piano, amp: n_float

you should hear something. Note that the sonic pi 3.1 version if you install it via apt get install does not fully work on raspberry pi.

ah oui ! please install on windows 10 the v3.2.2 and it will work : the osc and midi “processings” are not the same on v3.1.

1 Like

The problem you are having is because the data you are receiving is sent in a list. IF there are two or more bits of data eg note and duration you can use this

note,duration = sync "/osc*/oi"`
play note: note, release: duration

however, if you are only sending one piece of data you need to do this:

d = sync "/osc*/oi"
sample :ambi_choir,amp: d[0]

If you look at the cues log you can see the data coming in shown in a list

eg /osc/oi [0.256......]
note the [ ] around the number.
so your first loop will work if you chage it to

live_loop :alla do
  use_real_time
  d = sync "/osc/oi" #for versions after sp3 you need "/osc*/oi" here
  sample :ambi_choir, amp: d[0] #the first, and only item in the received list
  sleep 1 #in fact this is not necessary, as it will wait until the next sync anyway
end

Hope this helps

2 Likes

yes you could replace "/osc:127.0.0.1:4560/osc/note" by the /osc*/note but to debug it’s better to know where the signal comes from ip:port/path.

@robin.newman

live_loop :happy do
    with_fx echo do 
    print "thank you!! that was the problem!!"
    sleep 0.00001
    end
end

super cool, i had suspictions and the begginig that it can be something with list , but it was working with “play” and my osc app was sending this in the same format, so i was confused and still to much green in programing to find solution.

@nlb Update had solved the first problem i described. It was because the port of the python osc script was changing. I was not able to see that in previous version so indeed this is a really great update for solving bugs.

Thank you all for help! :sunny:

2 Likes