MIDI2TEX Version C-1.1

a MIDI to MusicTEX translation program

by

H.J.P. Kuykens, A.H. Verbruggen

20-7-’92

Note This manual was originally written for the Pascal version 1.1 of MIDI2TeX. Therefore, information in this document may be irrelevant or exuberant for the C-source code version.

[figure: MIDI; MusicTEX]

Contents

1 Introduction 3 2 How to read this manual 3 3 What it does do 3 4 What it does not do 4 5 What is needed? 4 6 Installation of the software 5 7 The need of neat MIDI files 5 8 Description of command structure and options 5 9 During processing 9 10Key signature and transposition 9

10.1 Key signature by MusicTEX . . . . . . . . . . . . . . . . . . 9 10.2 Key signature by MIDI2TEX . . . . . . . . . . . . . . . . . . 9 10.3 Transposition . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

11Line and page breaking 10 12The shell program (ST version only) 10 13An example of using MIDI2TEX 10 14Notes to versions 12 15Bugs & problems 14 16Technical notes for developers 15

16.1 Systems, instructions and comments . . . . . . . . . . . . . . 15 17License 16 18Acknowledgement 16

2 MIDI2TEX C-1.1

A Error and warning messages 18 B Package contents list 18

1 Introduction

MusicTEX is an extension of TEX for typesetting polyphonic music written by Daniel Taupin. I was surprised by the excellent result of the output. However, the coding of a music piece with MusicTEX is quite laborious and difficult. The first thing which came to my mind was that certainly there must be people out there who developed software which could translate MIDI files into MusicTEX code. I placed requests on the international NEWS system. However, I did not get any response. That made me decide to develop such software myself. MIDI2TEX is the result. I hope that it can be useful for other people who, just like me, are involved in MIDI but do not have a good music type setting system and know how to get on with TEX.

If you are not familiar with TEX at all I would recommend to find another software package to do musical typesetting. Setting up TEX and MusicTEX on your machine and mastering it is an awesome job which gobbles up a lot of your time and disk space. But, once you master it....

2 How to read this manual

If you are a regular user of MIDI2TEX then I suggest to switch immediately to section 14 to see what changes have been made since the last release and where to find more info about it.

If you are familiar with MusicTEX but not with MIDI2TEX I suggest to read the complete manual. If you want a quick start than switch to section 8 which describes all the command line options.

In this manual two types of attention marks can be found in the left margin.

! → The one shown left of this sentence asks your attention because there is some

important information in that sentence.

→ section 2 The other one, shown left of this sentence, refers to another section in this manual which contains information related to the subject in that sentence.

3 What it does do

→ section 15 MIDI2TEX inputs a type 1 MIDI file and translates this into source code for MusicTEX . Several features of the program are listed below:

• Maximum of 16 tracks translated

• Vertical alignment of notes in staffs

• Generation of beams and slurs

• Text in MIDI file supported

• Changes in signature supported

• Quantizing

• Insertion of rests

• Skipping of tracks • Combine several tracks into one instrument

• Selection of either violin, bass or alto clef for any track

• Reordering of tracks

• Changing vertical alignment

• Changing size of the music document

• Generate flats and sharps while taking into account the general signature

Most importantly, MIDI2TEX will do the massive job of coding note events in the MIDI file into MusicTEX notes. It speeds up the lay-out process of your sheet music tremendously. After the translation process you can manually adapt the MusicTEX source code to meet the desired lay out.

4 What it does not do

MIDI2TEX is not yet a very smart program. The vertical alignment of notes is not optimal. Complicated chord pieces are translated poorly. In general, additional editing of the MusicTEX code after the translation process is required to refine the output.

5 What is needed?

Software versions are available for PC compatibles (DOS), Macintosh and Atari ST. The versions are functionally identical. The Atari ST version includes a separate GEM based shell. The program itself needs approximately 90 kB and 10 kB for each track in the MIDI file to run properly.

Of course you need MusicTEX . MusicTEX consists of several TEX macro files and meta font files with music font definitions. The complete package is available on several bulletin boards and FTP sites. Recently I downloaded version 5.03 from rsovax.lps.u-psud.fr (in the directory /TeX/musictex). You need to acquire some knowledge about MusicTEX if you want to edit the source code after the translation process.

Further you need TEX. At the moment several good public domain packages are available. For the PC EMTEX is a good one. On the Atari ST I use TEX 3.1 by Christoph Strunk which I find pleasant to work with. OzTeX is available for the Mac. These packages are also available at FTP sites, PD services or bulletin boards.

Last but not least use of this program is only of any use if you are working with MIDI files. A MIDI file contains musical information and is a standard file format which enables to exchange music pieces between different software packages. Although many MIDI sequencer software packages have their own file format, most of them also support standard MIDI files.

This manual assumes that you have some knowledge of TEX and MusicTEX . If you are puzzled by any of the explanations in this manual see if reading the manuals of these packages can help you out.

6 Installation of the software

The PC version of the package comes in a ZIP file. Use any UNZIP program to decompress it to a target directory. The ST version comes in ARC’ed format ( V. 3.5). Copy the file MIDI2TEX.ARC to your (hard) disk and de-ARC it using any de-arc program. The example archive included in the distribution kit is ARC’ed and can be retrieved as described above.

7 The need of neat MIDI files

MIDI files are usually created by recording keyboard (or other MIDI instrument) events in a sequencer. As a consequence, the timing of notes can be ’offbeat’. MIDI2TEX needs much more ’clean’ files to enable correct translation. Therefore, it is necessary to first clean up the notes in a MIDI file to be processed. Many sequencers have a quantize function to align the start time of notes to a specific timing. That is a good start. If you have done that listen to the piece again to certify that all notes start at the correct position. The other thing you may want to do is to quantize the length of notes. Many notes which are played (usually short notes) do not fill the complete time they are supposed to be played. Usually the key is released earlier. If this is not corrected before starting MIDI2TEX the result is that after such notes a rest is placed. According to the program no note is sounding there! Some sequencers can quantize the length of notes too. If not, you can either edit them manually if your sequencer permits or you must do a lot of editing after processing of the file by MIDI2TEX . So, try to get your input MIDI files as neat as possible.

8 Description of command structure and options

A general call to MusicTEX looks like this:

  midi2tex inputfile [outputfile] [-option1 [-option2 [...]]]

The options are:

-? A help screen -s#,#,... Skip tracks (default none) -i#,#,... Combine tracks into one instrument (default none) -b#,#,... Code staffs with bass clef (default violin) -a1#,#,... Code staffs with alto 1 clef -a2#,#,... Code staffs with alto 2 clef -a3#,#,... Code staffs with alto 3 clef -a4#,#,... Code staffs with alto 4 clef -o#,#,... Order the tracks (default original order) -q# Quantize (default off) -p#,#,... Vertical part times (default type 4, quarter note) -f#,#,... Force beams to zero slope -h# Set horizontal size of music document -v# Set vertical size of music document -m# Set musicsize -e# Set Elemskip size -k# Set key sign -x Enable batch processing (ST version only) -dTYPE Generate debug information (default none)

The input file name is any valid DOS name. If the extension is omitted the default .MID is assumed. The output file name is optional. If omitted the input file name is used with extension .TEX. The options are described in more detail below.

-?, help screen: The program displays information on how to enter a correct command line and a listing of available options.

-s, skip tracks: Occasionally you might want to skip a track because you don’t want any output from it to appear on your scores. You can suppress output from a track by including the -s option in your command line. The numbers of the tracks(s) you want to skip immediately follow the option. For instance if you want to skip a drumtrack on track 4 your command line should include: -s4. The meta events in a skipped track ARE processed as they may contain information about timing or key signature.

The first track in a type 1 midi file is usually only used to store information about timing, key signature, etc. Therefore this track is skipped by default. If for any reason you want to prevent skipping of this track then include -s1 in the command line.

-i, instruments: In MusicTEX it is possible to assign two or more staffs to one instrument. For example they can be the left and right hand of a piano piece. This option can be used to assign two or more tracks to one instrument. The tracks are entered as numbers directly after -i, separated by comma’s. For instance if a piece contains 6 tracks and you want to assign track 2 and 4 to one instrument your command line must contain the option: -i2,4.

-b, bass clef: MusicTEX enables coding of music using different clefs. Most used are the violin and bass clef. MIDI2TEX enables the assignment of the bass clef to one or more tracks. If omitted, the default violin clef is used. For instance, to assign the bass clef to track 2 of a MIDI file include -b2 in the command line.

-a1..a4, alto clefs: Assign an alto clef to any of the tracks. For instance, to assign the alto 1 clef to track 3 of a MIDI file include -a13 in the command line.

-o, order track: The ordering of tracks in your MIDI file may not comply with the order you want the tracks to appear on the output. With this option you can redefine this order. Here is an example: consider a MIDI file containing 3 tracks. Normally the order of the tracks on your output will be 1, 2, 3. If you want to alter this order into 2, 3, 1 you must include the option -o2,3,1 in the command line. It is important that

! → you include \underline{ALL TRACKS} in this option. If there are 5 tracks in the MIDI file there must be 5 numbers in the option string. Don’t forget to include the first track in the string. By default it is skipped in the output but you must include it in this command. If you forget one MIDI2TEX will exit with an error. So, before using this command you must be sure how many tracks are included in the MIDI file. The best way to use this option is to first translate the MIDI file without this option. Examine the output and determine the order of the tracks that you want. Than retranslate the MIDI file with the -o option included.

-q, quantize: Quantizing involves the rounding of start times of notes. As stated in section 7 quantizing is a good tool for cleaning up the notes in your MIDI file. If you do not have this opportunity on your sequencer and your output comes out ugly with lots of rests inserted everywhere, try to use this option. The quantize option does two things:

• quantize the start time of notes

• quantize the length of notes

The number after the -q option determines the quantization time. Use table 8 to determine the quantization time:

quant. note number
�  1
�  2
�  4
��  8
��  16
��  32
��  64

Table 1: The quantization numbers

-p, part time: MusicTEX is designed to code notes in a vertical way. The notes at different tracks that start at the same time should be aligned to each other. Therefore in MusicTEX you can split up a measure into separate parts. The starts of such parts are aligned above each other.

MIDI2TEX follows this philosophy. By default it separates the measure into parts with a length of the denominator of the signature. If you want to change this part time use this option. Use table 8 to determine what number you should enter after the option. For instance if you want the separation time to be the length of an eighth note instead of a quarter note include -p8 in your command line.

-f, force zero slope: This option forces the slopes of the generated beams to be zero. The beams will be oriented horizontally.

-h, horizontal size: With this option a horizontal size can be set other than the default

! → defined in MusicTEX (160 mm). The parameter should be in 0.1mm. This option will output the proper sizing command in the source code. More important is that this command is used to append line and page breaking commands at the proper positions in the source file.

-v, vertical size: With this option a vertical size can be set other than the default defined in MusicTEX (240 mm). See -h option for further details.

-m, musicsize: With this option a choice can be made between 20pt and 16pt. The parameter must be either 16 or 20.

As an example we might want to produce a music document with width 100 mm, height 200mm and 16 pt musicsize. The option string should than include: -h1000 -v2000 -m16.

-e. elemskip: Notes in MusicTEX are spaced by the (MusicTEX ) variable \elemskip. Default values are set during initialization of MusicTEX . In previous versions of MIDI2TEX \autolines was used to alter the spacing of notes. Instead of using this macro in this version \elemskip is now altered directly. This only happens when the size of the document is changed in any way (-m,-v,-h,-e). If you’re not satisfied with the spacing of the notes you may use this option to directly alter the value of \elemskip. The value should be in pt. Changing the value of \elemskip in this way does not corrupt line and page breaking. An example: When using musicsize 20 the elemskip is 10 by default. If you want to reduce the space between the notes you must include the option -e8 in your command string.

-k, key sign: This option sets the keysign of the total music piece. Presently MIDI2TEX does not allow to set a key sign for individual tracks. The parameter following the option denotes the number of flats (negative sign) or sharps (positive sign). For instance to code a piece with four flats the command line should include: -k-4

