By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,537 Members | 1,471 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,537 IT Pros & Developers. It's quick & easy.

Midi file: this is very very very difficult !

P: n/a

I need help on MIDI file,

and precisely about retrieving
few note values
(mainly the "Velocity" value,
corrisponding to the intensity
of a played note)
while the MIDI is playing.

(If you don't kow,
the "Velocity" value is a value
stored in the MIDI file).

- - - - -

I'm using DirectX (Dx7vb.dll)
to manage (Start, Stop ...)
the MIDI file,

but if my problem can be solved
also without using DirectX
or by using an external (free)
..dll or .ocx,
it is good the same.

- - - - -

Scenario (very simple scenario):

I'm playing a MIDI file using
the DirectX commands
(by the Dx7vb.dll file;
if you have DirectX8 or DirectX9
things should not be very different).
No problem in this.

Now I want to retrieve some "live" information
while the Midi file is playing,
so I decide it cold be a good solution
to implement a 'callback' function.
I found a snippet of code
that allows me to retrieve the information
about the Start, the Stop...
of the Midi file.
No problem in this.

See below, if you like,
the snippet of code that performs the
'callback' task
(note: if you don't already have
on your project
the lines of code that allow you
to play a Midi file,
this solely snippet of code won't work;
if you want that playing code
I'll provide you with it).

- - - - -


I don't want to retrieve
the Start, the Stop...
of the Midi file.
I want to retrieve some information
about the current played notes
(most of all their Velocity value).
I presume that I need to use the

and their
..Velocity sub-parameter
I should indicate the channel
I'm retrieving the played notes from

in a 'standard' Midi file there are 16 channels;
if it is not a 'standard' Midi
you have 1 big channel only,
but my program splits it
in 16 separated channels
so to ultimately have
a 16 channels Midi file)
when I build the 'callback' strucutre
I think I have to change the parameter
myPerf.AddNotificationType DMUS_NOTIFY_ON_SEGMENT
(see below the snippet of code,
under the sections 3 and 5 )
and use another parameter,
(maybe the

- - - - -
If you need more explanations
I'll povide you with links where to download

the Dx7vb.dll,
the playing code,
a 'standard' Midi file
more details...
- - - - -
I previously post this request in several NGs,
but I got no answers
(= nobody answered me).
I don't know because it is a difficult task
or because those NGs are poorly populated.

==== ==== ==== ==== =====
==== ==== ==== ==== =====
Callback snippet of code.
''' 1 On the References section
' of your VB project
' you have to absolutely
' reference the Dx7vb.dll file
' (you find it under the 'Project' menu),

''' 2 On the Declarations section

'among the other declarations, you have to add these:
Implements DirectXEvent 'creates the "DirectXEvent_DXCallback"
Private myEvent As Long 'An Event handle
Dim myPerf As DirectMusicPerformance

''' 3 On the Load or Initialize or whatever you like event,
but before you start playing the Midi file
'among the other initialization stuff, you have to add these:
Set myPerf = Dx.DirectMusicPerformanceCreate
Call myPerf.Init(Nothing, hwnd)
myPerf.SetPort -1, 1
myPerf.AddNotificationType DMUS_NOTIFY_ON_SEGMENT 'relay messages
about the segment
myEvent = Dx.CreateEvent(Me)
myPerf.SetNotificationHandle myEvent 'used to identify the messages

''' 4 On the DirectXEvent_DXCallback
'Private Sub DirectXEvent_DXCallback(ByVal eventid As Long)

If eventid = myEvent Then 'the message is our message


Select Case myMSG.lNotificationOption
Case Else
Debug.Print "MESSAGE: Unknown"
End Select

End If

'End Sub

''' 5 On the Unload event

'now we discard all
myPerf.RemoveNotificationType DMUS_NOTIFY_ON_SEGMENT
Dx.DestroyEvent myEvent
If ObjPtr(dmSeg) Then Set dmSeg = Nothing
If ObjPtr(dmLoader) Then Set dmLoader = Nothing
If ObjPtr(Dx) Then Set Dx = Nothing

==== ==== ==== ==== =====
==== ==== ==== ==== =====
Nov 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.