adding more sound files
in
Core Library Questions
•
2 years ago
Hi,
attached is a sketch (made with help form arthurG, thanks!) which allows me to pan an audio file left and right, and change its gain. Next thing i want to do is load another sound, controlled by another ellipse. can anyone give me some tips, get me started?
cheers,
josh
- import ddf.minim.*;
- import ddf.minim.signals.*;
- AudioPlayer player;
- Minim minim;
- boolean over = false;
- boolean selected = false;
- int posX, posY;
- int offsetX, offsetY;
- float radius = 25.0f;
- void setup()
- {
- size(512, 512);
- minim = new Minim(this);
- player = minim.loadFile("Kalimba.mp3");
- player.play();
- textFont(createFont("SanSerif", 12));
- posX = width/2;
- posY = height/2;
- smooth();
- }
- void draw()
- {
- background(0);
- strokeWeight (1.0f);
- fill(255,155);
- // see waveform.pde for more about this
- if ( player.hasControl(Controller.PAN) )
- {
- // map the mouse position to the range of the pan
- float valPan = map(posX, 0, width, -1, 1);
- // if a pan control is not available, this will do nothing
- player.setPan(valPan);
- float valGain = map(posY, 0, height, 6, -48);
- player.setGain(valGain);
- // if a pan control is not available this will report zero
- text("pan : " + player.getPan() , 5, 20);
- text("gain : " + player.getGain() , 150, 20);
- if (selected)
- strokeWeight (2.0f);
- if (over)
- fill (255,255);
- ellipse (posX,posY,radius*2.0f,radius*2.0f);
- }
- else
- {
- text("The output doesn't have a pan control.", 5, 20);
- }
- }
- void stop()
- {
- // always close Minim audio classes when you are finished with them
- player.close();
- minim.stop();
- super.stop();
- }
- void mouseMoved() {
- over = false;
- if (sqrt(sq(mouseX-posX)+sq(mouseY-posY))<=radius) {
- over = true;
- }
- }
- void mousePressed() {
- if (over) {
- selected = true;
- offsetX = posX-mouseX;
- offsetY = posY-mouseY;
- }
- }
- void mouseReleased() {
- selected = false;
- }
- void mouseDragged()
- {
- if (selected) {
- posX = max(0,min(mouseX+offsetX,width));
- posY = max(0,min(mouseY+offsetY,height));
- }
- }
1