Hello again!
Yes I think that is accurate!
The thing is that in this class it only says what type of color for it to change. I might need to set them to 0 (if mousepressed puts them on 1). Like a reset to the whole drum machine (currently 6 rows of arrays).
Here I post another part of the code that regards to this!
Main page here
// -------------------------------------------------
// -------------------------------------------------
import g4p_controls.*;
import processing.opengl.*;
import ddf.minim.*;
import ddf.minim.ugens.*;
import ddf.minim.signals.*;
import controlP5.*;
Minim minim;
AudioOutput out;
Rect rect;
Tick tick;
Sampler kick;
Sampler snare;
Sampler hat;
ControlP5 cp5;
boolean[] row1 = new boolean[16];
boolean[] row2 = new boolean[16];
boolean[] row3 = new boolean[16];
boolean[] row4 = new boolean[16];
boolean[] row5 = new boolean[16];
boolean[] row6 = new boolean[16];
public boolean TOGGLE_VALUE = true;
public int BPM = 120;
public int BEAT;
ArrayList<Rect> buttons = new ArrayList<Rect>();
// -------------------------------------------------
// -------------------------------------------------
public void setup() {
size(1100, 650, JAVA2D);
minim = new Minim(this);
cp5 = new ControlP5(this);
out = minim.getLineOut();
Power();
Interface();
kick = new Sampler("BD.wav", 4, minim); // 4 nr de vozes
snare = new Sampler("SD.wav", 4, minim);
hat = new Sampler("CHH.wav", 4, minim);
kick.patch(out);
snare.patch(out);
hat.patch(out);
for (int i = 0; i < 16; i++){
buttons.add(new Rect(233+i*40, 155, row1, i));
buttons.add(new Rect(233+i*40, 190, row2, i));
buttons.add(new Rect(233+i*40, 225, row3, i));
buttons.add(new Rect(233+i*40, 260, row4, i));
buttons.add(new Rect(233+i*40, 295, row5, i));
buttons.add(new Rect(233+i*40, 330, row6, i));
}
BEAT = 0;
out.setTempo(BPM);
out.playNote(0, 0.25f, new Tick());
}
public void draw() {
background(20, 80, 89);
stroke(0, 0, 0, 0);
fill(24, 100, 110);
rect(226, 150, 649, 215); //Grande
fill(24, 100, 110);
rect(226, 370, 649, 110); //Grande2
fill(24, 100, 110);
rect(226, 120, 649, 25); // Pequeno
fill(24, 100, 110);
rect(146, 120, 75, 25); // Pequeno2
fill(24, 100, 110);
rect(146, 150, 75, 215); // Pequeno3
fill(24, 100, 110);
rect(880, 120, 75, 245); // Pequeno4
for (int i = 0; i < buttons.size(); i++){
buttons.get(i).draw();
}
if (TOGGLE_VALUE == true) {
fill(38, 160, 180);
rect(233 + BEAT * 40, 125, 35, 15);
out.unmute();
}
if (TOGGLE_VALUE == false) {
fill(0, 0, 0, 0);
out.mute();
}
}
void mousePressed(){
for (int i = 0; i < buttons.size(); ++i){
buttons.get(i).mousePressed();
}
}
public void customGUI(){
}
[Then I have a button page that I call GUIās from controlP5 library, so I can trigger things on click]
Here the rectangle class
public boolean TEST = false;
public class Rect {
public int x, y, w, h;
public boolean[] steps;
public int stepId;
public Rect(int _x, int _y, boolean[] _steps, int _id){
x = _x;
y = _y;
w = 35;
h = 30;
steps = _steps;
stepId = _id;
}
public void draw(){
if (steps[stepId]){
fill(157, 30, 139);
} else {
fill(38, 160, 180);
}
rect(x, y, w, h);
}
public void mousePressed(){
if (mouseX >= x && mouseX <= x+w && mouseY >= y && mouseY <= y+h){
steps[stepId] = !steps[stepId];
}
}
}
Then in here the Tick class that extends Instrument
public class Tick implements Instrument {
public void noteOn(float dur){
if (row1[BEAT]) hat.trigger();
if (row2[BEAT]) snare.trigger();
if (row3[BEAT]) kick.trigger();
}
public void noteOff() {
BEAT = (BEAT+1)%16;
out.setTempo(BPM);
out.playNote(0, 0.25f, this);
}
}
Sorry for the spam lol.
So the thing would be. Imagine I make a mess out of this and I click a bunch of buttons, and I want them to return to 0 because I donāt want to close and open the software again.
Do you understand my point?
Thank you again
Best regards Luis!