GMU:Processing im Park/Emilio Aguas/Code Sound Board

From Medien Wiki

--- Processing2.2.1 Code---

import ddf.minim.*;


Minim minim;
PImage img;
int n = 7;
int activeLocation = -1;
String playingLocation = "Audio";
AudioPlayer[] players = new AudioPlayer[n];
int[][] locations = {
  {380, 145, 6}, 
  {370, 157, 6}, 
  {350, 160, 6}, 
  {390, 160, 6}, 
  {410, 160, 6}, 
  {350, 170, 6},
  {420, 160, 6}
};



void setup() {
  size(800, 424);
  minim = new Minim(this);
  img = loadImage("Ilm_Park.jpg");
  for (int i = 0; i < n; i++) {
    players[i] = minim.loadFile("park-0"+i+".wav");
  }
}


void draw() {

  image(img, 0, 0);
  fill(255, 0, 0, 150);
  noStroke();
  // set dummy value for the active location 
  activeLocation = -1; 

  for (int i = 0; i < locations.length; i ++) {
    // get location triple
    int[] loc = locations[i];
    // assign variables
    int x = loc[0];
    int y = loc[1];
    int r = loc[2];

    // check if we are at the i'th location
    if (atLocation(x, y, r)) {
      // set active loaction to the current location
      activeLocation = i;
      // hilight the location
      ellipse(x, y, 2*r, 2*r);
      textSize(20);
      fill(255,0,255);
      text(playingLocation + activeLocation,x,y-10);
    }
  }
}

// check if the mouse is within radius r of location(x, y)
boolean atLocation(int x, int y, int r) {
 return dist(x,y,mouseX,mouseY)<r;
 }



void mousePressed() {

  // is the mouse hovering over one of the locations?
  if (activeLocation != -1) {

    // pause all players
    for (int i = 0; i < n; i++) {
      players[i].pause();
    }

    // play the sound associated with the current location
    println("Sound number " + (activeLocation));
    players[activeLocation].rewind();
    players[activeLocation].play();
  }
}