Skip to content

Instantly share code, notes, and snippets.

@microcosm
Created July 2, 2015 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save microcosm/c0bd4320fb678359b707 to your computer and use it in GitHub Desktop.
Save microcosm/c0bd4320fb678359b707 to your computer and use it in GitHub Desktop.
bool playing;
void setup() {
playing = false;
float bpm = 50;
clock.setBpm(bpm * 24); //24 ppqn https://en.wikipedia.org/wiki/MIDI_beat_clock
ofAddListener(clock.beatEvent, this, &ofApp::tick);
}
void ofApp::tick(void){
if(playing) {
if(counter == 0) {
cout << "====== Quarter Note =======" << endl;
} else {
cout << "." << endl;
}
if(counter == 23) {
counter = 0;
} else {
counter++;
}
chain1.midi()->sendMidiByte(MIDI_TIME_CLOCK);
chain2.midi()->sendMidiByte(MIDI_TIME_CLOCK);
}
}
void ofApp::togglePlaying() {
playing = !playing;
if(playing) {
chain1.sendMidiOn(note);
chain2.sendMidiOn(note);
chain1.midi()->sendMidiByte(MIDI_START);
chain2.midi()->sendMidiByte(MIDI_START);
clock.start();
counter = 0;
} else {
chain1.sendMidiOff(note);
chain2.sendMidiOff(note);
chain1.midi()->sendMidiByte(MIDI_STOP);
chain2.midi()->sendMidiByte(MIDI_STOP);
clock.stop();
}
}
void ofApp::keyPressed(int key){
if(key == ' ') {
togglePlaying();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment