I'm currently working on a school project with the DrumMachine in minim as a base, but I have one issue I was hoping you could help me with. The GUI is drawed using controlP5 (but is this even necessary?)
Right now I have to toggle each button with a click, but I would like to be able to click-hold-drag to toggle several buttons on. Could you please point me in the right direction?
Regards
Lorang
import processing.opengl.*;
/** * This sketch is a more involved use of AudioSamples to create a simple drum machine. Click on the buttons to * toggle them on and off. The buttons that are on will trigger samples when the beat marker passes over their * column. You can change the tempo by clicking in the BPM box and dragging the mouse up and down. */
ControlP5 gui; boolean[] hatRow = new boolean[16]; boolean[] snrRow = new boolean[16]; boolean[] kikRow = new boolean[16];
public int bpm; int tempo; // how long a sixteenth note is in milliseconds int clock; // the timer for moving from note to note int beat; // which beat we're on boolean beatTriggered; // only trigger each beat once
void setup() { size(600, 300, OPENGL); minim = new Minim(this); // load BD.wav from the data folder, with a 512 sample buffer int bsize = 2048; kick = minim.loadSample("BD.wav", bsize); // load SD.wav from the data folder snare = minim.loadSample("SD.wav", bsize); // load CHH.wav from the data folder hat = minim.loadSample("CHH.wav", bsize);
gui = new ControlP5(this); gui.setColorForeground(color(128, 200)); gui.setColorActive(color(255, 0, 0, 200)); Toggle h; Toggle s; Toggle k; for (int i = 0; i < 16; i++) { h = gui.addToggle("hat" + i, false, 10+i*36, 50, 14, 30); h.setId(i); h.setLabel("hat"); s = gui.addToggle("snr" + i, false, 10+i*36, 100, 14, 30); s.setId(i); s.setLabel("snr"); k = gui.addToggle("kik" + i, false, 10+i*36, 150, 14, 30); k.setId(i); k.setLabel("kik"); } gui.addNumberbox("bpm", 120, 10, 5, 20, 15); bpm = 120; tempo = 125; clock = millis(); beat = 0; beatTriggered = false;
// use the mix buffer do draw the waveforms. // because these are MONO files, we could have used the left or right buffers and got the same data for (int i = 0; i < kick.mix.size()-1; i++) { line(i, 65 - hat.mix.get(i)*30, i+1, 65 - hat.mix.get(i+1)*30); line(i, 115 - snare.mix.get(i)*30, i+1, 115 - snare.mix.get(i+1)*30); line(i, 165 - kick.mix.get(i)*30, i+1, 165 - kick.mix.get(i+1)*30); }