Skip to content

Instantly share code, notes, and snippets.

@ocello3
Created January 13, 2016 21:09
Show Gist options
  • Save ocello3/35c3b1742eafbb904c4f to your computer and use it in GitHub Desktop.
Save ocello3/35c3b1742eafbb904c4f to your computer and use it in GitHub Desktop.
Metronome class in processing (BPM, beat)
class Metro {
float bpm;
float nextTime = 0;
int mode = 0;
int modeNum;
Metro(float _bpm, int _modeNum) {
bpm = _bpm;
modeNum = _modeNum;
}
int metro() {
float timer = bpm * 100/6; // interval of mode
if (millis() > nextTime) {
mode++;
if (mode > (modeNum - 1)) {
mode = 0;
}
nextTime = millis() + timer;
}
return mode;
}
}
Metro metro1;
void setup() {
size(300, 300);
metro1 = new Metro(60, 3);
}
void draw() {
background(210);
int _mode = metro1.metro();
//println(mode);
fill(0, 200);
textSize(42);
textAlign(CENTER);
text(_mode, width/2, height/2);
//saveFrame("frames/#####.tif");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment