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

DTMやプログラミングにお熱なd-kamiがマイペースに書くブログ

++age

今日は誕生日であり、0x22歳となった。つまり34歳。はてなブログのプロフィールも修正したし完璧!というわけで今年は頑張りたいところだけど、作曲はいきなり微妙な雰囲気になっている。まぁ、胃潰瘍があったからねぇ…去年は腰椎椎間板ヘルニアやったし、これからは健康的に生きていきたいものだ…

Windows SDK使ってMIDIシーケンサ編 その1

何故だかWin32API使ってMIDIシーケンサを作ろうとしている。とりあえずピアノロール部分をCreateWindowExで作れるようにRegisterClassExしてる。よくわかってないけど、CreateWindowExのdwStyleにWS_CHILD | WS_BORDER | WS_VISIBLEと書いて、なんとか子ウインドウ(?)として作れた模様。メインのウインドウとは違うウインドウプロシージャで制御中…このボーダーラインの内を右クリックすると音が鳴るようにはなっている

 

f:id:d-kami:20180404224441p:plain

適当に作ろう

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);
}