I've already posted about this and phi.lho was kind enough to impart some of his knowledge in answering some of my questions. One of the unanswered problems though was that of my drum samples being triggered multiple times in quick succession, making them sound distorted. I think I now understand why this is happening, but still cant come up with a solution. Here's my code so far:
int colBox = int(mouseX)/25; //uses mouse coordinates to determine grid number
int rowBox = int(mouseY)/25;
grid[colBox][rowBox].checked();
}
}
void keyPressed(){
switch(key){
case 'm':
initial = millis();
if(on == true){
on = false;
}else{
on = true;}
break;
}
}
void stop(){
kick.close();
hihat.close();
snare.close();
crash.close();
minim.stop();
super.stop();
}
class Grid {
float x, y, wd, ht;
boolean active = false;
Grid(float X, float Y, float WD, float HT) {
x = X;
y = Y;
wd = WD;
ht = HT;
}
void display(int col) {
stroke (255);
if(active == true){
fill(0);
}else{
fill(col);
}
rect(x, y, wd, ht);
}
void checked(){
if(active == true){
active = false;
}else{
active = true;
}
}
void trigger(float x, float y){
if (active == true){
if (y == 4){
hihat.trigger();
}
if (y == 5){
kick.trigger();
}
if (y == 6){
snare.trigger();
}
if (y == 7){
crash.trigger();
}
}
}
}
I think the reason the samples are being triggered in really quick succession, rather than just once, is 'active == true' (line 145 of the code) is true for multiple frames before moving onto the next column. For example, if the BPM is 120 then each checked block will be activated (active == true) for 125ms before moving on to the next column. I'm assuming that in that 125ms, every time the frame resets, it will trigger the sample - hence the quick succession of samples. Obviously what I want is for the sample to only trigger once. Is there a way of doing this?
Any help or suggestions on this would be greatly appreciated!
I'm trying to make a drum-sequencing programme that plays drum samples with a control to change the bpm. I have 2 problems that I can' figure out. First, if I mouse-click outside of the grid I get an OutOfBoundsException and I don't know how to get around it. Secondly when a sample is triggered it sounds distorted (in fact, it sounds like the sample is being played three or four times in very quick succession). I've used sample.trigger() in another programme and it worked fine so I have no idea why its not working in this code. I've been scratching my head for days! I should point out I'm new to Processing and programming in general so apologies if my code is messy!
Any help or suggestions would be greatly appreciated!
speed = (((60 / bpm) * 1000) * 16);//60 seconds divided by bpm times by a thousand (to make it milli seconds) times by 16 for the 16 columns of the grid