# Sonic Pi OSC to Improviz visuals

**URL:** <https://in-thread.sonic-pi.net/t/sonic-pi-osc-to-improviz-visuals/6985>\
**Category:** Performances, Streams & Live Coding\
**Created:** [August 2, 2022, 7:55pm UTC](https://in-thread.sonic-pi.net/t/sonic-pi-osc-to-improviz-visuals/6985 "2022-08-02T19:55:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Relaxnow](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/relaxnow/32/2172_2.png) [@Relaxnow](https://in-thread.sonic-pi.net/u/Relaxnow)\
**Post date:** [August 2, 2022, 7:55pm UTC](https://in-thread.sonic-pi.net/t/sonic-pi-osc-to-improviz-visuals/6985/1 "2022-08-02T19:55:09Z")

</div>

[![](https://img.youtube.com/vi/HMcDAfzjpwk/maxresdefault.jpg "Sonic Pi OSC to Improviz") ](https://www.youtube.com/watch?v=HMcDAfzjpwk)

```ruby

# 200802 1758 Sonic Pi OSC to Improviz

use_osc "localhost", 5510 # Setup OSC to Improviz port

use_bpm 70

live_loop :time, delay: 0.01 do
  sleep 1
end

with_fx :reverb, room: 0.8 do
  with_fx :distortion, mix: 0.8 do
    
    
    live_loop :cowbell do
      sample :drum_cowbell, amp: 0.5, rate: knit(1,6, 0.5, 1).tick(:cb)
      osc "/vars/cb", rrand(1,8) # OSC to Improviz in variable cb
      
      sleep 3
      osc "/vars/cb", 0 # OSC to Improviz in variable cb to turn off value
    end
    
    live_loop :kick do
      # stop
      osc "/vars/kick", 0 # OSC to Improviz in variable kick to turn off value
      
      sample :drum_heavy_kick, amp: 2
      sleep 1.25
      osc "/vars/kick", rrand(1,8) # OSC to Improviz in variable kick 
    end
    
    live_loop :saf1 do
      #stop
      sample :elec_pop, slice: rrand(2,4), rate: rrand(1,2), pan: rrand(-1,1)
      sleep 0.25
    end
    
    live_loop :saf2 do
      # stop
      sample :loop_3d_printer, slice: 10, start: rrand(0.1,0.9), rate: 8, amp: 2, pan: rrand(1,-1)
      sleep 0.25
    end
    
    
    live_loop :sy do
      use_synth :growl
      play :c2
      osc "/vars/sy", 1
      sleep 4
      osc "/vars/sy", 0
      sleep 1
    end
    
    
  end # end distortion
  
  
  live_loop :sawstrings do
    # stop
    use_synth :saw
    sleep 5
    play [:c4, :ds5, :c6], attack: 5, amp: 1, cutoff: 90, pitch: -12
    sleep 5
    play [:c4, :ds5, :g5], attack: 5, amp: 1, cutoff: 90, pitch: -12
    sleep 5
    play [:a4, :c5, :f5], attack: 5, amp: 1, cutoff: 90, pitch: -12
    sleep 5
    play [:g4, :bb4, :d5], attack: 5, amp: 1, cutoff: 90, pitch: -12
    sleep 5
  end
  
end # end reverb

```

---

<div class="post-metadata">

**Author:** ![jamcultur](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jamcultur](https://in-thread.sonic-pi.net/u/jamcultur)\
**Post date:** [August 5, 2022, 2:43pm UTC](https://in-thread.sonic-pi.net/t/sonic-pi-osc-to-improviz-visuals/6985/2 "2022-08-05T14:43:51Z")

</div>

Your video is cool! I just downloaded Improviz and started it. It works correctly when I type Improviz commands in [http://localhost:3000/editor](http://localhost:3000/editor), but I don’t get any visuals when I run your program. Any idea why? Thanks!

---

<div class="post-metadata">

**Author:** ![Relaxnow](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/relaxnow/32/2172_2.png) [@Relaxnow](https://in-thread.sonic-pi.net/u/Relaxnow)\
**Post date:** [August 5, 2022, 9:25pm UTC](https://in-thread.sonic-pi.net/t/sonic-pi-osc-to-improviz-visuals/6985/3 "2022-08-05T21:25:52Z")

</div>

Thanks.

Here are the code that I used in Improviz, which you can copy to the editor, which use OSC from Sonic Pi when you run the Sonic Pi code above in Sonic Pi.

Let me know if it works 🙂

“#” uncomment in Atom  
“//” uncomment in editor

```ruby
paintOver()
# https://improviz.rumblesan.com/language.html

#motionBlur()
t = time/5
scale(4) # 1 2 4
#220802 1701 ver1.pz

background(0)

r = ext(:cb, 4)
kick = ext(:kick, 4)
sy = ext(:sy, 0)
if (sy%2)
  sphere(0.001)
  noFill()
  rotate(t)
  strokeSize(0.01)
  #stroke(255) # 0 # 255
  sphere(10)
else
  fill(0)
  cube(20)

rotate(0,0,t)
#rotate(t)
strokeSize(2)
#loop 4 times
  move(r)
  #texture(:algorave)
# rectangle(0.7,0.1,0.1)
#cube(4)
fill(255,0,0) # red
rectangle(0.05,r,0.01)
#color(1,0,0)
fill(0,0,255) # blue

triangle(0.1,kick,0.1)

stroke(255) # white
strokeSize(0.25)
rotate(t)
noFill()
rectangle(kick)

```

Where to get help: The Discord channel for Improviz

> **[Discord - A New Way to Chat with Friends & Communities](https://discord.com/channels/790732544491913216/856648656277733457)**
>
> Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.

My exploration of Improviz before I started learning Sonic Pi.

[tinyurl.com/learningImproviz](http://tinyurl.com/learningImproviz) (964 pages)  
(Take some time to load but lots of nice code with images examples to learn from)

[! MG learning Improviz 2 - Google Docs](http://tinyurl.com/mglearningimproviz2) (50 pages)

---

<div class="post-metadata">

**Author:** ![jamcultur](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jamcultur](https://in-thread.sonic-pi.net/u/jamcultur)\
**Post date:** [August 6, 2022, 3:12pm UTC](https://in-thread.sonic-pi.net/t/sonic-pi-osc-to-improviz-visuals/6985/4 "2022-08-06T15:12:08Z")

</div>

That worked great! Thank you!
