Pierluigi Bettitoni
"Intelligent Music Workstation", CD-ROM, Winter 1994
© IEEE Computer Society Press.


2. Using Standard MIDI File LIBRARY.

2.1 The Standard MIDI File LIBRARY Structure.

The structure of this library consists of three Units, and an application part. A detailed description of each Unit will be given in this section.
The first Unit we analize in detail is called W_SMFLib, and is the part of the library in which all the needed functions to perform the goal of writing a Standard Midi File of any format are implemented.
The second Unit is called R_SMFLib, and is the part of the library in which all the needed functions to perform the goal of reading a Standard MIDI File of any format are implemented.
The third Unit is called SMFInOutProc, and is the part of the library in which are implemented all the needed functions to perform the goal of accessing and reading a Standard MIDI File of any format to be imported by the user's application.
Finally, a sample application of how to use this library is furnished, and is called SMFAppl. In it, a short Format 0 or Format 1 Standard MIDI File is written, and the application, hooked to this Library, performs a reading and rewriting loop of the sample Standard MIDI File. In addition, the application is able to read any Standard MIDI File, of any format, feeded to it by the user. So, let's have some details about the three Units.

W_SMFLib.

This Unit consists of twenty-three Functions and two Procedures. As already stated, it perform the task of writing a Standard MIDI File of any Format. It is good to take note of the fact that the onus of respecting the syntax in writing a Standard MIDI File, lies on the user; that is to say, the following of the standard directives implemented by the International MIDI Association, has to be carefully followed by the application which intends to use this Unit. So, in order to ensure a correct performing, please take a full vision of the Standard. We will give a detailed description of each function and procedure in section 3.1, in terms of what each of them does and of what is the meaning of each of their parameters, if any; further, an example of how to use them will be given in cue of the procedure list of this Unit.

R_SMFLib.

This Unit consists of twenty Functions, and performs the reading of a Standard MIDI File of any Format. The reading Functions are automatically called by the reading loop implemented in the third Unit, the SMFInOutProc. This loop reads the Standard MIDI File one byte at a time and, as soon as a certain complete MIDI Information is recognized, it calls the opportune function, contained in the Unit we are about to describe in detail.
There's no need to give a sample of how to call these functions, because they are directly called in the right way by the reading loop implemented in the Unit SMFInOutProc. However, if you wish to take vision of the calling modality, please refer to the furnished documentation of that Unit (section 4.3).
Again, to have a more detailed vision of how the Functions and Procedures work, please refer to the furnished documentation of this Unit (section 4.2).
This will absolutely have to be done by those users who have customized the Units in which is performed the reading and writing of Standard MIDI Files, because any change in the previous Units might have to correspond to an opportune updating of this unit.

SMFInOutProc.

This unit takes care of writing a short sample of a Format 0 and Format 1 Standard MIDI File 1.0, implemented by the International MIDI Association; it creates or opens a file on which writing the MIDI File and lets you choose its Format; it then executes a reading loop for a Standard MIDI File, which will also be rewritten on a file, in order to allow the user to eventually edit it (using any File Editor) and check the reading; this loop is performed one byte at the time, and as soon as a certain complete MIDI Event is recognized, the opportune reading function ( contained in the UnitR_SFMLib) which does the rest of the required operations is called. The bytes read are stored in memory locations that, after the opportune treating by the calling application, will have to be deallocated, in order to prevent memory from being fragmented. Further, a protection against a memory allocation failure is given here, in terms of an Alert box, reporting that the bytes which can't be stored will be skipped, together with the name of the MIDI Event to which they belong, which will then be missing.


[ Index | Glossary | Previous Paragraph | Next Paragraph ]