-x, batch proc.: This option is only available on the ST version. It skips the message: hit key to exit which appears after processing of a file. Including this option on the command line in a batch file which contains calls to MIDI2TEX enables continuous execution.

-d, debug info: This option generates debug information. There are three ways to output this info: screen, file or printer.This is the way to select the debug type:

to screen  -dSCREEN
to file  -dFILE
to printer -dPRINTER

File output is written to a file with the name of the input file and extension .MLG. I do not believe that this option is of any use to anyone who is not familiar with the internal structure of the program. However, if for any reason the program should crash at least you know at

→ section 15 what point this happened. In section 15 further suggestions for its use

are given.

! → Warning: this option creates a huge amount of ASCII data. A single page of typeset music will generate about 65kB of debugging info depending on the number of notes in each measure.

9 During processing

During run time the program displays the measure it currently processes on the screen between square brackets. This is the sign that the program is actually doing something useful.

In some cases you may want to decide to abort the processing. In the PC version you can do so by pressing the ’q’ on the keyboard. On the Mac the translation process can be interrupted by typing command-period. The MusicTEX file and the log file are closed and the program exits. See section 15 for additional info. The code generated until the q key was hit can be translated normally. Code is appended which correctly closes the music document.

After completion of the translation process the program displays the number of pages it has coded.

10 Key signature and transposition

Accidental note processing can be performed either by MusicTEX or by MIDI2TEX . You may choose the method you prefer.

10.1 Key signature by MusicTEX

From version 4.5 (and maybe earlier versions too) it is possible to let MusicTEX figure out when flats or sharps should be inserted. To do this, translate the MIDI file without specifying any key signature. After the translation proces edit the resulting MusicTEX file. In the preamble you will find the command %\relativeaccidentals. Uncomment it by removing the % sign. Now edit the \generalsignature command to the required number of flats (negative sign) or sharps (positive sign). During processing MusicTEX will now figure out where to put flat and sharp signs.

10.2 Key signature by MIDI2TEX

MIDI2TEX contains a facility to generate sharps and flats taken into account the general key sign. To use this method translate the MIDI file with the option -k. The parameter of the -k option should be the number of flats or sharps of the key sign. Now after the translation process the file is ready for processing by MusicTEX .

10.3 Transposition

Currently MIDI2TEX does not have the ability to transpose parts because MusicTEX itself is quite capable of doing that. Including the MusicTEX \transpose= command in the preamble allows up or down tranpo- → reference [3] sition of tracks. See section 2.11 of the MusicTEX manual [3] for further

details.

11 Line and page breaking

MIDI2TEX keeps track of the space that is occupied by the typesetted music and inserts \alaligne and \alapage at the proper moments. It uses an \elemskip of 10pt for musicsize=20 and 8pt for musicsize=16. Inclusion of \autolines is not required anymore. \elemskip can be directly altered with the -e option.

When translating a file into a document with musicsize 16 you may end up in a TEX capacity exceeded error. During processing all measures are stored in memory until an \alapage is encountered. When selecting musicsize 16 there are so many notes on a single page that occasionally TEX may run out of storage space. There are two ways out: use BTEX or translate the MIDI file with musicsize 20.

12 The shell program (ST version only)

The main program MIDI2TEX can be controlled by the previously described options. The current operating system of the Atari-ST can only handle a command string of limited length. I wrote a small GEM based shell which avoids this problem.

The shell can be started by double clicking on the program name (M2TSHELL.PRG). A screen-wide form appears. This form contains edit fields for the different options. To edit a box first click on it with the mouse. The cursor appears in the box and you can use the keyboard to edit the string. You should not

! → include the option identifier in the string. Only the parameters should be entered. For instance, if you want to skip tracks 2 and 3 just put 2,3 in the box and not -s2,3.

One exception is the ’other box’. Here you can enter other valid MIDI2TEX options. As this box is not tied to a specific option the option identifiers must be included if this box is used. Currently there are no boxes to allow selection of the alto clefs. The only way to select them using the shell is by inserting proper option strings in the ’other box’.

