Sending Generated Notes as OSC Int

#1

Hello,

I’m trying to send notes as integers via OSC but I don’t know how to access my notes data generated by my play method. Must be simple but I’m new. Thanking you in advance.

tisane

use_osc “127.0.0.1”, 8000

live_loop :shapes do
use_synth :sine
notes = play (scale :e3, :minor_pentatonic).tick, release: 0.95
print notes
osc “/p5/note”, notes.to_i
sleep 1
end

0 Likes

#2

Hi Tisane,

a warm welcome to the Sonic Pi community - it’s lovely to have you here :slight_smile:

In your example, the notes variable you define happens to be an object which represents the actual running synthesiser in the SuperCollider synthesis engine. This is used to control the synth as it’s running. See http://sonic-pi.net/tutorial.html#section-7-1 for more information about this.

The easiest way to achieve what you want is to figure out the note first and use a variable for it:

live_loop :shapes do
  use_synth :sine
  note = (scale :e3, :minor_pentatonic).tick
  play note, release: 0.95
  print note
  osc “/p5/note”, note.to_i
  sleep 1
end

Hope this helps :slight_smile:

0 Likes

#3

Dear Sam,

thank you for the warm welcome and the rapid reply. Makes perfect sense now. I’m coming from OOP and thinking we have dot operators to access object variables. Just a slight yet important correction in the above code. notes.to_i should be replaced by note.to_i :––) Thanks again.

1 Like