4.2.1 DirectMusic用の変数を準備
まずは、MIDIファイルを演奏する方法です。WAVファイルの場合と同じようにDirectXに関連するオブジェクトやデータ型の変数を使って行います。
変数とデータ型の定義
DirextXを使ってMIDIファイルを演奏するときは、次のようなオブジェクトや変数を定義します。なお、ここでのポイントは変数名ではなくAs以降の変数の型です、念のため…。

変数名はお好きな名前をつけてOKですが、最低限例で出ている型の変数が必要です。また、変数の型には普段はあまり見かけないような型が並んでいますが、それぞれの使い道は以下をどうぞ。

 ◆DirectX 7の場合
Dim objDrX     As New DirectX7
Dim objDMPerf  As DirectMusicPerformance
Dim objDMLdr   As DirectMusicLoader
Dim objDMSgmnt As DirectMusicSegment
Dim objDMSgtSt As DirectMusicSegmentState
 ※DirectX 7を参照設定に追加する必要があります。

 ◆DirectX 8の場合
Dim objDrX     As New DirectX8
Dim objDMPerf  As DirectMusicPerformance8
Dim objDMLdr   As DirectMusicLoader8
Dim objDMSgmnt As DirectMusicSegment8
Dim objDMSgtSt As DirectMusicSegmentState8
Dim sctParams  As DMUS_AUDIOPARAMS
 ※DirectX 8を参照設定に追加する必要があります。


DirextXオブジェクトの作成です。このオブジェクトを使うときはNew(インスタンスの作成)を付けます。

Dim objDrX     As New DirectX7 'DirectX 7のとき
 または
Dim objDrX     As New DirectX8 'DirectX 8のとき


DirectXを使ってMIDIファイルを再生するときの主役となるオブジェクトです。

Dim objDMPerf  As DirectMusicPerformance 'DirectX 7のとき
 または
Dim objDMPerf  As DirectMusicPerformance8 'DirectX 8のとき


MIDIファイルを読み込むために使うオブジェクトです。

Dim objDMSgtSt As DirectMusicLoader 'DirectX 7のとき
 または
Dim objDMSgtSt As DirectMusicLoader8 'DirectX 8のとき


再生したいMIDIファイルを入れておくためのオブジェクトです。複数のMIDIファイルを使うときは、Dim objDMSgmnt(20) As DirectMusicSegmentのように配列にして使うと便利です。ただし、同時に2つのMIDIを演奏することはできません

Dim objDMSgmnt As DirectMusicSegment 'DirectX 7のとき
 または
Dim objDMSgmnt As DirectMusicSegment8 'DirectX 8のとき


MIDIファイルを再生するために使うオブジェクトです。複数のMIDIファイルを使うときは、Dim objDMSgtSt(20) As DirectMusicSegmentStateのように配列にして使うと便利です。ただし、同時に2つのMIDIを演奏することはできません

Dim objDMSgtSt As DirectMusicSegmentState 'DirectX 7のとき
 または
Dim objDMSgtSt As DirectMusicSegmentState8 'DirectX 8のとき


DirectMusicPerformance8オブジェクトの初期設定時に使う構造体です。パラメタに使います。DirectX 8のときだけ必要です。

Dim sctParams  As DMUS_AUDIOPARAMS 'DirectX 8のみ!
Copyright(C) 1999-2006 結城圭介。 All rights reserved