home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form MidiPlayer
- BackColor = &H00FFFFFF&
- Caption = "Midi Demo"
- ClientHeight = 5460
- ClientLeft = 1560
- ClientTop = 2175
- ClientWidth = 6300
- ClipControls = 0 'False
- ForeColor = &H00C00000&
- Height = 6150
- KeyPreview = -1 'True
- Left = 1500
- LinkTopic = "Form1"
- MaxButton = 0 'False
- ScaleHeight = 5460
- ScaleWidth = 6300
- Top = 1545
- Width = 6420
- Begin CommandButton BTN_ClearList
- Caption = "&Clear"
- Height = 400
- Left = 2400
- TabIndex = 14
- Top = 3500
- Width = 1000
- End
- Begin CommandButton BTN_QueueAll
- Caption = "Queue &All"
- Height = 400
- Left = 2400
- TabIndex = 13
- Top = 2900
- Width = 1000
- End
- Begin CommandButton BTN_Queue
- Caption = "&Queue"
- Height = 400
- Left = 2400
- TabIndex = 12
- Top = 2300
- Width = 1000
- End
- Begin ListBox PlayList
- Height = 4710
- Left = 3795
- TabIndex = 5
- Top = 500
- Width = 2370
- End
- Begin FileListBox File1
- Height = 3345
- Left = 100
- MultiSelect = 2 'Extended
- TabIndex = 11
- Top = 1875
- Width = 1800
- End
- Begin DirListBox Dir1
- Height = 930
- Left = 100
- TabIndex = 10
- Top = 870
- Width = 1800
- End
- Begin DriveListBox Drive1
- Height = 315
- Left = 100
- TabIndex = 9
- Top = 500
- Width = 1800
- End
- Begin CommandButton BTN_Pause
- Caption = "Pa&use"
- Height = 400
- Left = 2400
- TabIndex = 2
- Top = 1700
- Width = 1000
- End
- Begin CommandButton BTN_Exit
- Caption = "&Exit"
- Height = 400
- Left = 2400
- TabIndex = 4
- Top = 4700
- Width = 1000
- End
- Begin CommandButton BTN_Stop
- Caption = "&Stop"
- Height = 400
- Left = 2400
- TabIndex = 3
- Top = 4100
- Width = 1000
- End
- Begin CommandButton BTN_Next
- Caption = "&Next"
- Height = 400
- Left = 2400
- TabIndex = 1
- Top = 1100
- Width = 1000
- End
- Begin CommandButton BTN_Play
- Caption = "&Play"
- Height = 400
- Left = 2400
- TabIndex = 0
- Top = 500
- Width = 1000
- End
- Begin Label Label1
- Caption = "Total Time:"
- Height = 225
- Left = 100
- TabIndex = 6
- Top = 210
- Width = 2100
- End
- Begin Label Label3
- Caption = "Elapsed Time:"
- Height = 225
- Left = 3765
- TabIndex = 8
- Top = 210
- Width = 1245
- End
- Begin Label lblElapsedTime
- Caption = "00:00"
- Height = 225
- Left = 5025
- TabIndex = 7
- Top = 210
- Width = 630
- End
- Begin Menu MNU_File
- Caption = "&File"
- Begin Menu MNU_MidiMap
- Caption = "&Run Midi Mapper"
- End
- Begin Menu Separator2
- Caption = "-"
- End
- Begin Menu MNU_Exit
- Caption = "&Exit"
- End
- End
- Begin Menu MNU_About
- Caption = "&About"
- End
- ' Disclaimer of Warranty:
- ' This software and the accompanying files are provided "as is"
- ' and without warranties as to performance of the software and
- ' the accompanying files or any other warranties whether expressed
- ' or implied. No warranty of fitness for a particular purpose
- ' is offered.
- ' You may not sell this software or it's source code.
- ' You may use this code in any way you find useful.
- Declare Function mciSendString Lib "mmsystem" (ByVal lpstrCommand$, ByVal lpstrReturnStr As Any, ByVal wReturnLen%, ByVal hCallBack%) As Long
- Declare Function mciGetErrorString Lib "mmsystem" (ByVal dwError As Long, ByVal lpstrBuffer As Any, ByVal wLength As Integer) As Integer
- Declare Function GetModuleUsage% Lib "Kernel" (ByVal hModule%)
- Option Base 1 'Set arrays to use a base of 1
- Dim SongPath() As String 'array to store path and file name of the midi file
- Dim NumSongsQueued As Integer 'Total number of songs queued in the Play List
- Dim Number As Integer 'The song that is currently playing
- Dim TotalTime As String 'Playing time of all queued songs in format "(HH:MM:SS)"
- Dim TTime As Single 'Playing time of all queued songs for calculations
- 'Flags
- 'All flags are either true or false
- Dim StopPlayback, PausePlayback, NextSong As Integer 'Flags for controlling playback
- Dim SongPlaying As Integer 'Flag to let the whole program know whenever a song is playing
- Dim UnPaused As Integer 'Flag for indicating when a song has been paused and then started again
- Sub BTN_ClearList_Click ()
- 'Remove each item in the Play List
- If PlayList.ListCount > 0 Then
- For I = 0 To PlayList.ListCount - 1
- PlayList.RemoveItem 0
- Next
- End If
- 'Start with "clean" array
- Erase SongPath
- 'Reset variables
- NumSongsQueued = 0
- TTime = 0
- TotalTime = "00:00:00"
- label1.Caption = "Total Time: " + TotalTime
- BTN_Play.Enabled = False
- End Sub
- Sub BTN_Exit_Click ()
- Unload MidiPlayer
- End Sub
- Sub BTN_Next_Click ()
- 'This routine will stop playback of the current song and
- 'and skip to either the next song in the list, or jump
- 'to any song which the user highlights in the play list.
- Dim Ret, ErrorRet As Integer
- Dim mciErrorText As String
- Dim mciBuffer As Integer
- mciBuffer = 255
- mciErrorText = Space(255)
- 'Set NextSong flag to true
- NextSong = True
- 'Close the song that is playing.
- 'This automatically stops playback
- Ret = mciSendString("close all", 0&, 0, 0)
- If Ret <> 0 Then GoTo mciError3
-
- 'If the song highlighted in the Play List is not
- 'the song that is currently playing then
- 'set Number in the For..Next loop in BTN_Play_Click event
- 'to the selected song in the Play List
- If PlayList.ListIndex <> Number - 1 Then
- Number = PlayList.ListIndex
- End If
- Exit Sub
- mciError3:
- ErrorRet = mciGetErrorString(Ret, mciErrorText, mciBuffer)
- If ErrorRet = 1 Then
- Msg$ = mciErrorText
- MsgBox Msg$, 48, "Midi Error"
- Else
- MsgBox "An unknown error occured", 16, "Error"
- End If
- Ret = mciSendString("close all", 0&, 0, 0)
- End Sub
- Sub BTN_Pause_Click ()
- Dim Ret, ErrorRet As Integer
- Dim mciErrorText As String
- Dim mciBuffer As Integer
- mciBuffer = 255
- mciErrorText = Space(255)
- UnPaused = False
- If LCase$(Left$(BTN_Pause.Caption, 2)) = "pa" Then
- BTN_Pause.Caption = "Res&ume"
- 'Pause playback of the song
- Ret = mciSendString("pause MidiFile", 0&, 0, 0)
- If Ret <> 0 Then GoTo mciError1
- ElseIf LCase$(Left$(BTN_Pause.Caption, 2)) = "re" Then
- BTN_Pause.Caption = "Pa&use"
- Ret = mciSendString("play MidiFile", 0&, 0, 0)
- If Ret <> 0 Then GoTo mciError1
- 'The MCI sequencer doesn't support the RESUME command.
- 'The PLAY command will work fine, but the STATUS MODE command
- 'will still return PAUSED rather than STOPPED. Therefore,
- 'the program must be informed of this another way.
- UnPaused = True
- End If
- Exit Sub
- mciError1:
- ErrorRet = mciGetErrorString(Ret, mciErrorText, mciBuffer)
- If ErrorRet = 1 Then
- Msg$ = mciErrorText
- MsgBox Msg$, 48, "Midi Error"
- Else
- MsgBox "An unknown error occured", 16, "Error"
- End If
- Ret = mciSendString("close all", 0&, 0, 0)
- End Sub
- Sub BTN_Play_Click ()
- Dim Ret, ErrorRet As Integer
- Dim mciErrorText As String
- Dim mciBuffer As Integer
- Dim PlayDone As Integer, Start As Integer
- mciBuffer = 255
- mciErrorText = Space(255)
- Start = PlayList.ListIndex + 1
- 'If Play is pressed and nothing is selected in the Play List,
- 'Start will be 0 (because PlayList.ListIndex = -1), so it is
- 'necessary to set Start = 1.
- If Start = 0 Then
- Start = 1
- End If
- For Number = Start To NumSongsQueued
-
- StopPlayback = False
- 'PausePlayback = False
- NextSong = False
- PlayDone = False
- 'NewSong = True
- 'This line opens the sequencer with the specified file.
- Ret = mciSendString("open " + SongPath(Number) + " type sequencer alias MidiFile", 0&, 0, 0)
- 'mciSendString always returns 0 if successful. Any other value indicates
- 'that an error occcured.
- If Ret <> 0 Then GoTo mciError
-
- 'This lines plays the file specified in the open command
- Ret = mciSendString("play MidiFile", 0&, 0, 0)
- If Ret <> 0 Then GoTo mciError
-
- 'Highlight the song that is currently playing
- PlayList.Selected(Number - 1) = True
- SongPlaying = True
-
- 'Change the enabled property of all buttons and the menu item to start midi mapper
- BTN_Play.Enabled = False
- BTN_Next.Enabled = True
- BTN_Pause.Enabled = True
- BTN_Stop.Enabled = True
- BTN_Queue.Enabled = False
- BTN_QueueAll.Enabled = False
- MNU_MidiMap.Enabled = False
- BTN_ClearList.Enabled = False
-
- MLen% = 255
- Msg$ = String$(255, 0)
-
- 'Set the proper time format
- Stat$ = "set MidiFile time format smpte 30 drop"
- Ret = mciSendString(Stat$, Msg$, MLen%, MidiPlayer.hWnd)
-
- 'Execute the following DO loop while the song is playing
- 'When the msg$ "stopped" is returned, exit the loop.
- 'Also exit the loop if the Next or Stop button are pressed
- 'This loop is used to yield control to Windows while a song is playing
- 'It also returns the status of the song and the elapsed time.
-
- Do Until StopPlayback Or NextSong Or PlayDone
- 'A slower computer will obviously execute this loop less often.
- 'The only effect this should have is that the elapsed time
- 'will be updated less frequently causing the seconds to skip
- 'some increments. This probably would only happen on a 386
- 'computer.
- 'Sending Stat$ will return the status (playing, stopped, paused)
- Stat$ = "status MidiFile mode"
-
- 'In order for these functions to work properly,
- 'Msg$ and MMErr$ must be a fixed-length strings
- Ret = mciSendString(Stat$, Msg$, MLen%, MidiPlayer.hWnd)
-
- 'If the playback had been paused, MCI sequencer will still
- 'return PAUSED instead of STOPPED after the song has finished.
- 'Therefore this must be checked another way.
- If InStr(Msg$, "stopped") Or (InStr(Msg$, "paused") And UnPaused) Then
- PlayDone = True
- UnPaused = False
- End If
-
- 'Send Stat$ to return the elapsed time
- Stat$ = "status MidiFile position"
- Ret = mciSendString(Stat$, Msg$, MLen%, MidiPlayer.hWnd)
-
- lblElapsedTime.Caption = Mid$(Msg$, 4, 5)
-
- 'Yield control to Windows
- DoEvents
- Loop
- If Not NextSong Then
- 'Close midi file and sequencer device
- Ret = mciSendString("close all", 0&, 0, 0)
- If Ret <> 0 Then GoTo mciError
- End If
-
- 'If MNU_Reset.Checked Then
- ' MidiReset
- 'End If
-
- 'StopPlayback is only true if the Stop button was clicked
- If StopPlayback Then Exit For
- Next Number
-
- 'When the For..Next loop completes normally, Number is going
- 'to be incremented to one higher than what the array is dimensioned for.
- 'Therefore, reset Number to the # of queued songs.
- If Number > NumSongsQueued Then
- Number = NumSongsQueued
- PlayList.Selected(Number - 1) = False
- End If
- BTN_Play.Enabled = True
- BTN_Next.Enabled = False
- BTN_Pause.Enabled = False
- BTN_Stop.Enabled = False
- BTN_Queue.Enabled = True
- BTN_QueueAll.Enabled = True
- MNU_MidiMap.Enabled = True
- BTN_Exit.Enabled = True
- BTN_ClearList.Enabled = True
- SongPlaying = False
- Screen.MousePointer = 0
- Exit Sub
- mciError:
- Screen.MousePointer = 0
- ErrorRet = mciGetErrorString(Ret, mciErrorText, mciBuffer)
- If ErrorRet = 1 Then
- Msg$ = mciErrorText
- MsgBox Msg$, 48, "Midi Error"
- Else
- MsgBox "An unknown error occured", 16, "Error"
- End If
- Ret = mciSendString("close all", 0&, 0, 0)
- End Sub
- Sub BTN_Queue_Click ()
- Screen.MousePointer = 11
- For I = 0 To File1.ListCount - 1
- If File1.Selected(I) Then
-
- File1.Selected(I) = False
- 'Increment the number of queued songs and redim the arrays
- NumSongsQueued = NumSongsQueued + 1
- ReDim Preserve SongPath(NumSongsQueued)
-
- SongPath(NumSongsQueued) = File1.Path + "\" + File1.List(I)
- SongFileName = File1.List(I)
- If IsSongQueued(SongPath(NumSongsQueued)) Then
- Msg$ = SongPath(NumSongsQueued) + CRLF
- Msg$ = Msg$ + "This song is already in the Play List." + CRLF
- Msg$ = Msg$ + "Do you want to queue it again?"
- Ans% = MsgBox(Msg$, 36)
- If Ans% = 7 Then
- NumSongsQueued = NumSongsQueued - 1
- ReDim Preserve SongPath(NumSongsQueued)
- GoTo NextSong
- End If
- End If
- GetTime SongPath(NumSongsQueued)
- 'Add the song to the Play List
- PlayList.AddItem SongFileName + " (" + SongLength + ")"
-
- 'Scroll the list of songs, un-select it, and update the total time label
- PlayList.ListIndex = NumSongsQueued - 1
- PlayList.Selected(PlayList.ListIndex) = False
- label1.Caption = "Total Time: " + TotalTime
- End If
- NextSong:
- Next I
- If PlayList.ListCount <> 0 Then
- BTN_Play.Enabled = True
- End If
- Screen.MousePointer = 0
- End Sub
- Sub BTN_QueueAll_Click ()
- ReDim SongPath(1)
- 'If any songs are already queued, clear the Play List
- If PlayList.ListCount > 0 Then
- BTN_ClearList_Click
- End If
- Screen.MousePointer = 11
- For I = 0 To File1.ListCount - 1
- NumSongsQueued = NumSongsQueued + 1
- ReDim Preserve SongPath(NumSongsQueued)
- SongPath(NumSongsQueued) = File1.Path + "\" + File1.List(I)
- SongFileName = File1.List(I)
-
- Song$ = SongPath(NumSongsQueued)
- Call GetTime(Song$)
- label1.Caption = "Total Time: " + TotalTime
-
- PlayList.AddItem SongFileName + " (" + SongLength + ")"
- PlayList.ListIndex = NumSongsQueued - 1
- PlayList.Selected(PlayList.ListIndex) = False
- Next I
- If PlayList.ListCount <> 0 Then
- BTN_Play.Enabled = True
- End If
- Screen.MousePointer = 0
- End Sub
- Sub BTN_Stop_Click ()
- Screen.MousePointer = 11
- Ret = mciSendString("stop MidiFile", 0&, 0, 0)
- StopPlayback = True
- DoEvents
- SongPlaying = False
- Ret = mciSendString("Close All", 0&, 0, 0)
- End Sub
- Function CanPlay ()
- 'This function determines if the MCIsequencer and MidiMapper
- 'are installed on a system by attempting to open the sequencer
- 'and checking the SYSTEM.INI file.
- 'Returns 0 if all is well
- 'Returns 1 if mcisequencer not installed
- 'Returns 2 if Midi Mapper not installed
- 'Returns 3 of NEITHER device is installed
- Dim Ret, ErrorRet, RetVal As Integer
- Dim mciErrorText As String * 255
- Dim mciBuffer As Integer
- mciBuffer = 255
- 'mciErrorText = Space(255)
- Dim WinDir1 As String * 128
- Dim WinDirSize As Integer
- WinDirSize = 128
- Dim Mapper As String * 128
- Dim MapperSize As Integer
- MapperSize = 128
- CanPlay = False
- Ret = mciSendString("open sequencer", 0&, 0, 0)
- 'If the OPEN failed, set function return value to 1
- 'A variable must be used and then the value of that variable
- 'assigned to the function's return value, otherwise, the function
- 'could be called recursively.
- If Ret <> 0 Then
- RetVal = 1
- End If
- 'Use the line below if the mciSendString function was unsuccessful
- 'and you want to get the associated error message. This is not
- 'neccessary in this routine.
- 'If Ret <> 0 Then GoTo mciError2
- 'Need to get the Windows directory
- Ret = GetWindowsDirectory(WinDir1, WinDirSize)
- WinDir = LCase(Left$(WinDir1, Ret))
- SysIniFilePath = WinDir + "\system.ini"
- 'Since the sequencer will open properly even if Midi Mapper is not installed,
- 'check for this in the system.ini file
- a% = GetPrivateProfileString("Drivers", "MidiMapper", "None", Mapper, MapperSize, SysIniFilePath)
- 'If there is no line for the Midi Mapper in system.ini,
- 'add 2 to return value
- If InStr(Mapper, "None") Then
- 'This is where the function would be recursive if a variable
- 'were not used.
- RetVal = RetVal + 2
- End If
- 'Close the sequencer
- Ret = mciSendString("close all", 0&, 0, 0)
- CanPlay = RetVal
- Exit Function
- mciError2:
- ErrorRet = mciGetErrorString(Ret, mciErrorText, mciBuffer)
- If ErrorRet = 1 Then
- Msg$ = mciErrorText
- MsgBox Msg$, 48, "Midi Error"
- Else
- MsgBox "An unknown error occured", 16, "Error"
- End If
- Ret = mciSendString("close all", 0&, 0, 0)
- BTN_Stop_Click
- End Function
- Sub Dir1_Change ()
- File1.Path = Dir1.Path
- End Sub
- Sub Drive1_Change ()
- Dir1.Path = Drive1.Drive
- End Sub
- Sub File1_DblClick ()
- BTN_Queue_Click
- End Sub
- Sub File1_KeyPress (KeyAscii As Integer)
- If KeyAscii = 13 Then BTN_Queue_Click
- End Sub
- Sub Form_Load ()
- 'Center the window on the desktop
- Move (Screen.Width - Width) \ 2, ((Screen.Height - Height) \ 2 - 200)
- 'Initialize variables
- NumSongsQueued = 0
- Index = 0
- TotalTime = "00:00:00"
- label1.Caption = "Total Time: " + TotalTime
- BTN_Play.Enabled = False
- BTN_Next.Enabled = False
- BTN_Pause.Enabled = False
- BTN_Stop.Enabled = False
- Screen.MousePointer = 11
- File1.Pattern = "*.mid"
- Me.Show
- 'Define the Carriage Return Line Feed
- CRLF = Chr$(13) + Chr$(10)
- 'Determine if the MCIsequencer and Midi Mapper are installed
- Result% = CanPlay()
- Select Case Result%
- Case 0
- 'Everything OK, continue with program
- Case 1 'MCIsequencer not installed
- Msg$ = "The MCI sequencer driver is not installed. "
- Msg$ = Msg$ + "This driver MUST be installed before you can use the player. "
- Msg$ = Msg$ + "See your Windows user guide for information on installing the MCI sequencer."
- MsgBox Msg$, 16
- End
- Case 2 'Midi Mapper not installed
- Msg$ = "The Midi Mapper is not installed. "
- Msg$ = Msg$ + "This driver MUST be installed before you can use the player. "
- Msg$ = Msg$ + "See your Windows user guide for information on installing the Midi Mapper."
- MsgBox Msg$, 16
- End
- Case 3 'Neither is installed
- Msg$ = "The MCIsequencer AND the Midi Mapper are not installed. "
- Msg$ = Msg$ + "These drivers MUST BOTH be installed before you can use the player. "
- Msg$ = Msg$ + "See your Windows user guide for information on installing these drivers."
- MsgBox Msg$, 16
- End
- End Select
- File1.SetFocus
- Screen.MousePointer = 0
- End Sub
- Sub Form_Unload (Cancel As Integer)
- 'If SongPlaying Then
- ' Cancel = True
- ' Exit Sub
- 'End If
- 'Ensure any open devices are closed before exiting
- Ret% = mciSendString("close all", 0&, 0, 0)
- DoEvents
- Erase SongPath
- End
- End Sub
- Sub GetTime (Song As String)
- 'This sub retrieves the time of a single midi file
- Dim Ret, ErrorRet As Integer
- Dim mciErrorText As String
- Dim mciBuffer As Integer
- mciBuffer = 255
- mciErrorText = Space(255)
- MLen% = 255
- Msg$ = String$(255, 0)
- MMErr$ = String$(255, 0)
- 'Open the midi file
- Ret = mciSendString("open " + Song + " type sequencer alias TimeInfo", 0&, 0, 0)
- 'Set the appropriate time format
- Stat$ = "set TimeInfo time format smpte 30 drop"
- Ret = mciSendString(Stat$, Msg$, MLen%, MidiPlayer.hWnd)
- 'Get the playing time of the opened midi file
- Stat$ = "status TimeInfo length"
- Ret = mciSendString(Stat$, Msg$, MLen%, MidiPlayer.hWnd)
- If Ret <> 0 Then GoTo mciError5
- 'Trim the string down to just the needed info
- SongLength = Mid$(Left$(Msg$, 11), 4, 5)
- 'If SongLength begins with a 0, eliminate it
- If Left$(SongLength, 1) = "0" Then
- SongLength = Mid$(SongLength, 2)
- End If
- 'Call the Sub to accumulate the length of all songs queued
- GetTotalTime
- 'Close the device
- Ret = mciSendString("close all", 0&, 0, 0)
- 'Make sure Windows has processed all events
- DoEvents
- Exit Sub
- mciError5:
- ErrorRet = mciGetErrorString(Ret, mciErrorText, mciBuffer)
- If ErrorRet = 1 Then
- Msg$ = mciErrorText
- MsgBox Msg$, 48, "Midi Error"
- Else
- MsgBox "An unknown error occured", 16, "Error"
- End If
- Ret = mciSendString("close all", 0&, 0, 0)
- End Sub
- Sub GetTotalTime ()
- 'This sub accumulates the time of all songs as they are queued
- On Error GoTo TimeError
- ColonPosition = InStr(SongLength, ":")
- Minutes = Val(Mid$(SongLength, 1, ColonPosition - 1))
- 'Seconds are converted to a decimal value
- Seconds = Val(Mid$(SongLength, ColonPosition + 1)) / 60
- SongTime = Minutes + Seconds
- 'Since TotalTime is used a variable elsewhere in the program,
- 'use TTime instead
- TTime = TTime + SongTime
- DecimalPosition = InStr(Trim$(Str$(TTime)), ".")
- 'If there's no decimal then seconds are 0, and ".00" must be appended
- 'to TT$
- If DecimalPosition = 0 Then
- 'TT$ is the total time stored as a string
- TT$ = Trim$(Str$(TTime)) + ".00"
- DecimalPosition = InStr(TT$, ".")
- Else
- TT$ = Mid$(Trim$(Str$(TTime)), 1, DecimalPosition + 2)
- If Len(Mid$(TT$, DecimalPosition + 1)) = 1 Then
- TT$ = TT$ & "0"
- End If
- End If
- 'Convert the seconds from decimal back to standard time
- Seconds = Val(Mid$(TT$, DecimalPosition + 1))
- Seconds = Seconds * .6
- 'Find the position of the decimal point
- SecsDecimalPos = InStr(Str$(Seconds), ".")
- 'Do some rounding off if necessary
- If SecsDecimalPos > 0 Then
- If Mid(Seconds, SecsDecimalPos, 1) > 5 Then
- Seconds = Fix(Seconds)
- Seconds = Seconds + 1
- Else
- Seconds = Fix(Seconds)
- End If
- End If
- 'Get the total number of minutes
- Minutes = Val(Mid$(TT$, 1, DecimalPosition - 1))
- 'Compute the hours and the remaining minutes
- Hours = Minutes \ 60
- Minutes = Minutes - (Hours * 60)
- 'Convert each time unit to a string
- Secs$ = Trim$(Str$(Seconds))
- Mins$ = Trim$(Str$(Minutes))
- Hrs$ = Trim$(Str$(Hours))
- 'If the number of seconds, minutes, or hours is a single digit,
- 'place a 0 in front
- If Len(Secs$) = 1 Then
- Secs$ = "0" + Secs$
- End If
- If Len(Mins$) = 1 Then
- Mins$ = "0" + Mins$
- End If
- If Len(Hrs$) = 1 Then
- Hrs$ = "0" + Hrs$
- End If
- 'Create the total time string
- TotalTime = Hrs$ + ":" + Mins$ + ":" + Secs$
- Exit Sub
- TimeError:
- Msg$ = "An error occurred while determining the time of the midi file. "
- Msg$ = Msg$ + "The program can continue, but the Total Time will not be accurate."
- MsgBox Msg$, 48, "Non-Critical Error"
- Resume Next
- End Sub
- Function IsSongQueued (SongQueued As String) As Integer
- IsSongQueued = False
- For I = 1 To NumSongsQueued - 1
- If SongPath(I) = SongQueued Then
- IsSongQueued = True
- Exit For
- End If
- Next I
- End Function
- Sub MNU_About_Click ()
- AboutBox.Show 1
- End Sub
- Sub MNU_Exit_Click ()
- BTN_Exit_Click
- End Sub
- Sub MNU_MidiMap_Click ()
- On Error GoTo MidiMapErr
- 'Shell to the Midi Mapper
- X% = Shell("control midi mapper", 1)
- 'Yield to Windows and disable the main form while
- 'the midi mapper is running. This loop continues
- 'until the shelled app has been closed.
- While GetModuleUsage(X%) > 0
- z% = DoEvents()
- MidiPlayer.Enabled = False
- Wend
- MidiPlayer.Enabled = True
- MidiPlayer.SetFocus
- Exit Sub
- MidiMapErr:
- On Error GoTo 0
- MsgBox "Could not start Midi Mapper", 16
- Exit Sub
- End Sub
- Sub PlayList_DblClick ()
- If SongPlaying Then Exit Sub
- SelectedItemInList = PlayList.ListIndex
- 'Remove the highlighted item from the array
- If SelectedItemInList + 1 = NumSongsQueued Then 'removing the last item in list
- SongPath(NumSongsQueued) = ""
- Else
- 'Move all entries in the list that follow the deleted entry
- 'up 1 in the array
- For I = SelectedItemInList + 1 To NumSongsQueued - 1
- SongPath(I) = SongPath(I + 1)
- Next
- End If
- SubtractTime
- label1.Caption = "Total Time: " + TotalTime
- PlayList.RemoveItem SelectedItemInList
- NumSongsQueued = PlayList.ListCount
- If NumSongsQueued > 0 Then
- 'ReDim the array to equal the # of songs in the Play List
- ReDim Preserve SongPath(NumSongsQueued)
- Else
- BTN_Play.Enabled = False
- Erase SongPath
- TTime = 0
- TotalTime = "00:00:00"
- label1.Caption = "Total Time: " + TotalTime
- End If
- End Sub
- Sub SubtractTime ()
- 'This procedure is very similiar to GetTotalTime but it naturally
- 'subtracts the song's time instead of adding it
- 'Get the song's time from the entry in the play list
- Tyme$ = Right$(PlayList.List(PlayList.ListIndex), 7)
- ColonPosition = InStr(Tyme$, ":")
- FirstParen = InStr(Tyme$, "(")
- Minutes = Val(Mid$(Tyme$, FirstParen + 1, ColonPosition - FirstParen - 1))
- Seconds = Val(Mid$(Tyme$, ColonPosition + 1, 2)) / 60
- SongTime = Minutes + Seconds
- TTime = TTime - SongTime
- DecimalPosition = InStr(Trim$(Str$(TTime)), ".")
- 'If there's no decimal then seconds are 0, and ".00" must be appended
- 'to TT$
- If DecimalPosition = 0 Then
- TT$ = Trim$(Str$(TTime)) + ".00"
- DecimalPosition = InStr(TT$, ".")
- Else
- TT$ = Mid$(Trim$(Str$(TTime)), 1, DecimalPosition + 2)
- If Len(Mid$(TT$, DecimalPosition + 1)) = 1 Then
- TT$ = TT$ & "0"
- End If
- End If
- 'Convert the seconds from decimal to the standard
- 'number of seconds
- Seconds = Val(Mid$(TT$, DecimalPosition + 1))
- Seconds = Seconds * .6
- 'If there is a decimal part to the seconds,
- 'round it off to the closest integer
- SecsDecimalPos = InStr(Str$(Seconds), ".")
- If SecsDecimalPos > 0 Then
- If Mid(Seconds, SecsDecimalPos, 1) > 5 Then
- Seconds = Fix(Seconds)
- Seconds = Seconds + 1
- Else
- Seconds = Fix(Seconds)
- End If
- End If
- 'Get the total number of minutes
- Minutes = Val(Mid$(TT$, 1, DecimalPosition - 1))
- 'Compute the hours and the remaining minutes
- Hours = Minutes \ 60
- Minutes = Minutes - (Hours * 60)
- 'Convert each time unit to a string
- Secs$ = Trim$(Str$(Seconds))
- Mins$ = Trim$(Str$(Minutes))
- Hrs$ = Trim$(Str$(Hours))
- 'If the number of seconds, minutes, or hours is a single digit,
- 'place a 0 in front
- If Len(Secs$) = 1 Then
- Secs$ = "0" + Secs$
- End If
- If Len(Mins$) = 1 Then
- Mins$ = "0" + Mins$
- End If
- If Len(Hrs$) = 1 Then
- Hrs$ = "0" + Hrs$
- End If
- 'Create the total time string
- TotalTime = Hrs$ + ":" + Mins$ + ":" + Secs$
- End Sub
-