ofApp.cpp for MIDI Timecode
// in ofApp
void draw() {
text << " / " << tempoBars << " : " << tempoqNotes << " : " << num32thNotes;
ofDrawBitmapString(text.str(), 55, 12);
text.str(""); // clear
}
void testApp::newMidiMessage(ofxMidiMessage& msg){
midiMessage = msg;
int tempoDenominator = 4;
int tempoNumerator = 4;
int ticksPerqNote = 48;
int _ticksPerqNote = (int) 24.0 * 4.0/tempoDenominator;
ticksPerBar = tempoNumerator * ticksPerqNote;
ticks32thNotePerBar = (int) ticksPerBar/8.0;
ticksPer32thNote = (int) ticksPerqNote/8.0;
if(msg.status == 248){
tempoTicks += 1;
ticksfor32thNote +=1;
if(ticksfor32thNote % ticksPer32thNote == 0 ) {
// if(num32thNotes % 2 == 0) midiOut.sendNoteOff(1, 62, 0);
// else midiOut.sendNoteOn(1, 62, 127);
num32thNotes += 1;
}
if(tempoTicks % _ticksPerqNote == 0 ) {
tempoqNotes += 1;
tempoTicks = 0;
if (tempoqNotes % (tempoNumerator + 1) == 0 ) {
tempoBars += 1;
tempoqNotes = 1;
num32thNotes = 0;
ticksfor32thNote = 0;
}
}
}
if(msg.status == MIDI_START) {
//ticks = 0;
//qNotes = 0;
//bars = 0;
tempoTicks = 0;
tempoqNotes = 1;
tempoBars = 1;
isPlaying = false;
num32thNotes = 0;
ticksfor32thNote = 0;
cout << " live Set playing ...." << endl;
isPlaying = true;
};
if(msg.status == MIDI_STOP) cout << " live Set paused " << endl;
if(msg.status == MIDI_SONG_POS_POINTER && msg.byteOne == 0 && msg.byteTwo == 0) {
cout << " live Set stopped " << endl;
tempoTicks = 0;
tempoqNotes = 1;
tempoBars = 1;
//isPlaying = false;
num32thNotes = 0;
ticksfor32thNote = 0;
}
if ((int)midiMessage.bytes[0] == 190) {
// cout << "ch : " << (((int)midiMessage.bytes[0])) << endl;
cout << "ch : " << (((int)midiMessage.bytes[1])) << endl;
cout << "cont : " << (((int)midiMessage.bytes[2])) << endl;
}
// cout << "ch : "<< (((int)midiMessage.bytes[0])) << endl;
// cout << "note : " << (((int)midiMessage.bytes[1])) << endl;
if ((int)midiMessage.bytes[0] == 158){
ch15Note = (int)midiMessage.bytes[1];
}
if ((int)midiMessage.bytes[0] == 159){
ch16Note = (int)midiMessage.bytes[1];
}
}