Minim Problems
in
Core Library Questions
•
2 years ago
I want to make a music sampler with at least 4 sounds that can be triggered. The code below allows the sounds to play once. Right now it makes a static-y glitchy noise after the first playing of each sound. Also, it's playing on mouseover instead of click.
I've looked at all of the documentation but it's not helping. I'm guessing I need to do the close and stop code differently?
import hypermedia.video.*;
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
//SUCCESS!
PImage bass;
PImage organ;
PImage cymbal;
PImage scream;
Minim minim;
AudioPlayer sound1;
AudioPlayer sound2;
AudioPlayer sound3;
AudioPlayer sound4;
void setup(){
size(600,600);
background(102, 102, 102);
minim = new Minim(this);
sound1 = minim.loadFile("bass.mp3");
sound2 = minim.loadFile("organ.wav");
sound3 = minim.loadFile("bass.wav");
sound4 = minim.loadFile("scream.wav");
}
void draw(){
/* AudioPlayer sound1;
AudioPlayer sound2;
AudioPlayer sound3;
AudioPlayer sound4; */
mousePressed();
bass = loadImage("bass.png");
organ = loadImage("organ.gif");
scream = loadImage("scream.gif");
cymbal = loadImage("cymbal.gif");
image(bass, 0, 0);
image(organ, 0, 150);
image(scream, 320, 0);
image(cymbal, 0, 0);
}
void mousePressed(){
if(mouseX > 0 && mouseX < 321 && mouseY > 0 && mouseY < 240)
{
sound1.play();
}
if(mouseX > 321 && mouseX < 640 && mouseY > 0 && mouseY < 239)
{
sound2.play();
}
if(mouseX > 0 && mouseX < 320 && mouseY > 240 && mouseY < 480)
{
sound3.play();
}
if(mouseX > 320 && mouseX < 640 && mouseY > 240 && mouseY < 480)
{
sound4.play();
}
}
void stop()
{
// always close Minim audio classes when you are finished with them
sound1.close();
sound2.close();
sound3.close();
sound4.close();
//isplaying
// always stop Minim before exiting
minim.stop();
super.stop();
}
I've looked at all of the documentation but it's not helping. I'm guessing I need to do the close and stop code differently?
import hypermedia.video.*;
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
//SUCCESS!
PImage bass;
PImage organ;
PImage cymbal;
PImage scream;
Minim minim;
AudioPlayer sound1;
AudioPlayer sound2;
AudioPlayer sound3;
AudioPlayer sound4;
void setup(){
size(600,600);
background(102, 102, 102);
minim = new Minim(this);
sound1 = minim.loadFile("bass.mp3");
sound2 = minim.loadFile("organ.wav");
sound3 = minim.loadFile("bass.wav");
sound4 = minim.loadFile("scream.wav");
}
void draw(){
/* AudioPlayer sound1;
AudioPlayer sound2;
AudioPlayer sound3;
AudioPlayer sound4; */
mousePressed();
bass = loadImage("bass.png");
organ = loadImage("organ.gif");
scream = loadImage("scream.gif");
cymbal = loadImage("cymbal.gif");
image(bass, 0, 0);
image(organ, 0, 150);
image(scream, 320, 0);
image(cymbal, 0, 0);
}
void mousePressed(){
if(mouseX > 0 && mouseX < 321 && mouseY > 0 && mouseY < 240)
{
sound1.play();
}
if(mouseX > 321 && mouseX < 640 && mouseY > 0 && mouseY < 239)
{
sound2.play();
}
if(mouseX > 0 && mouseX < 320 && mouseY > 240 && mouseY < 480)
{
sound3.play();
}
if(mouseX > 320 && mouseX < 640 && mouseY > 240 && mouseY < 480)
{
sound4.play();
}
}
void stop()
{
// always close Minim audio classes when you are finished with them
sound1.close();
sound2.close();
sound3.close();
sound4.close();
//isplaying
// always stop Minim before exiting
minim.stop();
super.stop();
}
1