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


2.3 A tutorial example.

So, let's try performing the reading of a Standard MIDI File! We first hook our application to the Library as we explained before, that is to say, declaring the SMFInOutProc unit in the Uses of our program. We then choose from our menu bar the menu Import SMF and the library answers asking you to open the file you want to read; at this stage, the SMFAppl application also asks you the name of the file you are going to rewrite in, so if you are not concerned with this goal, please customize the reading loop to your special requirements. The SMFInOutProc, which is now running, reads the file sequentially and calls the opportune reading functions every time it recognizes a complete MIDI instruction; in case of alien datas, the loop simply skips them, while, in case of any kind of misfunction, the library will take care of reporting it to you via Alert boxes, telling you what went wrong. So, that's all it has to be done to make it with the reading of a Standard MIDI File.
The task of writing a MIDI File is performed the W_SMFLib unit, in which all the writing functions are implemented. When you choose from your menus, the Export SMF menu, your application will start picking the MIDI datas from its internal data structure, and will call the opportune writing function.
Again, the library opens or creates the file in which you're going to write, and asks you to choose the Format of it. Two formats are available in the SMFAppl Application, Format 0 and Format 1: SMFAppl in fact takes care of writing a short sample of MIDI File for each of them, while your application will be free to treat just one of them, or both. Notice that the W_SMFLib may perform also a Format 2 writing, it will completely depend on the syntax you follow when you call its functions! Further, the most important MIDI Meta Events are treated by the library but the user will be able to enreach this set by implementing some functions on his own, or by eventually customizing some already existing, to treat all the additional informations he wants to.
We now give a detailed description of what the SMFAppl Application does. This Program attempts to write a short Format 0 or 1 Standard MIDI File 1.0 sample, referring to the standard developed by the International MIDI Association; it does this by calling the W_SMFLib, which is the library attempting to the writing of a MIDI File. The user may conceive it as a tool to be used together with a Sequencer program which implements the reading and the writing of a Standard MIDI File. The application also reads any Standard MIDI File by calling the R_SMFLib, the library created to do this, and does it by executing a reading loop, implemented in the third library used, the SMFInOutProc, which also takes care of the handling about creating and opening the desired files. A description of this Program will follow in the next lines.
The user interface consists of a menu bar, with the Apple menu, and a MIDI File menu; the items of the Standard MIDI File menu are the following:

Write : a choice of this, will cause the program to create or open a file in which writing, and to ask for the Format of the Standard MIDI File. It will then perform the writing of a short sample of a Standard MIDI File of Format 0 or 1 (remember that no format 2 is actually treated here).

Read : a choice of this, will cause the program to display a Dialog box, in which the user will choose the file to be opened and read. It will then display another Dialog box, 'Save as ...', in order to let the user choose the name of the file in which rewriting the Standard MIDI File this program is about to read. After that, the reading is performed.

Quit : a choice of this causes the Program to teminate and it exits to shell.

The structure of this application is the typical one of samples furnished by Apple's MacIntosh Developer Technical Support.


[ Paragraph | Glossary | Previous Paragraph | Next Paragraph ]