Created
January 13, 2016 21:09
-
-
Save ocello3/35c3b1742eafbb904c4f to your computer and use it in GitHub Desktop.
Metronome class in processing (BPM, beat)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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