UNIT TP_Decl;

INTERFACE

uses  
        DOS,
        Printer;


CONST
    Version : String = 'V 1.1';
    NilStr = #00;
    BufSize = 8192; (* 8192 *)
    NoTracks = 16;
    MAXSLURR = 10; (* this is the maximum-1 that MusicTeX can handle *)
    MAXBEAMS = 9; (* ditto *)
    MAXPARTS = 25;
    PT       = 3.5; (* 0.1 mm  1 inch/72.27 = 25.4/72.27 mm *)

TYPE
    NoteTypes = (WH,WHPPP,WHPP,WHP,H,HPPP,HPP,HP,Q,QPPP,QPP,QP,
                 CPPP,CPP,C3,CP,C,CCPP,CC3,CCP,CC,
                 CCC3,CCCP,CCC,CCCC3,CCCCP,CCCC);

    DebugType = (SCREEN,DEBFILE,PRINT,NODEB);
    EventType = (VOID,NOTEON,NOTEOFF,REST,TXT,SIGNATURE,PEDAL,KEYSIGN);
    OrientType = (UP,DOWN);
    ClefType   = (VIOLIN,ALTO1,ALTO2,ALTO3,ALTO4,ALTO5,BASS);
    SlurType   = (STARTSLUR,ENDSLUR,REPEATSLUR);
    KeySignType= (NON,FLAT,SHARP,CORRECT);

    String20Type = String[20];
    Astr20Ptr    = ^String20Type;
    String255Type = String[255];
    Astr255Ptr    = ^String255Type;

    FileNameType = record
        p  : pathstr;
        d  : dirstr;
        n  : namestr;
        e  : extstr;
    End;

    BufType = Packed ARRAY[1..BufSize] OF Byte;
    FileRecord = record
        BufSemaphore,
        (*LastAvBytePnt,*)
        LastNoBytesRead,
        BufPoint    : Word;
        BytesProcessed : Longint;
        ReadBuf     : ^BufType;
        ReadIn,i    : integer;
        LastBlockRead,
        NoMoreData  : Boolean;
        FilePosition: LongInt;
    end;


    MeasureTime= record
                    Measure     : Integer;
                    MPart       : LongInt;
                 End;
                 

    NoteRecPoint = ^ NoteRecord;
    NoteRecord = record
                    MidiChnl,
                    NoteVal,
                    Velocity    : Byte;             
                    NoteType    : NoteTypes;
                    Event       : EventType;
                    Orient      : OrientType;
                    FilePos     : Longint;
                    EndTime,
                    StartTime   : MeasureTime;
                    ChordNote,
                    BeamNote,
                    SlurrNote   : Boolean;
                    Next,Prev   : NoteRecPoint;
                    MetaTxt     : AStr20Ptr;
                 End;

    BeamRecord = record
                    StartNote,
                    EndNote     : NoteRecPoint;
                    NoNotes,
                    Pitch,
                    Numb        : BYTE;
                    Slope       : ShortInt;
                    Orient      : OrientType;
                    NoteType    : NoteTypes;
                    Chain2Next  : Boolean;
                  End;

    SlurrRecord = record
                    NotePnt     : NoteRecPoint;
                    NoteVal,
                    Numb1,
                    Numb2       : BYTE;
                    KindOf      : SlurType;
                    Orient      : OrientType;
                    Occupied    : BOOLEAN;
                  End;

    ChordRecord  = record
                     StartNote,
                     EndNote       : NoteRecPoint;
                     NoNotes       : Byte;
                     ChordFinished : BOOLEAN;
                   End;

    AccKeyType = record
                   c,d,e,f,g,a,b : KeySignType;
                 end;

    AccKeyArray = ARRAY[1..NoTracks] Of AccKeyType;

     HeapRecord = record
                    Tail       : NoteRecPoint;
                    Size       : Word;
                  end;

    NoteArrayType   =  ARRAY[1..50] of NoteRecord;
    ChordArrayType  =  ARRAY[1..25] of ChordRecord;
    BeamArrayType  =  ARRAY[1..MAXBEAMS] of BeamRecord;
    SlurrArrayType  =  ARRAY[1..MAXSLURR] of SlurrRecord;


     TrackRecord = record
                     NoteList           : HeapRecord;
                     SpillList          : HeapRecord;
                     ChordArray         : ChordArrayType;
                     BeamArray          : BeamArrayType;
                     SlurrArray         : SlurrArrayType;
                     ChStackEnd,
                     ChStackPoint,
                     NotesSounding,
                     StatusByte         : Byte;
                     LastNoteOffTime,
                     Curtime,
                     OldTime,
                     OldOldTime         : MeasureTime;
                     FilRec             : FileRecord;
                     SlurrPt,
                     BeamPt,ChordPt     : Integer;
                     Beam,
                     Slurring,
                     Chord,
                     Skip,
                     Instrument,
                     ForceZeroBeams,
                     EndOfTrackRead     : BOOLEAN;
                     Clef               : ClefType;
                     PartStart,
                     PartEnd            : Array[1..MAXPARTS] of NoteRecPoint;
                     AccKey             : AccKeyType;
                   End;


    ControlInfo= record
                    
                    Num,          (* numerator of time signature *)
                    Den           (* denominator of time signature *) 
                                    : byte;
                    Division,     (* ticks in a quarter note *)
                    TicksPerMeasure : integer;
                    PartTime        : WORD;
                    PartType        : Byte;
                    nparts          : Byte;
                    PartOverRule    : BOOLEAN;
                    Tempo         (* int microsecs per quart note *)                        
                                    :Longint;
                    Twindow       (* TimeWindow *)
                                    :WORD;
                    KeySign,
                    Minor           : ShortInt;
                 End;

                   
