c_cpp ofApp.cpp用于MIDI时间码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp ofApp.cpp用于MIDI时间码相关的知识,希望对你有一定的参考价值。

// in ofApp

void draw() {
	text << " /   " << tempoBars << " : " << tempoqNotes << " : " << num32thNotes;
	ofDrawBitmapString(text.str(), 55, 12);
	text.str(""); // clear
}

void testApp::newMidiMessage(ofxMidiMessage&amp; 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];
	}

}

以上是关于c_cpp ofApp.cpp用于MIDI时间码的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp Midi程序变更示例

c_cpp MIDI控制器由jardous

c_cpp LCD MIDI Monitor v2.0

c_cpp MIDI监视器(LCD)v1.0

c_cpp Dilicktal_MIDI v2_0

c_cpp Dilicktal_MIDI v1_0