-
Notifications
You must be signed in to change notification settings - Fork 2
/
SaveEQPrUnit.pas
executable file
·159 lines (146 loc) · 3.32 KB
/
SaveEQPrUnit.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
unit SaveEQPrUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Winamp, IO;
type
TSaveEQPrForm = class(TForm)
SaveBtn: TButton;
CancelBtn: TButton;
PresetsBox: TComboBox;
procedure FormCreate(Sender: TObject);
procedure SaveBtnClick(Sender: TObject);
procedure PresetsBoxKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
procedure LoadPresets;
end;
var SaveEQPrForm: TSaveEQPrForm;
procedure SavePreset;
implementation uses Main;
{$R *.DFM}
procedure SavePreset;
begin
with TSaveEQPrForm.Create(Application) do
try
ShowModal;
finally
Free;
end;
end;
procedure TSaveEQPrForm.LoadPresets;
var f : file;
s : string;
hdr : array[0..30] of char;
eqd : array[0..267] of byte;
i,ior : integer;
begin
PresetsBox.Items.BeginUpdate;
PresetsBox.Items.Clear;
s := BasePath + 'mp3nav.q1';
{$I-}
if FileExists(s) then
begin
assignfile(f,s); reset(f,1);
blockread(f,hdr,sizeof(hdr));
ior := IOResult;
if not FatalIOError(ior) then
begin
while not eof(f) do
begin
blockread(f,eqd,sizeof(eqd));
i := 0; s := '';
while (i < 267 - 11) do
begin
if eqd[i] = 0 then break else s := s + char(eqd[i]);
inc(i);
end;
s := trim(s);
if s <> '' then
begin
PresetsBox.Items.Add(s);
end;
ior := IOResult;
if FatalIOError(IOR) then
begin
{ syserrormessage(ior);{}
break;
end;
end;
end else
begin
{ syserrormessage(ior);{}
end;
closefile(f);
end;
{$I+}
PresetsBox.Items.EndUpdate;
end;
procedure TSaveEQPrForm.FormCreate(Sender: TObject);
begin
LoadPresets;
end;
procedure TSaveEQPrForm.SaveBtnClick(Sender: TObject);
var f : file;
s,t,st,stu : string;
hdr : array[0..30] of char;
eqd : array[0..267] of byte;
i,ior : integer;
begin
{$I-}
s := BasePath + 'mp3nav.q1';
st := trim(PresetsBox.Text);
stu := AnsiUpperCase(st);
if length(st) > 267 - 12 then st := copy(st,1,267 - 12);
if FileExists(s) then
begin
AssignFile(f,s); reset(f,1);
blockread(f,hdr,sizeof(hdr));
ior := IOResult;
if not FatalIOError(ior) then
begin
while not eof(f) do
begin
blockread(f,eqd,sizeof(eqd));
i := 0; t := '';
while (i < 267 - 11) do
begin
if eqd[i] = 0 then break else t := t + char(eqd[i]);
inc(i);
end;
t := ansiuppercase(trim(t));
if t = stu then
begin
seek(f,filepos(f) - sizeof(eqd));
break;
end;
end;
end;
end else
begin
rewrite(f,1);
fillchar(hdr,sizeof(hdr),0);
hdr := 'Winamp EQ library file v1.1'#$1A'!--';
end;
fillchar(eqd,sizeof(eqd),0);
for i := 1 to length(st) do
begin
eqd[i-1] := byte(st[i]);
end;
for i := 0 to 9 do eqd[257 + i] := EQData[i];
eqd[267] := EQPreAmp;
eqd[length(st)] := 0;
blockwrite(f,eqd,sizeof(eqd));
closefile(f);
{$I+}
end;
procedure TSaveEQPrForm.PresetsBoxKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = VK_RETURN) then SaveBtn.Click else
if (Key = VK_ESCAPE) then CancelBtn.Click;
end;
end.