14#pragma comment(lib, "winmm.lib")
53 if ( m_hMidi != NULL )
55 ::midiOutClose(m_hMidi);
67 bool Open(UINT dev = MIDI_MAPPER)
70 return m_Rst(::midiOutOpen(&m_hMidi, dev, NULL, 0, CALLBACK_NULL));
80 return m_hMidi != NULL;
93 return m_Rst(channel, TParam(Midi_ProgramChange, channel, programNumber));
109 vp[0] = TParam(CCC_BackSelectMsb, channel, msb);
110 vp[1] = TParam(CCC_BackSelectLsb, channel, lsb);
111 return m_Rst(channel, vp);
124 ASSERT ( modulation <= 127 );
125 return m_Rst(channel, TParam(CCC_Modulation, channel, modulation));
139 ASSERT ( volume >= 0 && volume <= 127 );
140 return m_Rst(channel, TParam(CCC_Volume, channel, down_cast<BYTE>(volume)));
161 return m_Rst(channel, TParam(CCC_Panpot, channel, down_cast<BYTE>(pan + 64)));
175 ASSERT ( volume >= 0 && volume <= 127 );
176 return m_Rst(channel, TParam(CCC_Expression, channel, down_cast<BYTE>(volume)));
190 ASSERT ( level >= 0 && level <= 127 );
191 return m_Rst(channel, TParam(CCC_ReverbSendLevel, channel, down_cast<BYTE>(level)));
205 ASSERT ( level >= 0 && level <= 127 );
206 return m_Rst(channel, TParam(CCC_ChorusSendLevel, channel, down_cast<BYTE>(level)));
221 ASSERT ( level >= 0 && level <= 127 );
222 return m_Rst(channel, TParam(ECtrlChangeCode(controlNo), channel, down_cast<BYTE>(level)));
235 bool NoteOn(BYTE channel, BYTE note, BYTE velocity = 0)
237 ASSERT ( velocity <= 127 );
238 return m_Rst(channel, TParam(Midi_NoteOn, channel, note, velocity));
250 bool NoteOff(BYTE channel, BYTE note, BYTE velocity = 0)
252 ASSERT ( velocity <= 127 );
253 return m_Rst(channel, TParam(Midi_NoteOff, channel, note));
266 if ( pitchBend < -8192 )
270 else if ( pitchBend > 8181 )
274 int b = pitchBend + 8192;
275 BYTE msb = down_cast<BYTE>((b >> 7) & 0x7F);
276 BYTE lsb = down_cast<BYTE>((b ) & 0x7F);
277 return m_Rst(channel, TParam(Midi_PitchBendChange, channel, lsb, msb));
293 vp[0] = TParam(CCC_RpnMsb, channel, 0);
294 vp[1] = TParam(CCC_RpnLsb, channel, 0);
296 vp[2] = TParam(CCC_DataEntryMsb, channel, v);
297 vp[3] = TParam(CCC_DataEntryLsb, channel, 0);
299 vp[4] = TParam(CCC_RpnMsb, channel, 0x7F);
300 vp[5] = TParam(CCC_RpnLsb, channel, 0x7F);
301 return m_Rst(channel, vp);
305 bool OutMessage(
size_t len, LPCVOID pMessage)
309 mm.
Reset(len,
static_cast<const char*
>(pMessage));
311 hdr.dwBufferLength = len;
312 hdr.dwBytesRecorded = len;
313 if ( ! m_Rst(::midiOutPrepareHeader(m_hMidi, &hdr,
sizeof(MIDIHDR))) )
317 if ( ! m_Rst(::midiOutLongMsg(m_hMidi, &hdr,
sizeof(MIDIHDR))) )
322 while ( (hdr.dwFlags & MHDR_DONE) == 0 )
326 return m_Rst(::midiOutUnprepareHeader(m_hMidi, &hdr,
sizeof(MIDIHDR)));
355 return ::midiOutGetNumDevs();
366 if ( e != MMSYSERR_NOERROR )
368 ::midiOutGetErrorText(e, s.
GetBuffer(1000), 1000);
377 enum EMidiMessageKind
381 Midi_KeyPressure = 0xA,
382 Midi_CtrlChange = 0xB,
383 Midi_ProgramChange = 0xC,
384 Midi_ChannelPressure = 0xD,
385 Midi_PitchBendChange = 0xE,
391 CCC_BackSelectMsb = 0x00,
392 CCC_BackSelectLsb = 0x20,
393 CCC_Modulation = 0x01,
396 CCC_Expression = 0x0B,
397 CCC_DataEntryMsb = 0x06,
398 CCC_DataEntryLsb = 0x26,
401 CCC_ReverbSendLevel = 0x5B,
402 CCC_TremoloDepth = 0x5C,
403 CCC_ChorusSendLevel = 0x5D,
404 CCC_VarSendLevel = 0x5E,
425 TParam(EMidiMessageKind k, BYTE ch = 0, BYTE d1 = 0, BYTE d2 = 0)
426 : padding(0), kind(down_cast<BYTE>(k)), channel(ch), data1(d1), data2(d2)
429 TParam(ECtrlChangeCode ccc, BYTE ch = 0, BYTE d = 0)
430 : padding(0), kind(down_cast<BYTE>(Midi_CtrlChange)), channel(ch), data1(down_cast<BYTE>(ccc)), data2(d)
433 TParam(
void) : msg(0)
437 friend struct CMidiMessage::TParam;
438 C_ASSERT(
sizeof(TParam) ==
sizeof(DWORD) );
441 bool m_RstFx(MMRESULT r)
444 return r == MMSYSERR_NOERROR;
447 bool m_Rst(MMRESULT r)
450 if ( r != MMSYSERR_NOERROR )
454 return r == MMSYSERR_NOERROR;
457 bool m_Rst(BYTE channel,
const TParam& p)
461 return m_RstFx(MMSYSERR_BADERRNUM);
463 TTRACE3(
"MIDI msg = %02X %02X %02X\n", p.state, p.data1, p.data2 );
464 return m_Rst(::midiOutShortMsg(m_hMidi, p.msg));
471 if ( ! m_Rst(channel, vp[i]) )
479 mutable MMRESULT m_lastError;
#define loop(VAR, CNT)
loop構文.
void SetLastError(DWORD e)
[設定] ラストエラーコード設定.
bool ControlSendLevel(BYTE channel, BYTE controlNo, int level)
[設定] コントロールセンドレベル.
static UINT GetDeviceCount(void)
[取得] デバイス数取得.
bool Modulation(BYTE channel, BYTE modulation)
[設定] モジュレーション.
bool BankSelect(BYTE channel, BYTE msb, BYTE lsb)
[設定] バンクセレクト.
bool NoteOff(BYTE channel, BYTE note, BYTE velocity=0)
[設定] ノートオフ.
bool ProgramChange(BYTE channel, BYTE programNumber)
[設定] プログラムチェンジ.
bool ChorusSendLevel(BYTE channel, int level)
[設定] コーラスセンドレベル.
static CStr GetErrorString(DWORD e)
[取得] エラー文字列取得.
~CMidiMessage(void)
デストラクタ
bool NoteOn(BYTE channel, BYTE note, BYTE velocity=0)
[設定] ノートオン.
bool PitchBendSensitivity(BYTE channel, BYTE v)
[設定] ピッチベンドセンシビティ.
bool Panpot(BYTE channel, int pan)
[設定] パンポット.
bool Volume(BYTE channel, int volume)
[設定] ボリューム.
bool IsOpened(void) const
[確認] オープン確認.
void Close(void)
[設定] クローズ.
bool PitchBendChange(BYTE channel, int pitchBend=0)
[設定] ピッチベンドチェンジ.
bool Open(UINT dev=MIDI_MAPPER)
[設定] オープン.
bool ReverbSendLevel(BYTE channel, int level)
[設定] リバーブセンドレベル.
DWORD GetLastError(void) const
[取得] ラストエラーコード取得.
bool Expression(BYTE channel, int volume)
[設定] エクスプレッション.
CMidiMessage(void)
コンストラクタ
void ReleaseBuffer(void)
[操作] 割り当てたバッファを開放.
TYP * GetBuffer(size_t iLength=0)
[操作] 書き込みバッファ要求.
size_t GetSize(void) const
[取得] サイズ取得
void Reset(size_t l, const TYP *P)
[設定] 再設定