# Test OSC Control program for Sonic Pi

**URL:** <https://in-thread.sonic-pi.net/t/test-osc-control-program-for-sonic-pi/2864>\
**Category:** Creations & Ideas\
**Created:** [October 30, 2019, 11:05pm UTC](https://in-thread.sonic-pi.net/t/test-osc-control-program-for-sonic-pi/2864 "2019-10-30T23:05:54Z")\
**Posts on this page:** 4\
**Page:** 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:** [October 30, 2019, 11:05pm UTC](https://in-thread.sonic-pi.net/t/test-osc-control-program-for-sonic-pi/2864/1 "2019-10-30T23:05:55Z")

</div>

[Recently I was asked](http://in-thread.sonic-pi.net/t/working-with-osc-as-variables/2840/10) about controlling various features of a running sample using OSC. This program and an associated article and video is the result.

> **[test OSC controller for Sonic Pi](https://rbnrpi.wordpress.com/test-osc-controller-for-sonic-pi/)**
>
> I haven’t written anything for some time on this site. Instead I have ben putting material onto the in-thread.sonic-pi.net site. However, recently I was asked for help on that site from someo…

[![](https://img.youtube.com/vi/sR7tNhCQjVk/hqdefault.jpg "testOscControl") ](https://www.youtube.com/watch?v=sR7tNhCQjVk)

[code link](https://gist.github.com/rbnpi/6cc6e32d37bfd168de01205954512e9c)

---

<div class="post-metadata">

**Author:** ![dewildequinten](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@dewildequinten](https://in-thread.sonic-pi.net/u/dewildequinten)\
**Post date:** [November 5, 2019, 9:28pm UTC](https://in-thread.sonic-pi.net/t/test-osc-control-program-for-sonic-pi/2864/2 "2019-11-05T21:28:35Z")

</div>

Awesome project. Is it possible to make a generalized example for only receiving OSC messages.  
Because I’m confused about the sending part that are involved and its becomes very specific the example.

I just have continuous data coming in from an ESP wifi module and I need to set a variable set for each incoming osc signal. It must be easier not?  
😪🥵

---

<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:** [November 5, 2019, 11:12pm UTC](https://in-thread.sonic-pi.net/t/test-osc-control-program-for-sonic-pi/2864/3 "2019-11-05T23:12:58Z")

</div>

Here is a simpler system which receives inputs from two separate sources via OSC  
The received data is stored using set commands and is then available for a separate live loop to do whatever you want with it. To test, I am generating the OSC messages locally in Sonic Pi, but they can come externally from your ESP8266, in which case you miss out (or comment out) the local section.

```ruby
use_osc "localhost",4559 # used only for local testing where SP creates the data.
use_debug false
use_osc_logging false

live_loop :var1 do #receive and store var1 data
  v1 = sync "/osc/test/var1"
  set :v1,v1[0] # store the received data
end

live_loop :var2 do
  v2 = sync "/osc/test/var2" #receive and store var2 datga
  set :v2,v2[0] #store the second variable value
end

#as many as you need like the above

live_loop :latestData do #independent live loop processes latest available data
  puts "latest values var1 #{get(:v1)} var2 #{get(:v2)}"
  synth :tri,note: get(:v1),release: 0.4 #first variable adjust pitch
  synth :saw,note: get(:v2),release: 0.4 #second variable adjusts pitch
  sleep 0.4 #latest values read every 0.4 beats
end

#local generation of test osc messages
live_loop :createData1 do
  osc "/test/var1",rrand_i(60,72)
  sleep 0.2
end
live_loop :createData2 do
  osc "/test/var2",rrand_i(72,84)
  sleep 0.6
end

```

The two test data streams run at different rates, so you can hear the two variables updating at different times not synced to each other. Depending on how rapid a response you need, you may require to add use\_real\_time.

---

<div class="post-metadata">

**Author:** ![dewildequinten](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@dewildequinten](https://in-thread.sonic-pi.net/u/dewildequinten)\
**Post date:** [November 6, 2019, 8:45pm UTC](https://in-thread.sonic-pi.net/t/test-osc-control-program-for-sonic-pi/2864/4 "2019-11-06T20:45:35Z")

</div>

AMAZING! IT WORKS PERFECTLY AND I CAN CHANGE EVERYTHING OR ADD STUFF EASILY!

Sorry about the caps lock but I needed to do that!

🙌🙌🙌🙌🙌🙌🙌🙌🙌🙌🙌🙌🙌🙌🙌🙌🙌
