We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
OSCp5 Help! (Read 525 times)
OSCp5 Help!
Jan 17th, 2008, 5:35pm
 
Hey there

I am currently working on a project which uses max/msp to detect pitches and then uses the OSCp5 library in order to receive these pitches from max. The problem i am having at the moment is that i cant seem to beable to use the message sent in any way...EG i get the values into my comment box ok but when i try to implement them i cant seem to use them...im looking to beable to say //if(new value >47.8 && new value < 48.2);

Obviuosly not like that but that overall idea. I probably have made a stupid mistake somewhere but any help would be much appreciated here is my sketch:

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myBroadcastLocation;

Notes start,stop;
Notes [] n;
PImage bg;
int a;

PFont font;

void setup()
{
 size(1440,900);
 frameRate(30);
 /* start oscP5, listening for incoming messages at port 12000 */
 oscP5 = new OscP5(this,12000);
 
 /* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
  * an ip address and a port number. myRemoteLocation is used as parameter in
  * oscP5.send() when sending osc packets to another computer, device,
  * application. usage see below. for testing purposes the listening port
  * and the port of the remote location address are the same, hence you will
  * send messages back to this sketch.
  */
 myBroadcastLocation = new NetAddress("143.117.78.67",12000);

  start = new Notes(200,500);
 n = new Notes[1];
 
 // The background image must be the same size as the parameters
 // into the size() method. In this program, the size of "milan_rubbish.jpg"
 // is 200 x 200 pixels.
 bg = loadImage("LCM-SCALES.jpg");
 
 font = loadFont("Maestro-96.vlw");
 textFont(font);
 fill(300);
}

void draw()
{
 
  background(bg);
  start.draw();

}

class Notes{
float x1,y1,x2,y2;
Notes(float x, float y) {
 x1 = x;
 y1 = y;

}


void draw() {
fill(0);
  text("q",x1,y1);
  textSize(120);
}

}


/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
 /* get and print the address pattern and the typetag of the received OscMessage */
 println("### received an osc message with addrpattern "+theOscMessage.addrPattern()+" and typetag "+theOscMessage.typetag());
 theOscMessage.print();
}



thanks

matt
Re: OSCp5 Help!
Reply #1 - Jan 17th, 2008, 5:35pm
 
