Quantcast
Channel: Processing Forum
Viewing all 1768 articles
Browse latest View live

unable to set file path with minim.loadFile()

$
0
0
Minim minim.loadFile() doesn't work in my processing sketch when I specify a file path.  I've included the sketch that refuses to run, I get unexpected char 'p' as an error.  The sketch runs when I use the default path with minim.loadFile(). I don't know if this is a known problem as I haven't found the bug list for minim.







import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;

/**
  * This sketch demonstrates the difference between linearly spaced averages and logarithmically spaced averages 
  * (averages that are grouped by octave). It also draw the full spectrum so you can see how each set of averages 
  * compares to it.
  * <p>
  * From top to bottom:
  * <ul>
  *  <li>The full spectrum.</li>
  *  <li>The spectrum grouped into 30 linearly spaced averages.</li>
  *  <li>The spectrum grouped logarithmically into 10 octaves, each split into 3 bands.</li>
  * </ul>
  * 
  */

import ddf.minim.analysis.*;
import ddf.minim.*;

Minim minim;  
AudioPlayer jingle;
FFT fftLin;
FFT fftLog;
float height3;
float height23;

void setup()
{
  size(512, 300);
  height3 = height/3;
  height23 = 2*height/3;

  minim = new Minim(this);
  jingle = minim.loadFile("C:\processing sketch book\audio_file\data\jingle.mp3",2048);
  //jingle = minim.loadFile("jingle.mp3", 2048);
  // loop the file
  jingle.loop();
  // create an FFT object that has a time-domain buffer the same size as jingle's sample buffer
  // note that this needs to be a power of two 
  // and that it means the size of the spectrum will be 1024. 
  // see the online tutorial for more info.
  fftLin = new FFT(jingle.bufferSize(), jingle.sampleRate());
  // calculate the averages by grouping frequency bands linearly. use 30 averages.
  fftLin.linAverages(30);
  fftLog = new FFT(jingle.bufferSize(), jingle.sampleRate());
  // calculate averages based on a miminum octave width of 22 Hz
  // split each octave into three bands
  // this should result in 30 averages
  fftLog.logAverages(22, 3);
  rectMode(CORNERS);
}

void draw()
{
  background(0);
  // perform a forward FFT on the samples in jingle's mix buffer
  // note that if jingle were a MONO file, this would be the same as using jingle.left or jingle.right
  fftLin.forward(jingle.mix);
  
  stroke(255);
  noFill();
  // draw the full spectrum
  for(int i = 0; i < fftLin.specSize(); i++)
  {
    line(i, height3, i, height3 - fftLin.getBand(i)*2);
  }
  
  noStroke();
  fill(255);
  // draw the linear averages
  int w = int(width/fftLin.avgSize());
  for(int i = 0; i < fftLin.avgSize(); i++)
  {
    // draw a rectangle for each average, multiply the value by 5 so we can see it better
    rect(i*w, height23, i*w + w, height23 - fftLin.getAvg(i)*5);
  }
  
  // draw the logarithmic averages
  fftLog.forward(jingle.mix);
  w = int(width/fftLog.avgSize());
  for(int i = 0; i < fftLog.avgSize(); i++)
  {
    // draw a rectangle for each average, multiply the value by 5 so we can see it better
    rect(i*w, height, i*w + w, height - fftLog.getAvg(i));
  }
}

void stop()
{
  // always close Minim audio classes when you are done with them
  jingle.close();
  // always stop Minim before exiting
  minim.stop();
  
  super.stop();
}



Trying to make a thread sleep (minim)

$
0
0
Hello everyone!
Im quite new to Processing, and im currently experimenting with the minim lib.
The issue is that i want to load the audi files into an array and play them one after one. But the audio was playing all at once.
At the moment im trying to make the thread sleep but without any luck ("Unhandled exception type Interrupted Exception").

Any suggestion on what i could do?

  1. import ddf.minim.*; //Minim library
  2. import ddf.minim.analysis.*;

  3. Minim minim; 
  4. AudioPlayer player[]; //Player array

  5. //-----------------------------------------------------------------------------------
  6.  
  7. void setup() {

  8.   minim = new Minim(this); 
  9.   player = new AudioPlayer[8]; //setup Array
  10.   int i = 1;

  11.     //Getting the Audio     
  12.    while(i<8){
  13.     player[i] = minim.loadFile(i + ".mp3");
  14.   
  15.   player[i].play();
  16.   
  17.   //Trying to stop it
  18.   while(player[i].isPlaying()){
  19.   
  20.     Thread.sleep(player[i].length());
  21.    } 
  22.     i++;
  23.   }

  24.   } 
  25. //---------------------------------------------------------------------------------------
  26.     

