Manipulate MIDI-Files

Talk about all things "KVR Developer Challenge" related.
Post Reply New Topic
RELATED
PRODUCTS

Post

Helo,

in a Visual-Basic-program, we need to read a midi-file and manipulate the speed and the pitchvalue (transpose in halftone-steps) while playing the file.
therefore we would like to get a OCX-Control or a DLL for use in Visual Basic 6 or Visual Basic.NET

can you help us?
thank you in advance.

Bernhard

Post

Hi, you could use my MIDIX.ocx, has 3 controls, a MIDIIOCTrl, MIDIFileCtrl, and MIDIToolsCtrl (just a bunch of not so MIDI related functions).

It lacks documentation, but the MIDIX.odl shows all events and functions. Also check the MIDI_Player.hta demo, it shows how to load and play a MIDI file (it's just an html file renamed as hta, using vbscript).
To change tempo in real time, check the GetTimeAt function, where you can add a multiplier to change the tempo.

http://homepage.hispeed.ch/mbncp/download/MIDIX.zip

Post

Hi, thank you very much! Change tempo is easy, but where can I transpose the
midi-notes?

thank you in advance again.

Post

When you call MidiFile.ReadMidiFile(mfp, "c:\myfile.mid"), mfp is an array containing all MIDI tracks. Then each track is an array of events, where each event is an array of 2 elements, where the first one is the timestamp, and the second one an array of bytes that represent the MIDI data.
So,
track is the track number in the range 0 to Ubound(mfp) ' 0 base
event is the event number in the range 0 to UBound(mfp(track))
then we have:
mfp(track)(event)(0) is the timestamp
mfp(track)(event)(1)(0) is the status byte
mfp(track)(event)(1)(1) is the first data byte
mfp(track)(event)(1)(2) is the second data byte
For META (status = &HFF) events and SYSEX (status = &HF0), you can get more data bytes.

But in your case, if the status is within &H90 to &H9F and the velocity > 0 (second data byte), it's a NOTE ON event, so offset the first data byte, which in this case is the key pitch.
Example, Transpose 2 semi-tones:
mfp(track)(event)(1)(1) = mfp(track)(event)(1)(1) + 2
But make sure to store that value in an array, so when you get the note off message (either a note off &H80-&H8F, or a note on with velo = 0), apply the same transpose value.

Hope this helps :oops:

Post Reply

Return to “KVR Developer Challenge 2023”