sorry this is the max patch-

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 463 708 153 196617 /sinusoids 60.076778;
#P newex 463 687 62 196617 prepend set;
#P comment 530 615 345 196617 create a list of all the analysis data;
#P comment 476 593 345 196617 take away the index as we won't need that in processing;
#P comment 556 634 190 196617 osc is about creating addresses like this;
#P newex 463 632 95 196617 prepend /sinusoids;
#P newex 185 664 126 196617 udpsend 127.0.0.1 12000;
#P comment 315 667 345 196617 udpsend sends any messages received to the Port at the given IP address;
#P newex 505 119 29 196617 mtof;
#P user ezdac~ 411 203 455 236 0;
#P newex 191 82 48 196617 loadbang;
#P message 191 103 37 196617 loop 1;
#P comment 312 97 163 196617 b) start or stop playback;
#P comment 317 61 163 196617 a) open a sound file \, AIFF or WAV;
#P toggle 289 96 15 0;
#P message 271 60 43 196617 open \, 1;
#P comment 314 132 143 196617 best working in Mono for now;
#N sfplay~  2 120960 0 ;
#P newobj 256 129 53 196617 sfplay~ 2;
#P user panel 267 53 211 29;
#X brgb 255 255 255;
#X frgb 100 202 30;
#X border 2;
#X rounded 0;
#X shadow 0;
#X done;
#P user panel 268 88 211 29;
#X brgb 255 255 255;
#X frgb 100 202 30;
#X border 2;
#X rounded 0;
#X shadow 0;
#X done;
#P message 261 240 35 196617 auto 1;
#P message 225 240 35 196617 auto 0;
#P message 224 218 30 196617 print;
#P message 225 178 52 196617 npartial 7;
#P flonum 280 470 78 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 288 432 29 196617 mtof;
#P window linecount 0;
#P newex 228 279 16 196617;
#B color 5;
#P window linecount 1;
#P comment 143 408 71 196617 Print attack •;
#P toggle 214 406 15 0;
#P newex 214 445 55 196617 print pitch;
#P newex 214 425 27 196617 gate;
#P newex 216 487 27 196617 gate;
#P newex 216 507 61 196617 print attack;
#P toggle 216 468 15 0;
#P comment 145 470 71 196617 Print attack •;
#P flonum 611 494 62 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 529 494 76 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 611 450 62 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 529 450 76 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 611 407 62 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 529 407 76 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 315 454 84 196617 (up to 3 outputs);
#P flonum 437 405 72 9 0 0 32 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 358 406 72 9 0 0 32 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 280 406 72 9 0 0 32 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 529 472 64 196617 unpack 0. 0.;
#P newex 529 428 64 196617 unpack 0. 0.;
#P newex 529 386 64 196617 unpack 0. 0.;
#P newex 529 360 73 196617 route 1 2 3;
#P newex 280 354 61 196617 unpack 0. 0.;
#P newex 231 326 266 196617 fiddle~ 1024 1 20 3;
#B color 5;
#P window linecount 2;
#P comment 316 427 83 196617 raw pitch and amplitude;
#P comment 437 427 49 196617 amplitude (dB);
#P window linecount 1;
#P comment 527 516 153 196617 individual sinusoidal components;
#P comment 100 209 79 196617 • output volume;
#P newex 52 171 50 196617 send~ sig;
#B color 5;
#P flonum 64 207 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 35 225 39 196617 *~ 0.;
#B color 5;
#P newex 36 250 29 196617 dac~;
#B color 5;
#P newex 21 150 27 196617 *~;
#B color 5;
#P comment 38 191 125 196617 • click here to start DSP.;
#P toggle 22 190 15 0;
#P connect 44 1 11 0;
#P connect 44 1 52 1;
#P connect 44 0 11 0;
#P connect 44 0 52 0;
#P connect 31 0 32 0;
#P connect 31 0 56 0;
#P connect 16 1 26 0;
#P connect 15 1 24 0;
#P connect 14 1 22 0;
#P connect 16 0 25 0;
#P fasten 13 2 16 0 576 382 526 382 526 468 534 468;
#P connect 15 0 23 0;
#P fasten 13 1 15 0 555 379 520 379 520 424 534 424;
#P connect 14 0 21 0;
#P connect 13 0 14 0;
#P connect 11 4 13 0;
#P connect 60 0 61 0;
#P fasten 56 0 55 0 468 651 190 651;
#P connect 56 0 60 0;
#P connect 11 3 19 0;
#P fasten 12 1 18 0 336 379 363 379;
#P connect 17 0 36 0;
#P connect 36 0 37 0;
#P connect 12 0 17 0;
#P fasten 11 2 12 0 364 349 285 349;
#P fasten 50 0 44 0 196 126 261 126;
#P fasten 46 0 44 0 276 83 261 83;
#P fasten 47 0 44 0 294 120 261 120;
#P fasten 11 1 30 1 300 345 272 345 272 479 238 479;
#P connect 11 0 31 1;
#P connect 30 0 29 0;
#P connect 28 0 30 0;
#P connect 33 0 31 0;
#P connect 51 0 50 0;
#P connect 5 0 4 1;
#P connect 4 0 3 0;
#P connect 4 0 3 1;
#P fasten 2 0 4 0 26 171 40 171;
#P connect 2 0 6 0;
#P fasten 0 0 3 0 27 244 41 244;
#P window clipboard copycount 62;

thanks
Re: OSCp5 Help!
Reply #2 - Jan 18th, 2008, 4:17pm
 
assuming your address pattern is /sinusoids and it has one float as argument (reading from your max patch), then you could do the following:

(1) in oscEvent()
Code:

void oscEvent(OscMessage theOscMessage) {
if(theOscMessage.checkAddrPattern("/sinusoids")==true) {
float f = theOscMessage.get(0).floatValue();
if(f>47.8 && f< 48.2) {
// do something.
}
}
}


(2) or you can use oscP5.plug()
in setup() after you have created oscP5, add
Code:

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

then add the following function to your code
Code:

public void sinusoids(float theValue) {
if(theValue>47.8 && theValue< 48.2) {
// do soemthing.
}
}


you can also check the examples oscPlug or oscParsing
best,
andi
Page Index Toggle Pages: 1