Loading...
Logo
Processing Forum
i am sending message to processing from supercollider

n=NetAddr("127.0.0.1", 12000);
n.sendMsg("/sc1",10, "line", [200.0,0.1].choose);
and both variables in processing stretch and moveX is reacting to it

what i don't get is how do you make say

n.sendMsg("/stretch",10, "line", [200.0,0.1].choose);
and make only variable stretch react to this message
n.sendMsg("/moveX",10, "line", 400.0.rand);
and make only variable moveX react to this message

in other words how do one links the messages from sc and variables in processing?

here's my processing example http://pastebin.com/AjBE6zuk

can somebody please help?
thank you
best, k.

Replies(6)

Like this:

  1. void oscEvent(OscMessage theOscMessage) {
  2.  if (theOscMessage.checkAddrPattern("/stretch") == true) {
          stretch= theOscMessage.get(2).floatValue();
    }else if (theOscMessage.checkAddrPattern("/movex") == true){
          moveX= theOscMessage.get(2).floatValue();
    }
  3.  
  4. }
thank you!
but how to deal with arrays and use its values with variables?

//like this i can send array from SC
~message = ["/thing"] ++ ({200.0.rand} ! 10);
n=NetAddr("127.0.0.1", 12000);
n.sendMsg( *~message);

//also someone suggested to send the array as a string, and then parse it in P5
n.sendMsg("/thing", ({100.rand} ! 10).asString);

can you please show example with arrays if possible?
best,k
It would be the same.  Here is the typetag processing received when I sent your message from supercollider:

typetag: ffffffffff

10 random floats, right?

So, for example: 
theOscMessage.get(2).floatValue();

Would retrieve the value at index 2 of the array you sent from supercollider.
just got time to try your example and unfortunately i got error
is there some mistakes?

//sc code
n=NetAddr("127.0.0.1", 12000);
n.sendMsg("/stretch",200.0.rand,200.0.rand)

//p5 code
import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

float stretch, moveX;
void setup() {
  size(400,400);
  oscP5 = new OscP5(this,12000);
 
  myRemoteLocation = new NetAddress("127.0.0.1",12000);
}

    void draw() {
  background(255); 
  rect(width/2,height/2,stretch, stretch);
}


    void oscEvent(OscMessage theOscMessage) {

     if (theOscMessage.checkAddrPattern("/stretch") == true) {
          stretch= theOscMessage.get(2).floatValue();
    }else if (theOscMessage.checkAddrPattern("/movex") == true){
          moveX= theOscMessage.get(2).floatValue();
    }
    
    }
   

In your SC code:

n=NetAddr("127.0.0.1", 12000);
n.sendMsg("/stretch",200.0.rand,200.0.rand)

you are only attaching 2 things to your osc message (2 random numbers), which will be at index 0 and 1.

in processing:

 stretch= theOscMessage.get(2).floatValue();

you are asking for the value at index 2, which is giving you the null pointer error.  I think what you're trying to do is something like this, right?

Copy code
  1. import oscP5.*;
  2. import netP5.*;

  3. OscP5 oscP5;
  4. NetAddress myRemoteLocation;

  5. float stretchWidth, stretchHeight, moveX;
  6. void setup() {
  7.   size(400,400);
  8.   oscP5 = new OscP5(this,12000);
  9.   
  10.   myRemoteLocation = new NetAddress("127.0.0.1",12000);
  11. }

  12.     void draw() {
  13.   background(255);  
  14.   rect(width/2,height/2,stretchWidth, stretchHeight);
  15. }


  16.     void oscEvent(OscMessage theOscMessage) {

  17.      if (theOscMessage.checkAddrPattern("/stretch") == true) {
  18.           stretchWidth = theOscMessage.get(0).floatValue();
  19.           stretchHeight = theOscMessage.get(1).floatValue();
  20.     }else if (theOscMessage.checkAddrPattern("/movex") == true){
  21.           moveX= theOscMessage.get(0).floatValue();
  22.     }
  23.      
  24.     }
  25.     

hi, i want to trigger 2 rectangles in p5 with this simple phasing pattern in sc by
introducing slight wait time differences between  2 Tdefs

but something's wrong, there seems to be sync problems
and when i set both wait times to same value, only one rectangle is triggered
not both as i suspected
feels like messages can't be delivered at the same time or there is something else...
any ideas what seems to be he problem?


// sc code
n=NetAddr("127.0.0.1", 12000);
(
Ndef(saw,{|t_trig=0|0.1*Saw.ar*EnvGen.kr(Env.perc(0.01,0.3),t_trig)}).play;


Tdef(x
        var toggle = [1, 0].iter.loop;
inf.do{|i|
if(i%4==0,{n.sendMsg("/rekt",toggle.next);
Ndef(saw).set( _trig,1);
});
(0.04).wait;}}).play;



Tdef(x{
         var toggle= [2, 0].iter.loop;
inf.do{|i|
if(i%4==0,{n.sendMsg("/rekt",toggle.next);
Ndef(saw).set( _trig,1);
});
(0.0408).wait;}}).play;
)

//p5 code

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;
int switcher;
void setup() {
  size(400,400);
  oscP5 = new OscP5(this,12000);

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

  oscP5.plug(this,"rekt","/rekt");

}


void rekt(int theA) {

  switcher= theA;
}

void right(){
fill(0);
rect(200,0,200,200);
}

void left(){
fill(0);
rect(0,0,200,200);
}

void draw() {
  background(255);
 
  if(switcher==1){
  right();
} else if (switcher==2){
left();
}

}