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 & Pd (Read 1486 times)
OscP5 & Pd
Jul 16th, 2009, 1:15am
 
Hello everybody...

I'm new with pd and processing and what i try to do is to read a signal table from pd and represent it in processing.

The problem is that i should receive about 3000 samples but i get something like 220 or 230. I cannot understand what i do wrong.

From pd my data are read with |tabread~|, i |snapshot~| them with a |bang~| and then i send them to processing.

Can anybody help me???  ::)


This is my code :

import oscP5.*;
import netP5.*;

OscP5 oscP5;

float dataMin, dataMax;
float plotX1, plotY1;
float plotX2, plotY2;
float labelX, labelY;

int volumeInterval = 50;
int volumeIntervalMinor = 25;

int barWidth = 5;
int barSpace = barWidth+5;

float input1, input2;

float upthreshold;
float downthreshold;

int i=0;

int timeMin, timeMax;

PFont plotFont;

void setup( )
{
 size(800, 500);
 
 i = 0;  
 dataMin = 0;
 dataMax = 500;
 
 timeMin = 0;
 timeMax = 500;
 
 upthreshold = 130;
 downthreshold = 100;

 // Corners of the plotted time series
 plotX1 = 110;
 plotX2 = width - 50;
 labelX = 40;
 
 plotY1 = 50;
 plotY2 = height - 50;
 labelY = height - 10;
 
 plotFont = createFont("SansSerif", 20);
 textFont(plotFont);
 smooth( );
 
 drawFrame();

 oscP5 = new OscP5(this,6000);
 return;
}