Re : unable to set file path with minim.loadFile()

$
0
0
Try using forward slashes:

jingle = minim.loadFile("C:/processing sketch book/audio_file/data/jingle.mp3",2048);

need help with debugging

$
0
0
 I want is for the still images to run independently through the display code, then when the sensor is triggered the live camera feed will overlap the still images at various transparency based on the sensor reading.

Right now the still images run in the background but are not visible until the sensor range is tripped. The camera feed performs as desired until you are out of range then the camera feed never turns off. Also the camera feed flickers constantly. I am using a basic logitech webcam.


I appreciate any help you can provide.

Cheers,
Allison

int imgCount= 9;
PImage [] imgs = new PImage[imgCount];
float imgW;
float offset = 0;
float easing = 0.05; //using sensor value distance to change its position. this program overlays one image over another by modifying the alpha value of the image with the tint() function.

int currentImage=0;
int lastShown=0;
int interval=3000; // each slide shows for this many millis
int blendedInterval=9000;

//keep track of loaded images (true or false)
boolean[] loadStates = new boolean [imgCount];

// for loading images
float loaderX, loaderY, theta;

import processing.video.*;
import processing.serial.*;


Capture video;
int count;
int writeRow;
int maxRows;
int topRow;
int buffer[];

//int rangeAnalogPin= 0; //rangefinder

boolean showLiveVideo=false;
Serial serialPort;
int rangeVal=255;

void setup() {
  size (displayWidth, displayHeight, P3D);
  background(0);
  smooth();
  imgW= width/imgCount;
  // load images asynchronously
  for (int i = 0; i < imgCount; i++) {
    imgs[i] = requestImage("warhol_img"+nf(
i, 4)+".jpg");
  }

  // Setup VIDEO Capture

  String[] cameras = Capture.list();

  //if (cameras.length == 0) {
  // println("There are no cameras available for capture.");
  // exit();

  //else {
  //  println("Available cameras:");
  //  for (int i = 0; i < cameras.length; i++) {
  //  println(i+" "+cameras[i]);



  //video = new Capture(this, 640, 480);
  video = new Capture(this, cameras[9]);

  video.start();

  maxRows = height *2;
  buffer = new int[width * maxRows];
  writeRow = height - 1;
  topRow = 0;

  //frameRate(10);
  background(0);
  loadPixels();

  // Setup SERIAL PORT
  println(Serial.list());

  String portName = Serial.list()[0];
  serialPort = new Serial(this, portName, 9600);
}




void draw() {
  // check for new range finder data
  while ( serialPort.available () > 0) {  // If data is available,
    rangeVal = serialPort.read();         // read it and store it in val
    //println(rangeVal);
  }

  // draw pollock image
  background(0);
  //tint(255, 255);
  //image(img, 0, 0, displayWidth, displayHeight);
  for (int i = 0; i < imgs.length; i++) {
    // Check if individual images are fully loaded
    if ((imgs[i].width != 0) && (imgs[i].width != -1)) {
      // As images are loaded set true in boolean array
      loadStates[i] = true;
    }
  }
  if (checkLoadStates()) {
    // all the images are loaded
    if (currentImage<imgCount) {
      // we are in the first set of single images
      drawNextImage();
      if (millis()-lastShown>interval) {
        currentImage=currentImage+1;
        lastShown=millis();
      }
    }
    else {
      // we are drawing the blendef image
      drawBlendedImages();

      if (millis()-lastShown>blendedInterval) {
        // if we've shown the blended image for long enough
        // reset the whole system
        currentImage=0; // start at first image;
        lastShown=millis(); // reset the timer
        tint(255);
      }
    }
  }
  // draw video image
  tint(255, rangeVal);  // display at half opacity
  image(video, 0, 0, displayWidth, displayHeight);
}

void drawNextImage() {
  int y = (height - imgs[0].height) / 2;
  image(imgs[currentImage], 0, y, imgs[currentImage].height, imgs[currentImage].height);
}

