Maipn
YaBB Newbies
Offline
Posts: 2
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