Osc Messages from Processing to SuperCollider

HI!

How can I send two Osc Messages from Processing to SuperCollider?

So far I have only managed to connect one sound, but but I’m missing two more sounds.

How can I do that?

In void draw() I need to have two/three “/test” sounds.
I had to use booleans to start and stop the sound based on what happens to the graphic part in Processing.

This is my code of oscP5 in Processing:

import netP5.*;
import oscP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;

void setup () {
  oscP5 = new OscP5(this,57120);
  myRemoteLocation = new NetAddress("127.0.0.1",57120);
}

void draw() {

  OscMessage myMessage = new OscMessage("/test");
 
  myMessage.add(Impulse);

  /* invio messaggio */
  oscP5.send(myMessage,myRemoteLocation);

}
1 Like

Hi Alexx !

You have several options to send multiple OSC Messages.

  • Create your messages with different names (I prefer doing this so I can choose a clear name for each message)
  • Create one message with multiple values inside
import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

void setup() {
  size(400, 400);
  frameRate(25);
  oscP5 = new OscP5(this, 12000);

  myRemoteLocation = new NetAddress("127.0.0.1", 12000);
}


void draw() {
  background(0);
}

void mousePressed() {
  /* in the following different ways of creating osc messages are shown by example */
  OscMessage myMessage1 = new OscMessage("/synth/filter");
  OscMessage myMessage2 = new OscMessage("/synth/resonance");

  OscMessage myMessage3 = new OscMessage("/synth");


  myMessage1.add(123); 
  myMessage2.add(456); 

  myMessage3.add(123);
  myMessage3.add(456);

  /* send the message */
  oscP5.send(myMessage1, myRemoteLocation);
  oscP5.send(myMessage2, myRemoteLocation);
  oscP5.send(myMessage3, myRemoteLocation);
}


/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
  /* print the address pattern and the typetag of the received OscMessage */
  print("### received an osc message.");
  print(" addrpattern: "+theOscMessage.addrPattern());
  println(" typetag: "+theOscMessage.typetag());
  if (theOscMessage.checkTypetag("i")) {
    println(" typetag: "+theOscMessage.get(0).intValue());
  }
  if (theOscMessage.checkTypetag("ii")) {
    println(" First value : "+theOscMessage.get(0).intValue());
    println(" Second Value : "+theOscMessage.get(1).intValue());
  }
}

Cheers,
Geoffroy

2 Likes

Hi Geo_Pi!

My sound start and stop when two different graphic part start and stop in different time.
I need that Osc Messages is in the draw not in mouse Pressed, and when I add “OscMessage myMessage2 = new OscMessage(”/synth/resonance");" the program gives me error.
In the end I need to have two different sound for two different graphic part in two different time that I just give.

I don’t know if it’s understandable …

This is my code:

import netP5.*;
import oscP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;

PImage bg;

int a=1192; //sketch size
float s=20; //lunghezza linea
float x, y; //inizio linea
boolean Impulse= false;

float Time;
int restart = 0;

void settings() {
  size(1192,746);}

void setup() {
  
  frameRate(20);
  
  oscP5 = new OscP5(this,57120);
  myRemoteLocation = new NetAddress("127.0.0.1",57120);}

void draw() {

 bg = loadImage("Amazzonia.jpg");
  image(bg, 0, 0, width, height);
  //background(0);
  
  float sec = map(frameCount, 0, 60*60, 0,  TWO_PI);
  println(sec);
  
  pushMatrix();
  if (sec >= random(0.1,0.3)){
    Impulse = true;
  
  for (int i=0;i<=0.5*a;i++) {
      stroke(random(255,0));
      x = random(0,a);
      y = random(0,a);
      line(x,y,x+random(0,s),y);
  }

if (sec >= random(0.14,0.18)){
    
    
  int numberOfColumns = (int) random(1, 20);
  int numberOfRectsPerColumn = (int) random(1,(random(100,190)));
 
  for(int i = 1; i<=numberOfColumns; i++){
    int x1 = width/numberOfColumns * (i-1);
    int x2 = width/numberOfColumns;
    new Column(x1, x2, (int)random(height/10), numberOfRectsPerColumn).display();
  }
}

if (sec >= random(0.3,0.35)){
   Impulse=false;
  clear();
  image(bg, 0, 0, width, height);
  }

if (sec >= random(0.4,0.45))
  frameCount=0;

OscMessage myMessage = new OscMessage("/test");
 
  myMessage.add(Impulse);

  /* invio messaggio */
  oscP5.send(myMessage,myRemoteLocation); 

  popMatrix();
  
}

class Column {
  int x;
  int rectWidth;
  int rectHeight;
  int numberOfrects;
  
  Column(int x, int rectWidth, int rectHeight, int numberOfrects) {
    this.x = x;
    this.rectWidth = rectWidth;
    this.rectHeight = rectHeight;
    this.numberOfrects = numberOfrects;
  }
  
   void display(){
    for (int i=0; i<numberOfrects; i++) {
      fill(random(0, 0), 0, random(0, 0));
      rect(x, random(height), rectWidth, rectHeight);
    }  
    
    for (int i=0; i<numberOfrects; i++) {
      fill(random(255, 0), 255, random(255, 0));
      rect(x, random(height), rectWidth, rectHeight);
    } 
    
  }
}
1 Like

What error are you having?

Thank you @Geo_Pi !! :grin:

Did you figure it out? Cool !

1 Like