We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am creating a music machine and when I press the 'a' key the function begins to hold the note. When I release the 'a' key, the sound file stops, as i want it to.
But when I go to press the 'a' key again, no sound comes out at all. I feel like the key1.pause(); function stops it correctly but wont load the same sound file when pressing the 'a' key again.
When I use the key1.rewind(); under the keyReleased function, it plays the sound upon releasing the key 'a' in a rewind manner.
This is my final project for Programming for Visual Artists and really could use some assistance please!
import ddf.minim.analysis.*;
import ddf.minim.*;
Minim minim;
AudioPlayer key1;
void setup() {
size(1440, 770);
minim = new Minim(this);
key1 = minim.loadFile("key1.mp3", 512);
}
void draw() {
}
void keyPressed() {
if (key=='a')
key1.play();
}
void keyReleased() {
key1.pause();
}
Answers
Just like a piano, when you hold down the key, it plays. I am not striking the 'a' key to hear the whole file, I am only holding it down to play while the 'a' key is held.
So finding out how to reload the sound to be able to play repeatedly is my main concern! :)
I believe you need a sampler. Check the fisrt link were jeremydouglass talk about a sampler.
https://forum.processing.org/two/discussion/21316/how-do-i-play-the-same-soundfile-multiple-times-simultaneously
https://forum.processing.org/two/discussion/15705/play-single-audio-file-multiple-times
https://forum.processing.org/two/discussion/12966/how-to-play-an-audio-file-sequentially
https://forum.processing.org/two/discussion/3996/sound-only-plays-once-why
Kf
you need to rewind samples before they'll play again.
Or use a minim Sampler and no rewinding -- that is specifically what it is for.
When choosing the number of voices think about how many additional times you could press the piano key while previous vibrato from that note hangs in the air.