Hello,
Below is code I use to get the length (time in milliseconds) of a MIDI file.
It works perfect provided there is only one one Tempo setting in the sequence.
I've attached 2 MIDI files that demonstrate the problem
TimeTest1.mid
contains 60 notes and the Tempo is set at 60 bmp
60 x 1 sec = 60 seconds
TimeTest2.mid
contains 60 notes and the Tempo of first 20 notes is set at 60 bmp, the last 40 notes Tempo is set at 120 bpm
20 x 1 sec + 40 x 1/2 sec = 40 seconds
Windows Media Player shows correctly 60 seconds for the first, and 40 seconds for the second
My code correctly reports 60 seconds for the first, and incorrectly reports 30 seconds for the second
Any help to get this working correctly using VB would be appreciated.
Below is code I use to get the length (time in milliseconds) of a MIDI file.
It works perfect provided there is only one one Tempo setting in the sequence.
I've attached 2 MIDI files that demonstrate the problem
TimeTest1.mid
contains 60 notes and the Tempo is set at 60 bmp
60 x 1 sec = 60 seconds
TimeTest2.mid
contains 60 notes and the Tempo of first 20 notes is set at 60 bmp, the last 40 notes Tempo is set at 120 bpm
20 x 1 sec + 40 x 1/2 sec = 40 seconds
Windows Media Player shows correctly 60 seconds for the first, and 40 seconds for the second
My code correctly reports 60 seconds for the first, and incorrectly reports 30 seconds for the second
Any help to get this working correctly using VB would be appreciated.
Code:
Option Explicit
Private Declare Function mciSendStringW Lib "winmm.dll" _
(ByVal lpszCommand As Long, _
Optional ByVal lpszReturnString As Long, _
Optional ByVal cchReturn As Long, _
Optional ByVal hWndCallback As Long) As Long
Private Sub Form_Load()
Command1.Caption = "Get MIDI length"
End Sub
Private Sub Command1_Click()
Dim ret As Long
Dim buf As String
Dim midiLength As String
'ret = mciSendStringW(StrPtr("open """ & App.Path & "\TimeTest1.mid"" type sequencer alias myMIDI"))
ret = mciSendStringW(StrPtr("open """ & App.Path & "\TimeTest2.mid"" type sequencer alias myMIDI"))
ret = mciSendStringW(StrPtr("set myMIDI time format milliseconds"))
buf = Space$(255&)
ret = mciSendStringW(StrPtr("status myMIDI length"), StrPtr(buf), Len(buf))
midiLength = Val(buf)
MsgBox "MIDI length: " & midiLength & " milliseconds"
mciSendStringW StrPtr("close myMIDI")
End Sub