A file can either be selected by editing the file selection box or by using the file selector by clicking on the button above the file selection box.

13 An example of using MIDI2TEX

Included in the package is an example MIDI file. This file will be used to demonstrate how to use MIDI2TEX . The example file was generated by Cubase. Track 1 contains Cubase mastertrack information (time signature, clef etc.) and no notes. MIDI2TEX skip this track by default. Translation of the file is now initiated by entering

            MIDI2TEX EXAMPLE -dFILE

The screen will show some program info and start executing. After termination of the program two files are generated. One is called EXAMPLE.TEX and the other EXAMPLE.MLG. Use any editor to inspect the content of the files. EXAMPLE.TEX will look like:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%    MIDI2TeX C-version V 1.1 translation
%           of MIDI file :
%          example.MID
%
%   Written by Hans Kuykens, Ad Verbruggen
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input musicnft
\input musictex
\input musicadd
\input musictrp
\normal
\def\nbinstruments{3}
\generalsignature{0}\relax
\def\thename{example}
% \centerline{\enorme PUT A NAME HERE and remove }
\medskip\centerline{\moyen \thename}
\rightline{translation by MIDI2TeX}
\rightline{by H.J.P. Kuykens}
\def\date{\number\day -\number\month -\number\year}
\headline={\ifnum\pageno>1 \otherpage \else\frontpage\fi}
\def\frontpage{\hfil \tenrm\date}
\def\otherpage{\tenrm \thename \hfil \tenrm\date}
\generalmeter{\meterfrac{4}{4}}%
%\raggedlinestrue % uncomment for ragged right lines
%\relativeaccidentals
\debutmorceau
%measure 1
\NOtes\uptext{Track 3} \hl q&\uptext{Track 2} \soupir
     &\uptext{Track 1} \qu J\enotes\relax
\temps\NOtes&\zq j\zq {^k}\qu g&\soupir \enotes\relax
\NOtes\ibl0o{0}\qb0p\qb0q&\soupir &\qu G\enotes\relax
\NOtes\qb0p\tbl0\qb0o&\zq k\zq j\ql g&\soupir \enotes\relax
%measure 2
\barre
\NOtes\cl n\ds &\soupir &\qu J\enotes\relax
\NOtes\hlp l&\zq {^k}\zq j\ibl1g{-1}\qb1g\zq j
     \zq k\tbl1\qb1g&\qu G\enotes\relax
\temps\NOtes&\soupir &\qu {_I}\enotes\relax
\temps\NOtes&\zq g\zq {_i}\qu {=k}&\qu {=I}\enotes\relax
%measure 3
\alaligne
\NOtes\ibl0k{0}\qb0k\qb0l&\soupir &\qu J\enotes\relax
\NOtes\qb0n\qb0k&\zq j\zq {^k}\ql g&\soupir \enotes\relax
\NOtes\qb0l\qb0o&\soupir &\qu G\enotes\relax
\NOtes\qb0n\tbl0\qb0l&\zq k\zq j\qu g&\soupir \enotes\relax
%measure 4
\barre
\NOtes\ccl k\pt g\ds &\soupir &\qu J\enotes\relax
\temps\NOtes\hl j&\zq j\zq {^k}\ql g&\qu I\enotes\relax

\temps\NOtes&\zh {_i}\zh g\hu {=k}&\qu J\enotes\relax
\finmorceau
\bye

Now you can process EXAMPLE.TEX directly with TEX. Be sure not to use LaTEX because TEX cannot hold that many macro definitions. After processing the above example you will find out that the score comes out pretty ugly. The bass notes on the first score line are way beyond and the melody line is on score 3. Now rerun MIDI2TeX with the following command:

            MIDI2TEX EXAMPLE -o1,4,3,2 -b2

This command now reorders the tracks and assigns the bass clef to the second track. The resulting score will now look much better.

In addition to the example file mentioned above I also included some MIDI files which I received from Volkmar Zitz which were a great help for tracking down the errors in previous versions. Theses files are ARC’ed into EXAMP-LES.ARC. There is also a batch file included which starts the translation processing of these files. This is of course only for DOS users. ST users will have to do it manually unless they are using a shell.

