program channels; uses SysUtils, Algemeen, MidiDoos; var { Old & new midi-CHannel numbers: } chX, chY : integer; Bron,Doel : string; procedure Some_Help; begin Writeln('CHANNELS'); Writeln; Writeln('Changes Old to New midi channel number'); Writeln; writeln('Syntax: [program] [IMF] [OMF] [OCH] [NCH]'); Writeln; Writeln('IMF = name of Input MidiFile'); Writeln('OMF = name of Output MidiFile'); Writeln; Writeln('OCH = number of Old midiCHannel'); Writeln('NCH = number of New midiCHannel'); end; procedure Read_Parameters(var OK : boolean); var tel : integer; woord : string; begin OK := true; tel := ParamCount; if tel <> 4 then begin Some_Help; OK := false; Exit; end; Bron := ParamStr(1); Doel := ParamStr(2); woord := ParamStr(3); chX := getnum(woord); woord := ParamStr(4); chY := getnum(woord); if (chX < 0) or (chX > 15) then begin Writeln('Old channel ',chX,' out of [0,15] range'); OK := false; end; if (chY < 0) or (chY > 15) then begin Writeln('New channel ',chY,' out of [0,15] range'); OK := false; end; if (chX = chY) then begin Writeln(chX,' = New channel = Old channel: done.'); OK := false; end; if not OK then Exit; if not FileExists(Bron) then begin Writeln(Bron + ': does Not exist'); OK := false; end; end; procedure channel(MF : Midi; chX,chY : integer); var punt,aantal : integer; p,q,trk : integer; OK : boolean; let : byte; riedel : bytes; begin punt := 14; for trk := 0 to MF.Tracks-1 do begin MF.Check_Track_Header(punt,aantal,OK); p := punt; while (p < punt+aantal) do begin MF.Skip_Delta_Time(p); let := MF.invoer[p]; if ($80 <= let) and (let <= $EF) then begin { Change Midi Channel HERE } if let = ((let and $F0) or chX) then let := ((let and $F0) or chY); MF.invoer[p] := let; end; { PolyText extension } q := p; MF.Copy_Any_Event(p,riedel); let := riedel[0]; if not ($FF = let) then Continue; let := riedel[1]; if not ((let and $F0) = $10) then Continue; if (let and $0F) = chX then MF.invoer[q+1] := $10 or chY; end; punt := punt+aantal; end; end; procedure HoofdRoutine; { Beginning of Main program } var MF : Midi; OK : boolean; begin Read_Parameters(OK); if not OK then Exit; MF := Midi.Create; MF.Read_MidiFile(Bron); MF.Check_Structure(OK); if not OK then Exit; channel(MF,chX,chY); MF.Write_MidiFile(Doel); end; BEGIN HoofdRoutine; END.