oscP5 parse to float trouble

hello everyone! I'm trying to get a data (named "media") from my Raspberry PI to my Android phone using processing so I' ve decided to use oscP5 lybrary. I've successfully connected them (the android sketch receives that data) but I just can't manage to parse it into float format from the oscMessage format. Could someone explain me how should I do? This is the sketch. thank you

import g4p_controls.*; import processing.sound.*; import oscP5.*; import netP5.*;

int screenX=900; int screenY=600;

int letture,xInterfaccia=0,y,limit; float somma,media,oldMedia=500; boolean mediaAvailable;

OscP5 osc; NetAddress addr; SoundFile file;

void setup(){ size(900,600); background(150,0,0); while(y<screenY){ stroke(0); line(0,y,screenX,y); fill(255); textSize(11); text(int(1000-map(y,0,screenY,0,1000)),screenX-40,y); y=y+50; } y=0; osc = new OscP5(this, 12345); addr = new NetAddress("192.168.1.24",12345); // file = new SoundFile(this, "alarm.mp3"); }

void draw(){ //I've posted even the draw but it doesn't matte, it works fine. i get some troubles with oscEvent()

if(xInterfaccia>screenX-35){ //ripristino schermata una volta terminata saveFrame("SQM-##.png"); background(150,0,0); while(y<screenY){ stroke(0); line(0,y,screenX,y); fill(255); textSize(11); text(int(1000-map(y,0,screenY,0,1000)),screenX-40,y); y=y+50; } xInterfaccia=0; y=0; }

 if(mediaAvailable) {
    println(media);
    fill(0);                                      //disegna grafico
    if(oldMedia>media){
      triangle(xInterfaccia,screenY-oldMedia,xInterfaccia,screenY-media,xInterfaccia+10,screenY-media);
      rect(xInterfaccia,screenY,10,-int(media));
    }
    else if(oldMedia<media){
      triangle(xInterfaccia,screenY-oldMedia,xInterfaccia+10,screenY-oldMedia,xInterfaccia+10,screenY-media);
      rect(xInterfaccia,screenY,10,-int(oldMedia));
    }
    else
      rect(xInterfaccia,screenY,10,-int(oldMedia));

    oldMedia=media;
    fill(255);
    rotate(-PI/2);
    translate(-screenY,xInterfaccia+9);
    fill(255);
    textSize(9);
    text(hour()+":"+minute()+"   "+nf(map(media,0,screenY,0,1000),3,2),0,0);
    xInterfaccia+=10;
    rotate(PI/2);
    translate(screenY,-xInterfaccia-9);
    if(media>screenY-limit){
      file.play();
    }
    mediaAvailable=false;

} }

void oscEvent(OscMessage theMessage) { mediaAvailable=true; }

Answers

  • Format your code properly. Edit your post, select text and hit ctrl+o. Ensure there is an empty line above and below your code block.

    Regarding your question, where are you retrieving your float value from your OSC message? Have you check the examples provided? Also

    I'm trying to get a data (named "media")

    is your data a float value? Or what is the nature of your media variable?

    Kf

Sign In or Register to comment.