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 :
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.
When im trying to use osc message (in that case in range 0-1)
get the error like this:
“Runtime Error”
Thread death ±-> :live_loop_alla
unable to normalise argument with key :amp and value [0.2434298403294823]
And in case of attempt to control cutoff parameter:
Runtime Error: […] - NoMethoodError
Thread death
undefined method ‘>=’ for nill:NilClass
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
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
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… I think, this should work after some changes … will check later …
@Martin thank you, i tried to make it that way 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! 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
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
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.