User Tools

Site Tools


courses:intro.prototyping.fall.2012.nov07

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

courses:intro.prototyping.fall.2012.nov07 [2012/11/06 23:59]
130.239.232.31 created
courses:intro.prototyping.fall.2012.nov07 [2012/11/07 00:00] (current)
130.239.232.31
Line 1: Line 1:
 +=== Sound in processing ===
 +
 +==AudioSample==
 +
 +<code java>
 +import ddf.minim.*;​
 + 
 +Minim minim;
 +AudioSample money, chest;
 + 
 +void setup()
 +{
 +  // always start Minim before you do anything with it
 +  minim = new Minim(this);​
 +
 +  // load soundfile from the data folder
 +  money = minim.loadSample("​CASH2.WAV"​);​
 +  chest = minim.loadSample("​CHEST-OPEN1.WAV"​);  ​
 +}
 + 
 +void draw()
 +{
 +  //nothing to actually draw
 +}
 + 
 +//this runs when a key is pressed
 +void keyPressed()
 +{  ​
 +  if ( key == '​y'​ ) 
 +  {
 +    money.trigger();​
 +  }
 +  ​
 +  if ( key == '​u'​ ) 
 +  {
 +    chest.trigger();​
 +  }
 +}
 + 
 +//this is clean-up when the program quits
 +void stop()
 +{
 +  // always close Minim audio classes when you are done with them
 +  money.close();​
 +  chest.close();​
 +  minim.stop();​
 +}
 +</​code>​
 +
 +==AudioPlayer==
 +
 +<code java>
 +import ddf.minim.*;​
 +
 +Minim minim;
 +AudioPlayer soundtrack;
 +
 +void setup()
 +{
 +  // always start Minim before you do anything with it
 +  minim = new Minim(this);​
 +
 +  //load a file  ​
 +  soundtrack = minim.loadFile("​song.mp3"​);​
 +}
 +
 +void draw()
 +{
 +  //nothing to actually draw
 +}
 +
 +//this is run when a key is pressed
 +void keyPressed()
 +{
 +  if ( key == '​q'​ ) 
 +  {
 +    soundtrack.play();​
 +  }
 +  ​
 +  if ( key == '​w'​)
 +  {
 +    soundtrack.pause();​
 +  }
 +  ​
 +  if( key == '​e'​)
 +  {
 +    soundtrack.rewind(); ​
 +  }
 +}
 +
 +//this is clean-up when the program quits
 +void stop()
 +{
 +  // always close Minim audio classes when you are done with them
 +  soundtrack.close();​
 +  minim.stop(); ​
 +}
 +  ​
 +</​code>​
 +
 +== New input! Mouseclicked! ==
 +Much like keyPressed() is run when a key is pressed, mouseClicked is run when any mousebutton is clicked
 +and like keyPressed() this is written outside of setup() and draw().
 +<code java>
 +void mouseClicked() {
 +  //you decide what happens
 +}
 +
 +</​code>​
  
courses/intro.prototyping.fall.2012.nov07.txt · Last modified: 2012/11/07 00:00 by 130.239.232.31