14 Notes to versions

test version 1: This is the first external release of the software. It is distributed for evaluation purpose to persons who previously have shown interest in the program.

test version 2: This is the second test release of the software. Shortly after the release of the first test release I discovered some disturbing bugs. I wanted to get rid off these before sending it to other people who have shown their interest after a message on NEWS. New features in the second test version are:

• Processing can now be stopped by pressing the ’q’ on the keyboard.

• The program now recognizes slur notes and generates source code for it.

• Bug during insertion of rests removed

test version 3: A lot of bugs were found in the previous version and solved. Most important ones are listed below:

• Reading of Key sign corrected (this caused crashes)

• Running status events in the MIDI file now supported (also crashed the program)

• MIDI files outside current directory in M2TSHELL.PRG now selectable • Problems in ’Chordfinder’ solved (caused run time errors)

• The slope of the beam is now calculated from the number of notes in the beam and the minimum and maximum note value within that beam

• Chaining of beams to higher/lower order corrected. Also, single flag beam notes are now supported.

• Clearing of beam and chord arrays forgotten which resulted in recognition of notes from previous measures.

• The timing of the measure parts is now determined by the numerator of the signature.

• Occurrence of accidental notes now only produce one flat/sharp sign.

New features in the third test version are:

• Line and page breaking of the scores by insertion of \alaligne and \alapage commands. This is done by keeping track of the number of notes written.

• Occurrence of meta events in track 1 are now handled properly at the right measure

• Size of score and document may now be adjusted

• \temps inserted before measure parts with no beams open

• -h option from previous versions changed into -?

• -k option added to set general key signature

version 1.0: • Correction in the generation of \alaligne and \alapage com-

mands. Removed \autolines.

• Track 1 skipped by default.

• Batch processing option included (ST only).

• Slur bows better due to enhanced filling of line.

• Changed log file name extension from .LOG to .MLG to prevent overwriting by TEX.

• Added option -a1..-a5 to allow the use of alto clefs

• Added option -e to allow changing the elemskip value

version 1.1: • A small bug during unskipping track 1 removed version C-1.1: • The complete Pascal code was translated into C using P2C. Addi-

tional coding was necessary to get the code running. The current source compiled and linked succesfully using Turbo-C on a PC (small memory model), THINK-C on the Mac, UNIX and VAX machines using standard C-compilers. See section 16 for further information on compiling the source code. future plans: • Shifting of notes occuring in a chord

• Selection of only part of the MIDI file to be translated.

• Automatic transposition of measures that contain notes exceeding the MusicTEX note value limits.

• Further development of the portable C-version of the program for other platforms.

15 Bugs & problems

I encourage everybody to report bugs or problems that you encounter back to me so that these can be omitted in a next release. Also, I am open for suggestions for enhancement of both the program and the manual.

Piet van Oostrum suggested that this same program should also be able to translate type 0 MIDI files. I have adjusted the source code such that type 0 files now do not induce an error exit. I tested a few of such files without succes. Nevertheless, I decided to allow processing of such files for those of you who wish to experiment. When a type 0 file is encountered a warning is displayed on the screen that the result may be unpredictable. I would be pleased if anybody would share his experience with translating type 0 MIDI files with me.

Bugs may appear in two different forms: run-time errors and infinite loops. The first one generates an error-exit: the open files are closed and the program terminates. The second type of bug can be recognized by the fact that the displaying of processed measures stops. Just hit the ’q’ and the program terminates. Error messages and warnings are listed in the appendix.

If you find any problems I suggest to run the program in debug mode,

→ section 8, -d option preferably in FILE mode. Then, send the MIDI file and a small note explaining the problem to me. I’ll try to collect the problems and avoid them in a next version. Please send compressed (ARJ, ARC, ZOO, LZH, ZIP) files to:

Hans Kuykens Spaarndammerplts. 7b 1013 XP Amsterdam The Netherlands e-mail : kuykens@amc.uva.nl ( until 1-10-94)

Problems with the C-code may also be addressed to :

Ad Verbruggen e-mail : ahv@dimes.tudelft.nl

The following problems are known to me:

1. Notes which have a MIDI value larger or smaller than the notes accepted by MusicTEX are coded as question marks (?). This causes TEX to stop processing. One way to solve this problem is to octivate the measure. Automatic octivation is not (yet) implemented in MusicTEX .

2. Flat and sharp signs may disappear under a preceding note in score lines with very close spacing. This is a MusicTEX problem.

3. Notes in a chord are not shifted in any way.

4. Closing of double sounding notes may corrupt the beaming business.

5. The program fails to run on the Atari TT.

16 Technical notes for developers

MIDI2TeX was originally written in Turbo Pascal. As a consequence, portabilty was poor. I received many requests for the source. A few people have tried to generate a more portable version but to my knowledge nobody ever came up with a working version. I decided to do the job myself (Aug-1993). Somebody on the net was kind enough to pass the Pascal source code (V 1.1) through a very good Pascal-2-C converter. That produced 95 % of the C-code. It still needed editing to cope with pointers and the buffered IO. One particular problem that occurred is that on the Atari ST the bytes in an integer/longint are stacked in reverse order compared to the PC and Mac. To solve this problem the routines ReadLongInt and ReadInteger (in TP_M2TF4.C) were rewritten. The proper ones may be selected by inserting #ifdef statements. In a joint effort with Ad Verbruggen we were able to generate a working portable version. Exectuables have been generated on

• PC compatible (MSDOS), using Turbo-C

• Macintosh, using THINK-C

• Unix machines, C-compiler unknown

• VAX-VMS machine, C-compiler unknown

This source code is now available on the network for those who are interested to port the C-code to other platforms. I invite C-experts who are interested in implementing the program on another platform to get a copy of the code and generate the executable. In return I would like to ask to make this executable available to other network users. Please inform me about succesfull compilation and send me back the edited source- and make files. I’ll try to glue them together to get source which is portable to many systems.

16.1 Systems, instructions and comments

DOS: I used a small library model to link the modules. When I tried to use other than that, the program would crash at the first file read instruction. As my knowledge about C is poor I was unable to track down the reason for this. As a consequence of the small memory model the read buffers could only be 1024 bytes long.

VAX: Compile all source files using cc tp_m2t16.c,tp_decl.c,....

     Before linking : $define lnk$library sys$library:vaxcrtl.olb.
     Then : $link tp_m2t16,tp_decl,tp_misc,tp_midi,....

This gives you the executable with extension .EXE. Now, to enable command line arguments define a foreign command by :

     MIDI2TeX == "$ $disk:[....]tp_m2t16.exe. The string $disk:[...]

can be inspected on the local system by typing : show default. Now the program can be run by typing : MIDI2TEX midifile.

Macintosh: MacTraps should be included in the link process. Enable Require prototypes in Edit Menu : Options : Language Settings and check Far Data in Project Menu : Set Project Type. Code should be segmented.

17 License

Copyright (c) 1992 by H.J.P. Kuykens. All Rights Reserved.

You are free to use, copy and distribute MIDI2TEX and inspect or edit the source files for non-commercial purpose provided that :

• the name(s) of the author(s) is/are not removed from the manual nor from the program itself

For commercial purpose MIDI2TEX is shareware. That is, if MIDI2TEX is used to generate sheet music with the intention to distribute it for commercial purpose a fee of $ 25,- is required.

The software comes without any warranty. The responsibility for it’s use is completely for the user. The authors are not responsible for any damage arising from use of this program whether caused by negligence or other fault on the part of the authors or by any other cause.

18 Acknowledgement

Although I wrote the code myself several people have made valuable suggestions to me. In particular I would like to mention Angelo Melis with whom I exchanged a lot of ideas and Ad Verbruggen whose enthusiasm made it possible to develop the C-version of the program. Also, Noel (?) attributed to the ideas for this program.

After sending off test versions I received bug reports from: Volkmar Zitz, David Channing, Vincenzo de Florio, John Richards, Piet van Oostrum, Mark Torrance, Michal Tomczak-Jaegermann. I would like to thank them for their valuable help and suggestions. These bug reports are a tremendous help in finding and solving bugs in the software. Also Daniel Taupin and Dale (Gold?) helped me out when I needed some specific ’inside MusicTEX ’ information.

