Hi, I am a total newbie and have tried a few ways (//as you can see) to get these random files to play back when mousePressed but to no avail. This is the closest post I have found to what I am trying to do, which is to trigger the files, display the filename at the location and change the background to a random colour. Can anyone tell me what I am doing wrong?
- Minim minim;
- AudioSample[]notes = new AudioSample[8];
- AudioMetaData meta;
- int myRan;
- void setup() {
- size(400, 680);
- background(0);
- colorMode(HSB);
- textFont(createFont("Serif", 12));
- minim = new Minim(this);
- notes[0] = minim.loadSample("A2 MONO.wav", 2048);
- notes[1] = minim.loadSample("B2.wav", 2048);
- notes[2] = minim.loadSample("C2.wav", 2048);
- notes[3] = minim.loadSample("D2.wav", 2048);
- notes[4] = minim.loadSample("E2.wav", 2048);
- notes[5] = minim.loadSample("F2.wav", 2048);
- notes[6] = minim.loadSample("G2.wav", 2048);
- notes[7] = minim.loadSample("C3.wav", 2048);
- }
- int index = 0;
- void draw() {
- if (mousePressed)
- {
- //index = int(random(notes.length));
- background(random(255), 255, 255);
- myRan = (int) random(0, 8);
- notes[myRan].play();
- notes[myRan].cue(0);
- fill(255);
- textSize(random(48, 400));
- text("" + meta.fileName(), mouseX, mouseY);
- }
- }
- void stop() {
- minim.stop();
- super.stop();
- }