Ejemplo n.º 1
0
 // Pressing the mouse stops and starts the sound
 public void mousePressed() {
   if (tone.isPlaying()) {
     tone.stop(); //   The sound can be stopped with the function stop().
   } else {
     tone.repeat();
   }
 }
Ejemplo n.º 2
0
  public void draw() {
    if (tone.isPlaying()) {
      background(255);
    } else {
      background(100);
    }

    // Set the volume to a range between 0 and 1.0
    float ratio = (float) mouseX / width;
    tone.setVolume(ratio);

    // Set the rate to a range between 0 and 88,200
    // Changing the rate alters the pitch
    ratio = (float) mouseY / height;

    // The rate is set according to the mouseY position.
    tone.setRate(ratio * 88200);

    // Draw some rectangles to show what is going on
    stroke(0);
    fill(175);
    rect(0, 160, mouseX, 20);
    stroke(0);
    fill(175);
    rect(160, 0, 20, mouseY);
  }