Thursday, February 9, 2012

SoundCipher Processing Library and TouchOSC

The SoundCipher library the playNote function; it plays a not according to user input for pitch, volume and duration. It has a few other functions but i havent messed with them yet(my iPod is a little small for a full piano :))

I created a TouchOSC layout with three faders: Pitch, Volume, and Duration and a "Play Note" button. The faders, obviously, change the value they are called.Pitch is varied from 0 to 120(60 is middle C), volume varies from 0 to 100%, and duration is in seconds from 0 to 2 seconds. and the note that has been created using the faders is played when the button is pressed on the iPod.

OSC layout noteOSCtest2.touchosc.

Processing Code:

import oscP5.*;        //  Load OSC P5 library
import netP5.*;        //  Load net P5 library
import arb.soundcipher.*; //http://explodingart.com/soundcipher/tutorials.html

OscP5 oscP5;            //  Set oscP5 as OSC connection

SoundCipher sc = new SoundCipher(this);

float [] OSCdata = new float[4]; //pitch fader, volume fader, duration Btn

void setup()
{
  size(100, 100);        // Processing screen size

  oscP5 = new OscP5(this, 8000);  // Start oscP5, listening for incoming messages at port 8000
}

void draw()
{
  background(50);

  if (OSCdata[2] == 1)
  {
    fill(0,255,0);
    ellipse(50,50,25,25); //green status button pressed ellipse
 
    sc.playNote(OSCdata[0], OSCdata[1], OSCdata[3]);
    delay(int(OSCdata[3]*1000)); //so it plays the enitre current note before next note
  }
  else
  {
    fill(255,0,0); //RED status ellipse
    ellipse(50,50,25,25);
  }
}

void oscEvent(OscMessage theOscMessage) //  This runs whenever there is a new OSC message
{
  String addr = theOscMessage.addrPattern();  //  Creates a string out of the OSC message
  float val = theOscMessage.get(0).floatValue();  //get the value

  if (addr.equals("/1/pitch"))
  {
    OSCdata[0] = val;
  }  
  if (addr.equals("/1/volume"))
  {
    OSCdata[1] = val;
  }
  if (addr.equals("/1/push1"))
  {
    OSCdata[2] = val;
  }
  if (addr.equals("/1/duration"))
  {
    OSCdata[3] = val;
  }
}


No comments:

Post a Comment