|
Option Explicit
Dim DX8 As New DirectX8
Dim MIDLoader As DirectMusicLoader8
Dim MIDSeg As DirectMusicSegment8
Dim MIDPerf As DirectMusicPerformance8
Dim MIDSegState As DirectMusicSegmentState8
Dim mtTime As Long
Dim GetStartTime As Long
Dim Offset As Long
Dim MIDInPause As Boolean
Private Sub cmd_Open_Click()
Set MIDLoader = Nothing
Set MIDLoader = DX8.DirectMusicLoaderCreate
Set MIDPerf = Nothing
Set MIDPerf = DX8.DirectMusicPerformanceCreate
Dim dmusAudio As DMUS_AUDIOPARAMS
MIDPerf.InitAudio Me.hWnd, DMUS_AUDIOF_ALL, dmusAudio, _
Nothing, DMUS_APATH_DYNAMIC_STEREO, 128
MIDPerf.SetMasterAutoDownload True
MIDPerf.AddNotificationType DMUS_NOTIFY_ON_SEGMENT
CDialog_Open.Filter = "MIDI Files (*.mid)|*.mid"
CDialog_Open.FileName = vbNullString
CDialog_Open.InitDir = App.Path
CDialog_Open.ShowOpen
If CDialog_Open.FileName <> vbNullString Then
Set MIDSeg = MIDLoader.LoadSegment(CDialog_Open.FileName)
MIDSeg.SetStandardMidiFile
MIDSeg.SetStartPoint 0
cmd_Play.Enabled = True
Else
Exit Sub
End If
End Sub
Private Sub cmd_Play_Click()
MIDSeg.SetStartPoint 0
If chk_Loop.Value = vbChecked Then
MIDSeg.SetRepeats -1
Else
MIDSeg.SetRepeats 0
End If
Set MIDSegState = MIDPerf.PlaySegmentEx( _
MIDSeg, DMUS_SEGF_DEFAULT, 0)
cmd_Open.Enabled = False
cmd_Play.Enabled = False
cmd_Pause.Enabled = True
cmd_Stop.Enabled = True
Timer1.Enabled = True
MIDInPause = False
End Sub
Private Sub cmd_Pause_Click()
If MIDPerf.IsPlaying(MIDSeg, MIDSegState) = True Then
MIDInPause = True
Timer1.Enabled = False
mtTime = MIDPerf.GetMusicTime()
GetStartTime = MIDSegState.GetStartTime()
MIDPerf.StopEx MIDSeg, 0, 0
Else
Offset = mtTime - GetStartTime + Offset + 1
MIDSeg.SetStartPoint Offset
Set MIDSegState = MIDPerf.PlaySegmentEx(MIDSeg, 0, 0)
MIDInPause = False
Timer1.Enabled = True
End If
End Sub
Private Sub cmd_Stop_Click()
MIDPerf.StopEx MIDSeg, 0, 0
cmd_Play.Enabled = True
cmd_Pause.Enabled = False
cmd_Stop.Enabled = False
cmd_Open.Enabled = True
Timer1.Enabled = False
MIDInPause = False
End Sub
Private Sub cmd_Close_Click()
If MIDSeg Is Nothing Then
End
Else
If MIDPerf.IsPlaying(MIDSeg, MIDSegState) Then
MIDPerf.StopEx MIDSeg, 0, 0
End If
Set MIDSegState = Nothing
Set MIDPerf = Nothing
Set MIDSeg = Nothing
Set MIDLoader = Nothing
Set DX8 = Nothing
End
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, _
UnloadMode As Integer)
cmd_Close_Click
End Sub
Private Sub Timer1_Timer()
If MIDInPause Then Exit Sub
If MIDPerf.IsPlaying(MIDSeg, MIDSegState) = False Then
Timer1.Enabled = False
cmd_Play.Enabled = True
cmd_Pause.Enabled = False
cmd_Stop.Enabled = False
cmd_Open.Enabled = True
End If
End Sub
|
|