program one2nul; Uses SysUtils, Algemeen, MidiDoos; var Bron, Doel : string; procedure Some_Help; begin Writeln('ONE2NUL'); Writeln; Writeln('Converts type 1 to type 0 MidiFile'); Writeln; writeln('Syntax: [program] [IMF] [OMF]'); Writeln; Writeln('IMF = name of 1-type MidiFile (Input)'); Writeln('OMF = name of 0-type MidiFile (Output)'); end; procedure Read_Parameters(var OK : boolean); begin OK := true; if ParamCount <> 2 then begin Some_Help; OK := false; end; if not OK then Exit; Bron := ParamStr(1); Doel := ParamStr(2); if not FileExists(Bron) then begin Writeln(Bron + ': does Not exist'); OK := false; end; end; function grootte(MF : Midi; var reeds : integer; aantal : integer) : integer; var p : integer; tel : integer; begin p := reeds; tel := 0; while p < reeds+aantal do begin MF.Skip_Delta_Time(p); MF.Skip_Any_Event(p); tel := tel + 1; end; reeds := p; grootte := tel; end; procedure spoor(MF : Midi; var reeds : integer; aantal : integer; var onthou : gegevens); var p,t,tijd : integer; riedel : bytes; tel : integer; begin p := reeds; tijd := 0; tel := 0; while p < reeds+aantal do begin t := MF.Get_Delta_Time(p); tijd := tijd + t; MF.Copy_Any_Event(p,riedel); onthou[tel].stamp := tijd; onthou[tel].event := riedel; tel := tel + 1; end; reeds := p; end; procedure HoofdRoutine; { Beginning of Main program } var punt,aantal,was : integer; onthou,totaal : gegevens; trk,tel : integer; k,L,lengte,tijd : integer; OK : boolean; MI,MO : Midi; begin Read_Parameters(OK); if not OK then Exit; MI := Midi.Create; MI.Read_MidiFile(Bron); MI.Check_Structure(OK); if not OK then Exit; if MI.Type01 <> 1 then begin Writeln(Bron,' is NOT a type 1 MidiFile'); Writeln; Some_Help; Exit; end; { Loop through all tracks: } punt := 14; SetLength(totaal,0); SetLength(onthou,0); for trk := 0 to MI.tracks-1 do begin MI.Check_Track_Header(punt,aantal,OK); was := punt; tel := grootte(MI,punt,aantal); SetLength(onthou,tel); punt := was; spoor(MI,punt,aantal,onthou); if trk = 0 then begin totaal := onthou; Continue; end; totaal := TwoMerge(totaal,onthou); end; { End of Track processing } L := Length(totaal); for k := 0 to L-1 do if Hexadecimaal(totaal[k].event) = ' FF 2F 00' then totaal[k].event[1] := $0F; totaal[L-1].event[1] := $2F; { for k := 0 to L-1 do Writeln(totaal[k].stamp, hexadecimaal(totaal[k].event)); } { Overhead } lengte := 14 + 8; { Estimated filesize } for k := 0 to L-1 do lengte := lengte + Length(totaal[k].event) + 2; MO := Midi.Create; SetLength(MO.invoer,lengte); MO.Put_Midi_Header(0,1,MI.ticks); punt := 14 + 8; tijd := 0; for k := 0 to L-1 do begin was := tijd; tijd := totaal[k].stamp; MO.Put_Delta_Time(tijd - was,punt); MO.Put_Any_Event(totaal[k].event,punt); end; MO.Put_Track_Header(punt-14-8,14); SetLength(MO.invoer,punt); MO.Write_MidiFile(Doel); end; BEGIN HoofdRoutine; END.