As computing becomes more ubiquitous in our objects, designers need to be more aware of how to design meaningful interactions into electronically enhanced objects. At the University of Washington, a class of junior Interaction Design majors is exploring this question. These pages chronicle their efforts.

Thursday, April 5, 2012

Aaron’s Processing


/**
 * Load File
 * by Damien Di Fede.
 * edited by Aaron Calzado for ART 387 Spring 2012
 *
 * This sketch demonstrates how to use the <code>loadFile</code> method
 * of <code>Minim</code>. The <code>loadFile</code> method allows you to
 * specify the file you want to load with a <code>String</code> and optionally
 * specify what you want the buffer size of the returned <code>AudioPlayer</code>
 * to be. If you don't specify a buffer size, the returned player will have a
 * buffer size of 1024. Minim is able to play wav files, au files, aif files,
 * snd files, and mp3 files. When you call <code>loadFile</code>, if you just
 * specify the filename it will try to load the file from the data folder of
 * your sketch. However, you can also specify an absolute path
 * (such as "C:\foo\bar\thing.wav") and the file will be loaded from that
 * location (keep in mind that won't work from an applet). You can also specify
 * a URL (such as "http://www.mysite.com/mp3/song.mp3") but keep in mind that
 * if you run the sketch as an applet you may run in to security restrictions
 * if the applet is not on the same domain as the file you want to load. You can
 * get around the restriction by signing the applet. Before you exit your sketch
 * make sure you call the <code>close</code> method of any <code>AudioPlayer</code>'s
 * you have received from <code>loadFile</code>, followed by the <code>stop</code>
 * method of <code>Minim</code>.
 */

 // Drawing Text taken from Daniel Shiffman @ http://www.learningprocessing.com
 // Music - I do not own the music. Please don't sue me!

import ddf.minim.*;

AudioPlayer player;
Minim minim;

PFont f; // drawing text step 2 declare pfont variable

void setup()
{
  size(512, 200, P2D);

  f = loadFont("Courier-Bold-16.vlw"); // drawing text step 3 load font

  minim = new Minim(this);
 
  // load a file, give the AudioPlayer buffers that are 2048 samples long
  player = minim.loadFile("stde.mp3", 2048);
  // "play" the file once, "loop" the file forever!
  player.loop();
}

void draw()
{
  background(80);
  stroke(255);
  // if mouse is pressed
  if (mousePressed) {
    // drawing text
    textFont(f,24);
    fill(255);
    text("PSYCH! It never ends!", 105, 100);
  } else {
    textFont(f,10); // drawing text step 4 specify font to be used
    fill(255); // drawing text step 5 specify font color
    text("Click anywhere to end the song", 165, 100); // drawing text step 6 display Text

  }
  // draw the waveforms
  // the values returned by left.get() and right.get() will be between -1 and 1,
  // so we need to scale them up to see the waveform
  // note that if the file is MONO, left.get() and right.get() will return the same value
  for(int i = 0; i < player.left.size()-1; i++)
  {
    line(i, 50 + player.left.get(i)*50, i+1, 50 + player.left.get(i+1)*50);
    line(i, 150 + player.right.get(i)*50, i+1, 150 + player.right.get(i+1)*50);
  }
}

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

No comments:

Post a Comment