void drawBlendedImages() {
  int y = (height - imgs[0].height) / 2;
  for (int i = 0; i < imgs.length; i++) {
    //image(imgs[i], width/imgs.length*i, y, imgs[i].height, imgs[i].height);
    tint(255, 128);
    image(imgs[i], 0, y, imgs[i].height, imgs[i].height);
  }
}

// Loading animation
void runLoaderAni() {
  // Only run when images are loading
  if (!checkLoadStates()) {
    ellipse(loaderX, loaderY, 10, 10);
    loaderX += 2;
    loaderY = height/2 + sin(theta) * (height/8);
    theta += PI/22;
    // Reposition ellipse if it goes off the screen
    if (loaderX > width + 5) {
      loaderX = -5;
    }
  }
}

// Return true when all images are loaded - no false values left in array
boolean checkLoadStates() {
  for (int i = 0; i < imgs.length; i++) {
    if (loadStates[i] == false) {
      return false;
    }
  }
  return true;
}

void captureEvent(Capture c) {
  c.read();
}

Re : need help with debugging

$
0
0

Also the camera feed flickers constantly
It may help to use a buffer.
  1. PImage videoBuffer;

  2. void draw(){
  3.       if(video.available()){
  4.             video.read();
  5.             videoBuffer = video;
  6.       }
  7.       if(videoBuffer != null){
  8.             image(videoBuffer, 0, 0);
  9.       }
  10. }


Re : unable to set file path with minim.loadFile()

$
0
0
Thanks for replying so fast to my question.  You're right the forward slashes are needed in the file path.  Should this be considered a bug or are the forward slashes needed for compatibility across different platforms (windows, linux, mac)?


Thanks again
wpkelley1

Re : unable to set file path with minim.loadFile()

Re : Trying to make a thread sleep (minim)

$
0
0
Some remarks:
- Thread.sleep() is probably not the proper solution;
- The Processing function delay() does the same thing...
- See the What is an exception? article in the Technical FAQ.


Re : need help with debugging

$
0
0
I added the buffer but still getting the same flickering issue. Also the video is not supposed to start until the value within the sensor range is met but the camera is always on.

here is my processing code with the buffer and another tweak.
int imgCount= 12;
PImage [] imgs = new PImage[imgCount];
float imgW;
float offset = 0;
float easing = 0.05; //using sensor value distance to change its position. this program overlays one image over another by modifying the alpha value of the image with the tint() function.

int currentImage=0;
int lastShown=0;
int interval=3000; // each slide shows for this many millis
int blendedInterval=9000;

int lastRangeReading = 0;
int videoResetInterval=1000; // if we haven't gotten any close range values for a second, reset video transparency

//keep track of loaded images (true or false)
boolean[] loadStates = new boolean [imgCount];

// for loading images
float loaderX, loaderY, theta;

import processing.video.*;
import processing.serial.*;


Capture video;
int count;
int writeRow;
int maxRows;
int topRow;
int buffer[];

boolean showLiveVideo=false;
Serial serialPort;
int rangeVal=255;

PImage videoBuffer;

void setup() {
  size (480, 640, P3D);
  background(0);
  smooth();
  imgW= width/imgCount;
  // load images asynchronously
  for (int i = 0; i < imgCount; i++) {
    imgs[i] = requestImage("warhol_img"+nf(i, 4)+".jpg");
  }

  // Setup VIDEO Capture

  String[] cameras = Capture.list();

  //video = new Capture(this, 640, 480);
  video = new Capture(this, cameras[9]);

  video.start();

  maxRows = height *2;
  buffer = new int[width * maxRows];
  writeRow = height - 1;
  topRow = 0;

  frameRate(10);
  background(0);
  loadPixels();

  // Setup SERIAL PORT
  println(Serial.list());

  String portName = Serial.list()[0];
  serialPort = new Serial(this, portName, 9600);
}

