You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.1 KiB
60 lines
1.1 KiB
import processing.sound.*;
|
|
|
|
SoundFile[] file;
|
|
|
|
// Define the number of samples
|
|
int numsounds = 5;
|
|
int bpm = 280;
|
|
int divider = 16;
|
|
int duration = int((60/float(bpm))*1000);
|
|
int beat = 0;
|
|
|
|
int[][] samples = {
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
|
};
|
|
|
|
void setup() {
|
|
size(640, 360);
|
|
background(255);
|
|
|
|
// Load sound files
|
|
file = new SoundFile[numsounds];
|
|
for (int i = 0; i < numsounds; i++) {
|
|
file[i] = new SoundFile(this, "bank1/" + (i+3) + ".wav");
|
|
}
|
|
|
|
}
|
|
|
|
void draw() {
|
|
background(255);
|
|
stroke(255);
|
|
|
|
for(int i=0; i<4; i++) {
|
|
fill(90);
|
|
for(int y=0; y<divider; y++) {
|
|
rect((width/divider)*y,(height/4)*i, width/divider, height/4);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for(int i=0; i<4; i++) {
|
|
|
|
fill(150);
|
|
if(samples[i][beat] != 0) {
|
|
fill(0, 200, 0);
|
|
file[samples[i][beat]+1].play();
|
|
}
|
|
rect((width/divider)*beat,(height/4)*i, width/divider, height/4);
|
|
|
|
}
|
|
|
|
beat++;
|
|
if(beat>=divider){beat=0;}
|
|
|
|
delay(duration);
|
|
|
|
}
|