Steve Chamberlain has passed the Pascal code through P2C (Caltec) to obtain the C-code.

References

[1] Borland. Turbo C++, version 3.0, Users’s guide. Borland International, inc., P.O. box 660001, Scotts Valley,CA95067-0001, USA, 1992.

[2] S. De Furia and J. Scacciaferro. MIDI programmer’s handbook. M & T Publishing, Inc., 1989.

[3] Daniel Taupin. MusicTEX, Using TEX to write polyphonic or instrumental music. Laboratoire de Physique ds Solides, Orsay, France, june 1992. (Version 4.52, (last version 5.02).

A Error and warning messages

1. No input file specified, or file does not exist

2. MidiFile track # is not ok

3. Found a NoteOff without a NoteOn

4. Can only translate MIDI files of type 1, sorry…

5. Nil pointer detected in NoteOff search

6. No. of order indices does not correspond with No. of tracks in file 7. Staffindex out of range, you tried to change a staff attribute which I

cannot handle

8. Heap exhausted during initializing memory

9. The noteheap appeared to be empty during a note request to the noteheap

10. A note value exceeded 127, probably a program bug

11. Invalid PartTime entered, only one of 1, 2, 4, 8, 16, 32 allowed

12. Invalid quantization time entered, use switch -? to get proper range 13. Can only define one multi-staff instrument in this version

14. Definition of an instrument of one track is useless

15. The Slur-array is exhausted, too many slurs (9) for MusicTeX

16. Process terminated by user

17. The Beam-array is exhausted, too many beams (9) for MusicTeX 18. -h and -v option can only take one parameter

19. -m option parameter must be either 20 or 16

20. Unknown error, probably a bug…

B Package contents list

The following files are included in the MIDI2TEX software package:

PC version

MIDI2TEX.EXE:  the executable

EXAMPLE.MID: an example MIDI file EXAMPLES.EXE: additional example MIDI files MANUAL.TEX: the TEX manual you are reading right now MIDI2TEX.BBL: the bibliography file MIDI2TEX.PIC: the frontpage logo

ST version

MIDI2TEX.TTP:  the executable
M2TSHELL.PRG:  the GEM shell to call MIDI2TEX.TTP

EXAMPLES.ARC: additional example MIDI files M2TSHELL.RSC: the resource file for the shell EXAMPLE.MID: an example MIDI file MANUAL.TEX: the TEX manual you are reading right now MIDI2TEX.BBL: the bibliography file MIDI2TEX.PIC: the frontpage logo

Source

TP_DECL.C : source file, declarations TP_MISC.C : source file, miscelaneous functions TP_DEBUG.C : source file, debug functions TP_MIDI.C : source file, MIDI parser TP_M2TF4.C : source file, buffered file IO TP_HEAP1.C : source file, defines and handles a heap of notes TP_M2T16.C : source file, the main program

*.H : the header files EXAMPLE.MID: an example MIDI file MANUALC.TEX: the TEX manual you are reading right now MIDI2TEX.BBL: the bibliography file MIDI2TEX.PIC: the frontpage logo

[

Index

] Line and page breaking, 10

Alto clefs, 6

Bass clef, 6 Batch processing, 8

Commands -?, 6 -a1..4, 6 -b, 6 -d, 8 -e, 8 -f, 8 -h, 8 -i, 6 -k, 8 -m, 8 -o, 7 -p, 7 -q, 7 -s, 6 -v, 8 -x, 8 described, 5

Debugging

options, 8 Defining

elemskip size, 8 horizontal size, 8 music size, 8 parts, 7 vertical size, 8 zero slope beam, 8

FTP sites, 4

Instrument staffs, 6

Key signature by MIDI2TEX , 9

MIDI files, 4 need of neat, 5

Ordering tracks, 7 PC version

installation, 5

Quantization by MIDI2TEX , 7 MIDI files, 5

Signature by MusicTEX , 9 command, 8

Skip tracks, 6 ST version

installation, 5

Transposition, 9