midiOutShortMsg

概要

MIDIショートメッセージを送信する関数です。

対象言語

Visual C# .net, Visual Basic .net ( VB2003, VB2005 )

使用例

C#
/// <summary>
///
 4バイト以内のMIDIデータ(Short Message)を送信します。
/// </summary>
/// <param name="data">
送信するデータ。</param>
void SendShortMsg(byte[] data)
{
    byte[] sendData = new byte[4];
    for (i = 0; i < data.Length; i++)
    {
        sendData[i] = data[i];
    }
    int message = (sendData[3] << 24) | (sendData[2] << 16) | (sendData[1] << 8) | sendData[0];
    midiOutShortMsg(systemHandle, message);
}


[DllImport("winmm.dll")]
static extern int midiOutShortMsg(int hMidiOut, int dwMsg);

Visual Basic
''' <summary>
'''
 4バイト以内のMIDIデータ(Short Message)を送信します。
''' </summary>
''' <param name="data">
送信するデータ。</param>
Private Sub SendShortMsg(ByVal data As Byte())
    Dim sendData As Byte() = New Byte(3)
    Dim i As Integer
    For i = 0 To data.Length - 1
        sendData(i) = data(i)
    Next i
    Dim message As Integer = ((((sendData(3) << &H18) Or (sendData(2) << &H10)) Or (sendData(1) << 8)) Or sendData(0))
    midiOutShortMsg(systemHandle, message)
End Sub


Declare Function midiOutShortMsg Lib "winmm" (ByVal hMidiOut As IntegerByVal dwMsg As IntegerAs Integer

Memo

4バイト以内のMIDIメッセージは、ウィンドウメッセージとして直接送信します。

Next MIDIによる代替コード

C#
using NextMIDI;
using NextMIDI.DataElement;
using NextMIDI.MidiOutPort;


MidiCC midiCC = new MidiCC();

// CH 1 Hold ON

midiCC.CH = 0;
midiCC.Number = 64;
midiCC.Value = 127;

midiOut.SendData(midiCC, 0);

Visual Basic
Imports NextMIDI
Imports NextMIDI.DataElement
Imports NextMIDI.MidiOutPort


Dim myMidiCC As New MidiCC

' CH 1 Hold ON

myMidiCC.CH = 0
myMidiCC.Number = 64
myMidiCC.Value = 127

myMidiOut.SendData(myMidiCC, 0)

Top