# OSC - Offbeat Series of Complications

**URL:** <https://in-thread.sonic-pi.net/t/osc-offbeat-series-of-complications/3645>\
**Category:** Support, Help & Resources\
**Created:** [April 13, 2020, 9:55pm UTC](https://in-thread.sonic-pi.net/t/osc-offbeat-series-of-complications/3645 "2020-04-13T21:55:48Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![zwrok](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/zwrok/32/1327_2.png) [@zwrok](https://in-thread.sonic-pi.net/u/zwrok)\
**Post date:** [April 13, 2020, 9:55pm UTC](https://in-thread.sonic-pi.net/t/osc-offbeat-series-of-complications/3645/1 "2020-04-13T21:55:48Z")

</div>

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 -

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

```

BUT…

Sometimes :

1. When i do sync - for example:

```ruby
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](https://europe1.discourse-cdn.com/flex017/uploads/sonic_pi/original/2X/f/f4145d2d33fec15383f8835a34f3c76adf3ce159.png)  
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

 ![error](https://europe1.discourse-cdn.com/flex017/uploads/sonic_pi/original/2X/b/b3586f93b3de4bd5469bcea2946321faa3fabacf.jpeg)

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!

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [April 14, 2020, 6:10am UTC](https://in-thread.sonic-pi.net/t/osc-offbeat-series-of-complications/3645/2 "2020-04-14T06:10:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zwrok](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/zwrok/32/1327_2.png) [@zwrok](https://in-thread.sonic-pi.net/u/zwrok)\
**Post date:** [April 14, 2020, 7:26am UTC](https://in-thread.sonic-pi.net/t/osc-offbeat-series-of-complications/3645/3 "2020-04-14T07:26:14Z")

</div>

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](https://europe1.discourse-cdn.com/flex017/uploads/sonic_pi/original/2X/b/b6b9c125ae4d65eaa5b15f30f5ef800852087934.png)

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

 ![2020-04-14 09_24_03-Sonic Pi](https://europe1.discourse-cdn.com/flex017/uploads/sonic_pi/original/2X/d/db2d8525d8b2a9c2ddb13edcf6aa4c321ebcf97f.png)

code:

```ruby
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

```

---

<div class="post-metadata">

**Author:** ![Martin](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/martin/32/157_2.png) [@Martin](https://in-thread.sonic-pi.net/u/Martin)\
**Post date:** [April 14, 2020, 7:59am UTC](https://in-thread.sonic-pi.net/t/osc-offbeat-series-of-complications/3645/4 "2020-04-14T07:59:26Z")

</div>

Hi @zwrok,

untested guess: You might want to try `control`:

```ruby
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:

```ruby
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 …

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [April 14, 2020, 8:08am UTC](https://in-thread.sonic-pi.net/t/osc-offbeat-series-of-complications/3645/5 "2020-04-14T08:08:03Z")

</div>

> [@zwrok](#):
>
> Sonic Pi v3.1

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

this following code works

```ruby
# 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 ?

---

<div class="post-metadata">

**Author:** ![zwrok](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/zwrok/32/1327_2.png) [@zwrok](https://in-thread.sonic-pi.net/u/zwrok)\
**Post date:** [April 14, 2020, 8:49am UTC](https://in-thread.sonic-pi.net/t/osc-offbeat-series-of-complications/3645/6 "2020-04-14T08:49:59Z")

</div>

@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

![log](https://europe1.discourse-cdn.com/flex017/uploads/sonic_pi/original/2X/b/bedb58b3d2036b9701020f0c8f7f87c88e9e65e3.png)

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [April 14, 2020, 8:58am UTC](https://in-thread.sonic-pi.net/t/osc-offbeat-series-of-complications/3645/7 "2020-04-14T08:58:05Z")

</div>

ok so uncomment the firsr part of my code

```ruby
##| 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.

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [April 14, 2020, 10:48am UTC](https://in-thread.sonic-pi.net/t/osc-offbeat-series-of-complications/3645/8 "2020-04-14T10:48:09Z")

</div>

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

```ruby
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:

```ruby
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

```ruby
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

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [April 14, 2020, 10:56am UTC](https://in-thread.sonic-pi.net/t/osc-offbeat-series-of-complications/3645/9 "2020-04-14T10:56:32Z")

</div>

> [@nlb](#):
>
> c\_value = sync “/osc:127.0.0.1:4560/osc/note”

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.

---

<div class="post-metadata">

**Author:** ![zwrok](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/zwrok/32/1327_2.png) [@zwrok](https://in-thread.sonic-pi.net/u/zwrok)\
**Post date:** [April 14, 2020, 11:37am UTC](https://in-thread.sonic-pi.net/t/osc-offbeat-series-of-complications/3645/10 "2020-04-14T11:37:46Z")

</div>

@robin.newman

```ruby
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! ☀
