home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form Form1
- Caption = "Form1"
- ClientHeight = 3195
- ClientLeft = 60
- ClientTop = 345
- ClientWidth = 4680
- LinkTopic = "Form1"
- ScaleHeight = 3195
- ScaleWidth = 4680
- StartUpPosition = 3 'Windows Default
- Attribute VB_Name = "Form1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- '----------------------------------------------------------------------
- ' Visual Basic Game Programming For Teens
- ' MusicTest Program
- '----------------------------------------------------------------------
- Option Explicit
- Option Base 0
- 'main DirectX object
- Dim dx As DirectX8
- 'DirectMusic loader object
- Private dmLoader As DirectMusicLoader8
- 'DirectMusic performance object
- Private dmPerf As DirectMusicPerformance8
- 'DirectMusic segment object
- Private dmSeg As DirectMusicSegment8
- 'DirectMusic segment state object
- Private dmSegState As DirectMusicSegmentState8
- 'DirectMusic audio path object
- Private dmPath As DirectMusicAudioPath8
- 'DirectMusic audio parameters
- Dim dmA As DMUS_AUDIOPARAMS
- Private Sub Form_Load()
- 'set up line-by-line error checking
- On Local Error Resume Next
- 'create the DirectX object
- Set dx = New DirectX8
- 'create the DirectMusic loader object
- Set dmLoader = dx.DirectMusicLoaderCreate
- If Err.Number <> 0 Then
- MsgBox "Error creating DirectMusic loader object"
- Shutdown
- End If
- 'create the DirectMusic performance object
- Set dmPerf = dx.DirectMusicPerformanceCreate
- If Err.Number <> 0 Then
- MsgBox "Error creating DirectMusic performance object"
- Shutdown
- End If
- 'initialize DirectMusic
- dmPerf.InitAudio Me.hWnd, DMUS_AUDIOF_ALL, dmA
- If Err.Number <> 0 Then
- MsgBox "Error initializing DirectMusic audio system"
- Shutdown
- End If
- 'create the DirectMusic audio path object
- Set dmPath = dmPerf.CreateStandardAudioPath( _
- DMUS_APATH_DYNAMIC_3D, 64, True)
- If Err.Number <> 0 Then
- MsgBox "Error creating DirectMusic audio path object"
- Shutdown
- End If
- 'load the MIDI file
- If Not LoadMusic(App.Path & "\symphony.rmi") Then
- MsgBox "Error loading music file symphony.rmi"
- Shutdown
- End If
- 'print some music information to the immediate window
- Debug.Print "Length: " & dmSeg.GetLength
- Debug.Print "Name: " & dmSeg.GetName
- Debug.Print "Repeats: " & CBool(dmSeg.GetRepeats)
- Debug.Print "Clock time: " & dmPerf.GetClockTime
- Debug.Print "Music time: " & dmPerf.GetMusicTime
- Debug.Print "Latency time: " & dmPerf.GetLatencyTime
- PlayMusic
- End Sub
- Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
- Shutdown
- End Sub
- Public Function LoadMusic(sFile As String) As Boolean
- On Local Error Resume Next
- LoadMusic = False
- If Len(sFile) = 0 Then Exit Function
- 'remove any existing segment
- If Not (dmSeg Is Nothing) Then
- dmSeg.Unload dmPath
- Set dmSeg = Nothing
- End If
- 'load the MIDI file
- Set dmSeg = dmLoader.LoadSegment(sFile)
- If Err.Number <> 0 Then Exit Function
- dmSeg.SetStandardMidiFile
- 'download the music segment
- dmSeg.Download dmPath
- If Err.Number <> 0 Then Exit Function
- 'success
- LoadMusic = True
- End Function
- Private Sub PlayMusic()
- If dmSeg Is Nothing Then Exit Sub
- Set dmSegState = dmPerf.PlaySegmentEx(dmSeg, 0, 0, Nothing, dmPath)
- End Sub
- Private Sub StopMusic()
- If dmSeg Is Nothing Then Exit Sub
- dmPerf.StopEx dmSeg, 0, 0
- End Sub
- Private Sub Shutdown()
- 'stop music playback
- If Not (dmPerf Is Nothing) Then
- dmPerf.StopEx dmSeg, 0, 0
- dmPerf.CloseDown
- End If
- 'delete DirectMusic objects
- Set dmLoader = Nothing
- Set dmSeg = Nothing
- Set dmPath = Nothing
- Set dmPerf = Nothing
- Set dx = Nothing
- End
- End Sub
-