VAR
    TmpStr      : String[40];
    NilPos,
    Drno,abyte  : Byte; 
    ntracks,
    ninstruments,
    nTracksInInstr,
    CurTrack,  
    FileFormat,
    SafetyCounter,
    OK_result   : integer;     
    MidiFile    : file;
    DebugFile,
    TexFile     : Text;
    DebBuf,
    TexBuf      : ^BufType;
    FileInfo    : SearchRec;
    DebugFileName,
    MidiFileName,
    TeXFileName : FileNameType;
    path        : PathStr;
    fname       : NameStr;
    dir         : DirStr;
    ext         : ExtStr;
    ReadIn,i    : integer;
    Quantizing,
    QuitTrack,    
    DebugFileOpened,
    MidiFileOpened,
    TeXHeaderFinished,
    Debug       : Boolean;
    QuantTime   : Integer;
    NoOfBytes   : LongInt;
    TrackArray  : ARRAY[1..NoTracks] OF TrackRecord;    
    SlurrIndexes: ARRAY[0..25] of boolean;
    ALongInt    : LongInt;
    PieceContr  : ControlInfo;
    TempTime,
    OldTime,
    CurTime     : MeasureTime;
    MeasureStr  : STRING[255];
    DebugOut    : DebugType;
    MeasureCount: Integer;
    Notes       : String[128];
    (* AES_handle  : Integer; *)
    HlpFilRec   : FileRecord;
    OldExitProc : pointer;
    CPosition   : Byte;
    N           : NoteRecPoint;
    NotePool    : HeapRecord;
    TrackOrder  : Array[1..NoTracks] OF Byte;
    BeamIndex, OrderIndex,
    NoOfSkips,NoOfPages,Indent,BarIndent,
    ScoreWidth,ScoreHeight,ScoreSep,
    LineHeight,MeasureMaxCnt,ElemSkip,
    MusicSize,CumLength,CumHeight   : Integer;
    SizingChanged,BatchProcessing    : Boolean;

IMPLEMENTATION

Begin
End.