void draw()
{
  if (video.available()) {
    video.read();
    videoBuffer=video;
  }
  if (videoBuffer !=null) {
    image(videoBuffer, 0, 0);
  }
  // check for new range finder data
  while ( serialPort.available () > 0) {  // If data is available,
    rangeVal = serialPort.read();         // read it and store it in val
       lastRangeReading=millis();
    //println(rangeVal);
  }
if(millis()-lastRangeReading >videoResetInterval) {
    lastRangeReading =millis();
    rangeVal=255; // make video completely transparent   
 }


  // draw pollock image
  background(0);
  //tint(255, 255);
  //image(img, 0, 0, displayWidth, displayHeight);
  for (int i = 0; i < imgs.length; i++) {
    // Check if individual images are fully loaded
    if ((imgs[i].width != 0) && (imgs[i].width != -1)) {
      // As images are loaded set true in boolean array
      loadStates[i] = true;
    }
  }
  if (checkLoadStates()) {
    // all the images are loaded
    if (currentImage<imgCount) {
      // we are in the first set of single images
      drawNextImage();
      if (millis()-lastShown>interval) {
        currentImage=currentImage+1;
        lastShown=millis();
      }
    }
    else {
      // we are drawing the blendef image
      drawBlendedImages();

      if (millis()-lastShown>blendedInterval) {
        // if we've shown the blended image for long enough
        // reset the whole system
        currentImage=0; // start at first image;
        lastShown=millis(); // reset the timer
        tint(255);
      }
    }
  }
  // draw video image
  tint(255, rangeVal);  // display at half opacity
  image(video, 0, 0, 480, 640);
}

void drawNextImage() {
  int y = (height - imgs[0].height) / 2;
  image(imgs[currentImage], 0, y, imgs[currentImage].height, imgs[currentImage].height);
}

void drawBlendedImages() {
  int y = (height - imgs[0].height) / 2;
  for (int i = 0; i < imgs.length; i++) {
    //image(imgs[i], width/imgs.length*i, y, imgs[i].height, imgs[i].height);
    tint(255, 128);
    image(imgs[i], 0, y, imgs[i].height, imgs[i].height);
  }
}

// Loading animation
void runLoaderAni() {
  // Only run when images are loading
  if (!checkLoadStates()) {
    ellipse(loaderX, loaderY, 10, 10);
    loaderX += 2;
    loaderY = height/2 + sin(theta) * (height/8);
    theta += PI/22;
    // Reposition ellipse if it goes off the screen
    if (loaderX > width + 5) {
      loaderX = -5;
    }
  }
}

// Return true when all images are loaded - no false values left in array
boolean checkLoadStates() {
  for (int i = 0; i < imgs.length; i++) {
    if (loadStates[i] == false) {
      return false;
    }
  }
  return true;
}

void captureEvent(Capture c) {



  c.read();
}


here is my arduino code
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  //Serial.println(sensorValue);
  //Serial.println(map(sensorValue, 0, 545, 0, 255));
  Serial.write(map(sensorValue, 20, 225, 0, 255));
 
  // send sensor value as number between 0 - 255
  //Serial.write(sensorValue/4);
  delay(50);        // delay in between reads for stability
}

OpenGL: beginGL() does not exist

$
0
0
Dear All,

I've stumbled on this yesterday evening: "The function beginGL() does not exist.", while trying to switch a sketch from 1.5.1 to 2.0b6 (tried it now with 2.0b7, still doesn't work). 

Minimal sketch reproducing this would be found here: http://wiki.processing.org/w/Advanced_OpenGL, and the fault lies somewhere in 
  1. PGraphicsOpenGL pgl = (PGraphicsOpenGL) g; // g may change GL gl = pgl.beginGL(); // always use the GL object returned by beginGL

I am just a happily hacking noob, tried to browse through the code and issue tracker, still no clues as to what/why/where.  

I dearly hope this is not machine specific, but just in case, I am running win7 64, with an nvidia quadro inside. 

Cheers,
D.

Re : OpenGL: beginGL() does not exist

$
0
0
This was changed to beginPGL(), which you can then grab the gl object from.

Re : Event handling in Processing 2.0b7

Re : Using 2.0b7 P3D with contributed libraries

$
0
0
I fixed the bug in PeasyCam.
Topic here
The problem was the MouseEvent class.

Re : Using 2.0b7 P3D with contributed libraries

$
0
0

I think this may be a problem with java.awt.event.MouseEvent vs. processing.event.MouseEvent!?
Makes sense and you proved it by fixing PeasyCam good job.

Osculator and Processing

$
0
0
Hello,

I am currently starting a project which includes the use of Processing and Osculator.

I intend to use a wiimote to control a video that would be displayed through Processing. The A button would play and pause the video. B button would take a screenshot. And rolling the wiimote left and right would rewind and fast forward the video.

