Created
July 2, 2015 15:54
-
-
Save microcosm/c0bd4320fb678359b707 to your computer and use it in GitHub Desktop.
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
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