# Playing the Blues with TouchOSC

**URL:** <https://in-thread.sonic-pi.net/t/playing-the-blues-with-touchosc/434>\
**Category:** Performances, Streams & Live Coding\
**Created:** [November 19, 2017, 3:05pm UTC](https://in-thread.sonic-pi.net/t/playing-the-blues-with-touchosc/434 "2017-11-19T15:05:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrbombmusic](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/mrbombmusic/32/2282_2.png) [@mrbombmusic](https://in-thread.sonic-pi.net/u/mrbombmusic)\
**Post date:** [November 19, 2017, 3:05pm UTC](https://in-thread.sonic-pi.net/t/playing-the-blues-with-touchosc/434/1 "2017-11-19T15:05:29Z")

</div>

Finally got around to making a video of one of my projects that I made using TouchOSC after the great tutorial that @robin.newman made .

> [@Using TouchOSC with Sonic Pi](http://in-thread.sonic-pi.net/t/using-touchosc-with-sonic-pi/275/12):
>
> I have made a series of three videos posted on youtube which show in detail how to create a simple layout in TouchOSC and set it up to control Sonic Pi 3. You can find the videos [here video1](https://youtu.be/1wLcpM6G8w4)[here video2](https://youtu.be/uzAB_Iy38mQ)[here video3](https://youtu.be/fm0kDnlWPEs) or as a playlist [here](https://www.youtube.com/watch?v=1wLcpM6G8w4&list=PLjMfQ8Gw5Iq6Kg4kSNEM_3jF-LFjDdD2d) The code used in the final Sonic Pi program (which is explained in detail in the third video) is below #Test program to illustrate use of TouchOSC with Sonic Pi 3 #by Robin Newman, October 2017 set :trans,0 #set initial slider recorded position #optional…

Set up 3 buttons to play the I, IV & V chords of a Blues progression and a slider that runs through 5 octaves of a pentatonic scale to use to solo while playing the chords.

> <https://twitter.com/mrbombmusic/status/931994644405157889>

Here’s the code

```ruby
set :trans, 0

pent = scale(:e2, :minor_pentatonic, num_octaves: 5)

osc_send "192.168.1.4", 9000, "osc/Blues/fader1", 0
osc_send "192.168.1.4", 9000, "osc/Blues/toggle1", 0
sleep 0.2

live_loop :Ichord do
  use_real_time
  b = sync "/osc/Blues/push1"
  puts "Button 1 is ", b[0]
  if b[0] > 0
    play [52, 56, 62, 71], amp: 3, release: 0.5
  end
end

live_loop :IVchord do
  use_real_time
  b = sync "/osc/Blues/push2"
  puts "Button 1 is ", b[0]
  if b[0] > 0
    play [57, 61, 67, 76], amp: 3, release: 0.5
  end
end

live_loop :Vchord do
  use_real_time
  b = sync "/osc/Blues/push3"
  puts "Button 1 is ", b[0]
  if b[0] > 0
    play [59, 63, 69, 78], amp: 3, release: 0.5
  end
end

live_loop :slider do
  use_real_time
  b = sync "/osc/Blues/fader1"
  puts "slider is ", b[0]
  set :trans, b[0]*24
end

live_loop :toggle do
  use_real_time
  b = sync "/osc/Blues/toggle1"
  puts "toggle is ", b[0]
  if b[0] > 0
    use_synth :tb303
    x = play pent[get(:trans).floor], sustain: 1000
    set :x, x
    in_thread do
      loop do
        control get(:x),note: pent[get(:trans).floor]
        sleep 0.01
      end
    end
  else
    control get(:x),amp: 0,amp_slide: 0.1
    sleep 0.1
    kill get(:x)
  end
end

```

Here’s a link to download the TouchOSC template.

> **[Blues.touchosc.zip](https://drive.google.com/file/d/1R8ODkwAiol3PdT2Xw8nWLaVrECX_CsU0/view?usp=drive_open)**
>
> Google Drive file.

---

<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 19, 2017, 8:39pm UTC](https://in-thread.sonic-pi.net/t/playing-the-blues-with-touchosc/434/2 "2017-11-19T20:39:04Z")

</div>

Nice. TouchOSC makes a great controller. So flexible and versatile, and links to Sonic Pi so easily.

---

<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 19, 2017, 10:30pm UTC](https://in-thread.sonic-pi.net/t/playing-the-blues-with-touchosc/434/3 "2017-11-19T22:30:22Z")

</div>

I gave the code a run through and suggest a couple of alterations.  
First, if you are sending your OSC messages to the same address, it is more convenient to use  
`use_osc "192.168.1.4",9000`  
to set up the ip address and port followed by calls to `osc` to send messages  
Secondly, you shouldn’t add osc to the beginning of the OSC address when SENDING a message, but only use the address of the TouchOSC element with which you wish to communicate. Sonic Pi only prepends /osc to all INCOMING OSC messages.  
Putting both these points together use the code:

```ruby
set :trans, 0
use_osc "192.168.1.240",9000 #additional line to specify destination for OSC command

pent = scale(:e2, :minor_pentatonic, num_octaves: 5)

osc "/Blues/fader1", 0 #use osc instead of osc_send, and dont add osc to start of address
osc "/Blues/toggle1", 0
sleep 0.2

```

for the beginning of the code for the program. The remainder is as you specify above.

Fortuitously your code worked because you used `osc/Blues/fader1` rather than `/osc/Blues/fader1` (OSC addresses should start with /) and the `osc` was ignored thus actually using `/Blues/fader1` as the (correct) address.

---

<div class="post-metadata">

**Author:** ![mrbombmusic](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/mrbombmusic/32/2282_2.png) [@mrbombmusic](https://in-thread.sonic-pi.net/u/mrbombmusic)\
**Post date:** [November 20, 2017, 1:29am UTC](https://in-thread.sonic-pi.net/t/playing-the-blues-with-touchosc/434/4 "2017-11-20T01:29:46Z")

</div>

Thanks Robin! I feel like my code working is always fortuitous 😀