If this becomes relatively straightforward I would implement more than one video into processing and a display would appear with a homepage that would allow you to choose the video to play with the wiimote.

I have never used Osculator and don't have a clue where to start with a project like this. So far I have imported the Osculator library into Processing.

Can anyone offer their advice on how complicated and ambitious my idea is, and if anyone could help me get started I would very much appreciate it.

Thank you.

Re : OpenGL: beginGL() does not exist

$
0
0
Hey! Thanks for your answer. I'm still stumbling along...
So this 
  1.   PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;  
  2.   GL gl = pgl.beginGL();  
Becomes this:
  1.   PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;  
  2.   PGL gl = pgl.beginPGL();  
But then I get errors like "glColor4f(...) does not exist. Bummer :(

(just for reference, i am using the simple example from the wiki). 

Re : OpenGL: beginGL() does not exist

$
0
0
Not exactly. This:

  1. PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;  
  2. GL gl = pgl.beginGL();  
         
Becomes this:

  1. GL gl = g.beginPGL().gl
Also, at the top of that wiki it says "This post is for Processing 1.x, it doesn't apply to Processing 2.x". A lot was changed for Processing 2.0, including coloring/vector definition. Check out this post by Andres on the changes regarding immediate vs. retained drawing modes.
      

Re : Using 2.0b7 P3D with contributed libraries

$
0
0
It appears that this problem was reported as an issue but unfortunately I only scanned the outstanding issues so missed it because it had been closed (issue 1437)

It seems to me that this is going to be an ongoing problem for a while until the library authors find time to modify their code to handle the new Proccessng event model.

Looking at the source code it appears that the processing.Event class has an attribute:-
  1. protected Object nativeObject;

and the method getNative to retrieve it.

  1. /**
  2. * Get the platform-native event object. This might be the java.awt event
  3. * on the desktop, though if you're using OpenGL on the desktop it'll be a
  4. * NEWT event that JOGL uses. Android events are something else altogether.
  5. * Bottom line, use this only if you know what you're doing, and don't make
  6. * assumptions about the class type.
  7. */
  8. public Object getNative() {
  9.       return nativeObject;
  10. }

Currently the G4P library uses the registerMouseEvent, registerKeyEvent methods to capture the AWT mouse and keyboard events then forwards them to the various GUI controls.

My idea is to use the new methods register("mouseEvent", this) to capture the Processing events  then forward the native object onto the controls.

This solution (for desktop applications) is simple to implement provided that the native objects inside the Processing event match their AWT counterparts i.e.

Processing Event
      Native object
MouseEvent
                        java.awt.event.MouseEvent
KeyEvent     
                java.awt.event.KeyEvent

Does anyone know whether this is the casse for all renderers. The comments suggest that OpenGL on the desktop may become NEWT based.

I am not familiar with the NEWT toolkit but my research seems to indicate that the AWT and NEWT toolkits can exist side by side and in particular JOGL can work with both.

Is it the intention of the development team to replace AWT with NEWT when using P2D and P3D or can I rely on the native object mapping above?

Re : ArrayIndexOutofBoundsException ERROR

$
0
0
The reason I am using  myPort = new Serial(this, Serial.list()[0], 9600); is because on one of the examples the code says that using that code any COM PORT when I plug my devices it ill take that new port and uses that one. In this case, I dont have to care about the port number and just write this code. 

// Example by Tom Igoe

import processing.serial.*;

// The serial port:
Serial myPort;

void setup() {
  // List all the available serial ports:
  println(Serial.list());
  // Open the port you are using at the rate you want:
  myPort = new Serial(this, Serial.list()[0], 9600);
}

void draw() {
  while (myPort.available() > 0) {
    int inByte = myPort.read();
    println(inByte);
  }
}


Thanks to everyone !! 

Re : Osculator and Processing

$
0
0
You mean the library OscP5? It can handle the OSC events sent from Osculator, which communicates with the Wiimote.
At first you should have a look at the OSCulator documentation here.
It's working like this:
1) Connect Wii to OSCulator 
2) Set the Proper OUT Port in OSCulator
3) Setup the OSC-out connection in OSCUlator. You can either send MIDI or OSC (maybe even more) - you need to specify this for every button or load a template
3) In Processing start the OscP5 Sender-Receiver example. There you should put in the output port of OSCulator.

If you get a message there, you can go further...
Good luck!
Viewing all 1768 articles
Browse latest View live