Re: File Open and Write VB6
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...
Re: File Open and Write VB6
Yeah, I know all the byte structures needed for MIDI,
Just need to know how to write them…
So I open for binary then?
Then when I write I’d have to use something like…
Write #1, Byte1, Byte2 etc…
?
Re: File Open and Write VB6
no its more complicated than that... you usually would use an array of bytes and loop it to write to the file..
the syntax to write the bytes to a file is
VB Code:
Put #1, [i]byte number[/i], [i]byte[/i]
Re: File Open and Write VB6
Ah, ok...
Didn't know what the Put command was... Thanks.
1 Attachment(s)
Re: File Open and Write VB6
The following pdf is a tutorial about file access.
Hope this helps!!
Re: File Open and Write VB6
Cool thanks for the pdf... I'll be perusing that. :)
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)
Re: File Open and Write VB6
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:
0 - single-track
1 - multiple tracks, synchronous
2 - multiple tracks, asynchronous
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.
Re: File Open and Write VB6
I think that you'd have to either choose the record, or let the next record be used.