void draw( )
{
 drawVolumeLabels( );
 
 stroke(#5679C1);
 strokeWeight(5);
 float value =  random(500);
 
 if(i >= (plotX2-plotX1)/barSpace)
 {
   drawFrame();
   i = 0;
 }
 drawHist(value);
 return;
}

void drawHist(float val)
{
 float y = map(val, dataMin, dataMax, plotY2, plotY1);
 float d = map(downthreshold, dataMin, dataMax, plotY2, plotY1);
 float u = map(upthreshold, dataMin, dataMax, plotY2, plotY1);
 
 strokeWeight(barWidth);

 if(val <= downthreshold)
 {
   stroke(#00AA00);
   line(plotX1+i*barSpace, plotY2-2, plotX1+i*barSpace, y+2);
 }  
 else if(val <= upthreshold  && val > downthreshold)
 {
   stroke(#00AA00);
   line(plotX1+i*barSpace, plotY2-2, plotX1+i*barSpace, y+2);
   
   stroke(#AABBCC);
   line(plotX1+i*barSpace, y+2, plotX1+i*barSpace, d-2);
 }
 else if(val >= upthreshold)
 {
   stroke(#00AA00);
   line(plotX1+i*barSpace, plotY2-2, plotX1+i*barSpace, y+2);
   
   stroke(#AABBCC);
   line(plotX1+i*barSpace, y+2, plotX1+i*barSpace, d-2);    
   
   stroke(#BB0000);
   line(plotX1+i*barSpace, y+2, plotX1+i*barSpace, u-2);
 }
 return;
}

void oscEvent(OscMessage oscMess)
{
 if(oscMess.checkAddrPattern("/pd/trace/1")==true)
 {
   stroke(#00AA00);
   if(oscMess.checkTypetag("f"))
   {
     input1 = oscMess.get(0).floatValue();

     if(input1 != input2 && input1> 0)
     {
       input2 = input1;
       i++;
       println("i -> "+i+" "+input1);
     }
   }
 }
 return;
}

void drawThreshold()
{
 // gray area ~ values [45-50] mark the gray area
 stroke(#EE00FF);
 
 float y = map(upthreshold, dataMin, dataMax, plotY2, plotY1);
 line(plotX1, y, plotX2, y); // below that the voice is normal
 
 y = map(downthreshold, dataMin, dataMax, plotY2, plotY1);
 line(plotX1, y, plotX2, y); // below that the voice is normal
 return;
}

void drawFrame()
{
 background(224);
 
 // Show the plot area as a white box
 fill(255);
 rectMode(CORNERS);
 noStroke( );
 rect(plotX1, plotY1, plotX2, plotY2);
 
 drawTitle( );
 drawAxisLabels( );
 drawTimeLabels( );
 drawThreshold();
 return;
}

void drawTitle( )
{
 fill(0);
 textSize(20);
 textAlign(LEFT);
 String title = "Jitter";
 text(title, plotX1, plotY1 - 15);
 return;
}

void drawAxisLabels( )
{
 fill(0);
 textSize(13);
 textLeading(15);
 textAlign(CENTER, CENTER);

 text("Pathology\nThreshold", labelX, (plotY1+plotY2)/2);
 textAlign(CENTER);
 text("Time", (plotX1+plotX2)/2, labelY);
 return;
}

void drawTimeLabels( )
{
 fill(0);
 textSize(10);
 textAlign(CENTER, TOP);

 // Use thin, gray lines to draw the grid.
 stroke(128);
 strokeWeight(1);
 
 for (float v = dataMin; v <= dataMax; v += volumeIntervalMinor)
 {
   if (v % volumeIntervalMinor == 0)
   { // If a tick mark
     
     float y = map(v, timeMin, timeMax, plotX1, plotX2);
     if (v % volumeInterval == 0)
     { // If a major tick mark
       if (v == dataMin)
         textAlign(RIGHT); // Align by the bottom
       else if (v == dataMax)        
         textAlign(RIGHT, TOP); // Align by the top
       else
         textAlign(RIGHT, CENTER); // Center vertically
               
       text(floor(v), y+10 , plotY2 + 10);

       line( y, plotY2 - 4, y, plotY2); // Draw major tick
     }
     else
       line(y, plotY2 - 2, y, plotY2); // Draw minor tick
   }
 }
 return;
}
 
void drawVolumeLabels( )
{
 fill(0);
 textSize(10);
 stroke(128);
 strokeWeight(1);
 
 for (float v = dataMin; v <= dataMax; v += volumeIntervalMinor)
 {
   if (v % volumeIntervalMinor == 0)
   { // If a tick mark
     
     float y = map(v, dataMin, dataMax, plotY2, plotY1);
     if (v % volumeInterval == 0)
     { // If a major tick mark
       if (v == dataMin)
         textAlign(RIGHT); // Align by the bottom
       else if (v == dataMax)        
         textAlign(RIGHT, TOP); // Align by the top
       else
         textAlign(RIGHT, CENTER); // Center vertically
     
       text(floor(v), plotX1 - 10, y);
       line(plotX1 - 4, y, plotX1, y); // Draw major tick
     }
     else // Commented out; too distracting visually
       line(plotX1 - 2, y, plotX1, y); // Draw minor tick
   }
 }
 return;
}


Thank you
Re: OscP5 & Pd
Reply #1 - Jul 16th, 2009, 5:04pm
 
Hi

are you sure it's not a problem in your puredata patch? I tried to replicate the problem, but it worksforme. here's the patch I used
http://kulturserver-berlin.de/home/alvaro/osctest.pd
(File->save page as->bla.pd)
Re: OscP5 & Pd
Reply #2 - Jul 24th, 2009, 4:56am
 
So I have been trying to solve it, but still nothing.

I changed my pd patch, to send 75 values, it seems to send it fine, but the processing thread does not receive all the values....so i can't visualize my results....

it is a part of my master and i'm desperate....so if anyone has an idea what to do to synchronize the two programs....pleassssssssseeeee help!!!


i attach the code of processing and pd too... one file of processing and for pd is the _main.pd

---->>> how can i upload my code *.rar


p.s. alvaro...thanks...but i was too blond to run your patch....
Page Index Toggle Pages: 1