# Playing the Blues with TouchOSC

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 .

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.

Here’s the code

``````set :trans, 0

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

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

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

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:

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

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.