Hello... I'm new hear and fairly new to VB altogether...
I'm experimenting with writing files, namely in the Standard MIDI Format,
Any tips on how exactly to go about this?
When I open the file from VB 6,
How should I open?
Open MIDFILE.mid For Output As #1
Or... Should I write it as Binary?
Open MIDFILE.mid For Binary As #1
The problem I have is...
When I open for Binary I'm having trouble writing to it... not sure why...
But I can write okay when I open for Output...
well when you open a file for output it assumes its text, that is what the majority of the file IO is in VB. The ability to open a file for binary read/write are for all other types of files, so that is what you would need to use... but you know in order to write a midi file it would have to be all bytes...
I guess the other thing I need to do is package bytes into words no?
A MIDI message can consist of anywhere from 1 to 3 bytes
So I assume I'd need to write all the bytes for a message at once right?
Furthermore I need to add Start/Stop bytes (MIDI words consist of 10 bytes)
So if I wanted to send a "Note ON" message (Midi Message 144)
The bit-pattern would be:
what I want to tranmit: 10010000
what bits get put on the line (read left-to-right): 0 00001001 1
(note: the spaces are just to show that there is a start and stop bit)
Last edited by Disposable; Feb 11th, 2005 at 10:06 AM.
I found this info on how to write the necessary header chunk...
But can't figure out exactly how to do it...
______________________________________________________________
The header chunk appears at the beginning of the file, and describes the file in three ways. The header chunk always looks like:
4D 54 68 64 00 00 00 06 ff ff nn nn dd dd
The ascii equivalent of the first 4 bytes is MThd. After MThd comes the 4-byte size of the header. This will always be 00 00 00 06, because the actual header information will always be 6 bytes.
ff ff is the file format. There are 3 formats:
Single track is fairly self-explanatory - one track only. Synchronous multiple tracks means that the tracks will all be vertically synchronous, or in other words, they all start at the same time, and so can represent different parts in one song. Asynchronous multiple tracks do not necessarily start at the same time, and can be completely asynchronous.
nn nn is the number of tracks in the midi file.
dd dd is the number of delta-time ticks per quarter note. (More about this later)
-------------------------------------------------------------------------
Let's say I want to define the Format as "0"
The number of Tracks as "1"
And the Division as "10"
So I'd...
Open TestFile.mid for Binary As #1
Then I want to write the header chunk
To be MThd, the size of the header, Format, Number Of Tracks, Division
But I don't know how to do this.
Can anyone point me in the right direction?
Do I define Header as something then add all the information and then
Put #1, Header
?
Note, I do already have an ActiveX control that does all this automagically...
But I want to learn how to do it anyway for my own purpose...
I don't know C++ (What the ActiveX control is writtenin)
So I can't examine it's code with any validity...
Plus it has a lot of other functions I'd have to pick through.
Last edited by Disposable; Feb 11th, 2005 at 03:04 PM.