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.
IndexProgramming Questions & HelpOther Libraries › Making Ess talk to sDrop
Page Index Toggle Pages: 1
Making Ess talk to sDrop (Read 847 times)
Making Ess talk to sDrop
May 2nd, 2010, 11:10pm
 
Hey guys.  I am basically trying to drag and drop in an mp3 file into my sketch and have that mp3 placed into an Audiochannel.  After that I want to be able to press a key to play it.

The way I approached it was to get the two examples (I pretty much combined one example from each library) working individually in one sketch.  That worked fine.

Next I tried to add in myFile into myChannel=new AudioChannel("01 Intro.mp3); making it myChannel=new AudioChannel(myFile);

Where ever I put that piece of code I get "The constructor AudioChannel(File) is undefined."  I don't know where to put it...or if thats how to go about it.  I tried letting myChannel equal something from the get go and then having the user press the S key to change it but I still get the undefined error.  My logic is off somewhere but I cant find it.  Here's the code, thanks in advance for anyone that can help.  


Code:


/*
* Trying to drag and drop an mp3 into the sketch and then played by
* pressing the P button.
*/



import krister.Ess.*;
import sojamo.drop.*;

AudioChannel myChannel;
FFT myFFT;

int bufferSize;
int bufferDuration;

SDrop drop;

void setup() {
 size(256,200);
 drop = new SDrop(this);

 // start up Ess

   Ess.start(this);        //Has to be here or Ess doesn't work

 myChannel=new AudioChannel("01 Intro.mp3");
 bufferSize=myChannel.buffer.length;
 bufferDuration=myChannel.ms(bufferSize);

 myFFT=new FFT(512);

 frameRate(30);
 noSmooth();
}

void draw() {
 background(0,0,255);            //This draws the cool stuff
 drawSpectrum();
 drawSamples();
}


void dropEvent(DropEvent theDropEvent) {    //allows me to drag n drop files/folders
 if(theDropEvent.isFile()) {
   // for further information see
   // http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html
   File myFile = theDropEvent.file();
   println("\nisDirectory ? "+myFile.isDirectory()+"  /  isFile ? "+myFile.isFile());
   println(myFile);
   if(myFile.isDirectory()) {
     println("listing the directory");

     // list the directory, not recursive, with the File api. returns File[].
     println("\n\n### listFiles #############################\n");
     println(myFile.listFiles());
   }
   if(keyPressed) {
     if (key == 's' || key == 'S') {
       myChannel=new AudioChannel(myFile);
     }
   }
 }

}

void drawSpectrum() {    //helps to draw the cools stuff along with drawSamples
 noStroke();

 myFFT.getSpectrum(myChannel);

 for (int i=0; i<256; i++) {
   float temp=max(0,185-myFFT.spectrum[i]*175);
   rect(i,temp+.5,1,height-temp+.5);
 }
}


void drawSamples() {    //Draws cool stuff along with drawSpectrum
 stroke(255);

 // interpolate between 0 and writeSamplesSize over writeUpdateTime
 int interp=(int)max(0,(((millis()-myChannel.bufferStartTime)/(float)bufferDuration)*bufferSize));

 for (int i=0;i<256;i++) {
   float left=100;
   float right=100;

   if (i+interp+1<myChannel.buffer2.length) {
     left-=myChannel.buffer2[i+interp]*75.0;
     right-=myChannel.buffer2[i+1+interp]*75.0;
   }

   line(i,left,i+1,right);
 }
}  

void keyPressed() {    //toggles for on and off
 if(keyPressed) {
   if (key == 'p' || key == 'P') {
     if (myChannel.state==Ess.PLAYING) {
       myChannel.stop();
     }
     else {
       myChannel.play(Ess.FOREVER);
     }
   }
 }
}

// clean up Ess before exiting

public void stop() {
 Ess.stop();
 super.stop();
}



Re: Making Ess talk to sDrop
Reply #1 - May 2nd, 2010, 11:37pm
 
Okay I'm an idiot...Audiochannel only takes in strings but still....ya know what I'm trying to do.  Please help =[
Page Index Toggle Pages: 1