unit uParseTrackerFile;
interface
uses Classes, Windows, uGlobal, SKAeroAPI;
type
PParseFile = ^TParseFile;
TParseFile =
record
Nr :Integer;
Str :
string;
Ptr : PParseFile;
Max : Integer;
end;
function FExist(FileSpec :
string): Boolean;
procedure FSeekTo(nReading: Integer; sBuffer:
string);
function ParsetoMidiTracker(MidiTrackerFile:
string;
ExePath:
string; List: TStringList): Boolean;
procedure FBuffin(FileName:
string);
implementation
uses uMidiTracker;
var
LineStart : PParseFile;
FPBuffer : PParseFile;
FToPBuffer : PParseFile;
nReading : Integer;
function ParsetoMidiTracker(MidiTrackerFile:
string;
ExePath:
string; List: TStringList): Boolean;
var
sParse :
String;
IntB: Integer;
IntA: Integer;
begin
// Buffer Liste füllen
FBuffin(MidiTrackerFile);
if not assigned(FPBuffer)
then
begin
result := False;
exit;
end;
List.Delimiter := '
,';
FPBuffer := LineStart;
while (FPBuffer.Nr <= LineStart.Max)
do
begin
FPBuffer := FPBuffer^.Ptr;
sParse := LeftTrim(FPBuffer.Str);
if Length(sParse) <> 0
then
begin
List.DelimitedText := sParse;
// Lade die Noten
for IntA := 0
to 7
do
begin
for IntB := 0
to List.Count - 1
do
Grid[IntA, IntB] := StrToInt(List.Strings[IntB]);
inc(FPBuffer.Nr);
FPBuffer := FPBuffer^.Ptr;
sParse := LeftTrim(FPBuffer.Str);
List.DelimitedText := sParse;
for IntB := 0
to List.Count - 1
do
InstGrid[IntA, IntB] := StrToInt(List.Strings[IntB]);
inc(FPBuffer.Nr);
FPBuffer := FPBuffer^.Ptr;
sParse := LeftTrim(FPBuffer.Str);
List.DelimitedText := sParse;
end;
// Lade das Tempo
if (FPBuffer.Nr = 16)
then
begin
for IntB := 0
to List.Count - 1
do
MidiTracker.Tempo := StrToInt(List.Strings[IntB]);
SKAERO_SetTrackValue(SKAERO_GetMainItem(MainHandle, ID_TRACK_TEMPO), MidiTracker.Tempo);
TempoWait := 1000
div round((MidiTracker.Tempo / 15));
end;
end;
if not (FPBuffer.Nr >= LineStart.Max)
then
begin
inc(FPBuffer.Nr);
FPBuffer := FPBuffer^.Ptr;
sParse := LeftTrim(FPBuffer.Str);
List.DelimitedText := sParse;
end;
if (FPBuffer.Nr > 16)
then
begin
for IntA := 0
to 7
do
begin
MidiTracker.CurrentInst[IntA] := StrToInt(List.Strings[IntA]);
end;
inc(FPBuffer.Nr);
end else
begin
for IntA := 0
to 7
do
MidiTracker.CurrentInst[IntA] := InstGrid[IntA, 0];
inc(FPBuffer.Nr);
end;
end;
// Resourcen Freigeben
FPBuffer :=
nil;
FToPBuffer :=
nil;
Result := True;
end;
procedure FBuffin(FileName:
string);
var
sBuffer:
string;
f : TextFile;
begin
if not FExist(FileName)
then
Exit;
try
Assignfile(f, FileName);
reset(f);
while not eof(f)
do
begin
ReadLN(f, sBuffer);
FSeekTo(nReading, sBuffer);
inc(nReading);
end;
finally
nReading := 0;
CloseFile(f);
end;
end;
function FExist(FileSpec :
string): Boolean;
var
hFile: Cardinal;
lpFindFileData: TWin32FindData;
begin
Result := False;
hFile := FindFirstFile(PAnsiChar(FileSpec), lpFindFileData);
if hFile <> INVALID_HANDLE_VALUE
then
begin
Windows.FindClose(hFile);
Result := True;
end;
end;
procedure FSeekTo(nReading: Integer; sBuffer:
string);
begin
New(FPBuffer);
if nReading = 0
then
Begin
New(FToPBuffer);
LineStart := FToPBuffer;
end;
FPBuffer^.Nr := nReading;
FPBuffer^.Str := sBuffer;
LineStart^.Max := nReading;
FToPBuffer^.Ptr := FPBuffer;
FToPBuffer := FPBuffer;
end;
end.