マイペースなプログラミング日記

x86エミュレータやFPGA、WebGLにお熱なd-kamiがマイペースに書くブログ

適当に作ろう

JavaでもやってるけどCreateWindowな環境でもやってたりします

#include "MidiOut.h"
#include <assert.h>

void MidiOut::open(){
	midiOutOpen(&hMidiOut, MIDI_MAPPER, 0, 0, 0);
}

void MidiOut::noteOn(int32_t channel, int32_t note, int32_t velocity) {
	assert(0 <= velocity && velocity <= 127);
	assert(0 <= channel && channel <= 15);
	assert(0 <= note && note <= 127);

	int32_t outData = NOTE_ON | channel;
	outData |= (note << 8);
	outData |= (velocity << 16);

	midiOutShortMsg(hMidiOut, outData);
}

void MidiOut::noteOff(int32_t channel, int32_t note, int32_t velocity) {
	assert(0 <= velocity && velocity <= 127);
	assert(0 <= channel && channel <= 15);
	assert(0 <= note && note <= 127);

	int32_t outData = NOTE_OFF | channel;
	outData |= (note << 8);
	outData |= (velocity << 16);

	midiOutShortMsg(hMidiOut, outData);
}

void MidiOut::reset() {
	midiOutReset(hMidiOut);
}

void MidiOut::close() {
	midiOutClose(hMidiOut);
}