4: Variable Flasher

Posted on Wednesday the 10th of February, 2010

Sadly I didn’t get too much time for my creative thing today. This evening I attended a very interesting presentation on MacRuby at the local Amsterdam CocoaHeads meeting. I enjoyed it a lot - the speaker was both knowledgeable and engaging and great to chat with afterwards.

So, what did I get up to? Well I managed to get back-communication from Polynome to SCLang working. I was initially running into problems getting SCLang to register the OSC messages that I was sending. However, after scrutinising the documentation I ascertained that SCLang expects all external OSC messages on an explicit port: 57120. Once I figured that out (and not to have two instances of SCLang running simultaneously) things became a lot more straightforward.

I essentially had to add two components. Firstly the I needed to tell my Polynome client to send a new rate when a button was pressed. I achieved this with the button_pressed method (which does some very basic calculation on the x and y coords of the button to generate a rate value). This is then sent off via OSC on the SCLang port.

class SCFlasher < Polynome::Client
  def init
    listen(5706, "/tick") {toggle_all}
  end

  def button_pressed(x,y)
    send_to(57120, "/press", (x * 8) + y)
  end
end

Finally I had to add an OSC listener at the SCLang side. For this I used a OSCresponderNode. The first param being nil means that the responder will listen to anybody attempting to talk over that port. I specify that I’m listening for the path /press and I then print out the message (for sanity logging) and then use the first param (an integer) to update the tempo of the TempoClock.

~outAddr = NetAddr("localhost", 5706);
c = TempoClock(1);
c.schedAbs(t.beats.ceil, { ~outAddr.sendMsg("/tick"); 1});

OSCresponderNode(nil, '/press', { |t, r, msg| msg.postln ; c.tempo = msg[1]  }).add;

Running all the processes results in the required behaviour. I’ve refrained from recording a video, as there’s only so many epileptic inducing flashing videos I want to impose on people. I’ll create another video when things get a little more interesting (hopefully soon).

Recent Posts