-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunitframesound.pas
226 lines (189 loc) · 6.19 KB
/
unitframesound.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
unit UnitFrameSound;
// Copyright 2022-2025 Zoran Vučenović
// SPDX-License-Identifier: Apache-2.0
{$mode ObjFPC}{$H+}
{$i zxinc.inc}
interface
uses
Classes, SysUtils, UnitInputLibraryPathDialog, UnitSpectrum, UnitOptions,
UnitFrameSoundVolume, CommonFunctionsLCL, UnitCommon, SoundChipAY_3_8912,
Forms, Controls, ExtCtrls, StdCtrls;
type
TFrameSound = class(TFrame, ICheckStateValid)
Bevel1: TBevel;
Bevel2: TBevel;
CheckBox1: TCheckBox;
ComboBox1: TComboBox;
Label1: TLabel;
LabelVolume: TLabel;
Panel1: TPanel;
Panel2: TPanel;
Panel4: TPanel;
PanelVolume: TPanel;
PanelSoundLibrary: TPanel;
private
FrameSoundLib: TFrameInputLibraryPath;
FSpectrum: TSpectrum;
FrameSoundVolume: TFrameSoundVolume;
FSaveLibOnClose: Boolean;
procedure FormOnShow(Sender: TObject);
procedure AfterShow(Data: PtrInt);
function GetSoundMuted: Boolean;
function GetAYOutputMode: TSoundAY_3_8912.TOutputMode;
function GetVolLevel: Integer;
procedure SetFrameSoundLib(AFrameSoundLib: TFrameInputLibraryPath);
procedure SetSoundMuted(const AValue: Boolean);
procedure FormOnCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormCloseCallback(Sender: TObject; var {%H-}CloseAction: TCloseAction);
procedure SetAYOutputMode(AValue: TSoundAY_3_8912.TOutputMode);
procedure SetVolLevel(AValue: Integer);
public
constructor Create(TheOwner: TComponent); override;
class function CreateForAllOptions(AOptionsDialog: TFormOptions;
ASpectrum: TSpectrum; AFrameSoundLib: TFrameInputLibraryPath): TFrameSound;
function IsStateValid: Boolean;
property VolLevel: Integer read GetVolLevel write SetVolLevel;
property AYOutputMode: TSoundAY_3_8912.TOutputMode read GetAYOutputMode write SetAYOutputMode;
end;
implementation
{$R *.lfm}
{ TFrameSound }
procedure TFrameSound.FormOnShow(Sender: TObject);
begin
AfterShow(2);
end;
procedure TFrameSound.AfterShow(Data: PtrInt);
begin
if Data > 0 then
Application.QueueAsyncCall(@AfterShow, Data - 1)
else begin
DisableAlign;
try
FrameSoundLib.AnchorParallel(akRight, 0, PanelSoundLibrary);
FrameSoundLib.AutoSize := True;
PanelSoundLibrary.AnchorParallel(akRight, 0, Panel1);
Panel1.AnchorParallel(akRight, 0, Self);
finally
EnableAlign;
end;
end;
end;
function TFrameSound.GetSoundMuted: Boolean;
begin
Result := CheckBox1.Checked;
end;
function TFrameSound.GetAYOutputMode: TSoundAY_3_8912.TOutputMode;
begin
Result := TSoundAY_3_8912.TOutputMode(ComboBox1.ItemIndex);
end;
function TFrameSound.GetVolLevel: Integer;
begin
Result := FrameSoundVolume.Level;
end;
procedure TFrameSound.SetSoundMuted(const AValue: Boolean);
begin
CheckBox1.Checked := AValue;
end;
procedure TFrameSound.FormOnCloseQuery(Sender: TObject; var CanClose: Boolean);
var
F: TFormOptions;
begin
if Assigned(FrameSoundLib) then begin
F := nil;
if Sender is TFormOptions then
F := TFormOptions(Sender);
if (F = nil) or (F.CurrentControl = Self) then begin
FrameSoundLib.FormOnCloseQuery(Sender, CanClose);
FSaveLibOnClose := FSaveLibOnClose or CanClose;
end;
end;
end;
procedure TFrameSound.FormCloseCallback(Sender: TObject;
var CloseAction: TCloseAction);
begin
if (Sender is TCustomForm) and (TCustomForm(Sender).ModalResult = mrOK) then begin
FSpectrum.SoundMuted := GetSoundMuted;
FSpectrum.AYOutputMode := GetAYOutputMode;
if Assigned(FrameSoundLib) then
if FSaveLibOnClose then
FrameSoundLib.FormOnClose(Sender, CloseAction);
end;
end;
procedure TFrameSound.SetAYOutputMode(AValue: TSoundAY_3_8912.TOutputMode);
begin
ComboBox1.ItemIndex := Integer(AValue);
end;
procedure TFrameSound.SetVolLevel(AValue: Integer);
begin
FrameSoundVolume.Level := AValue;
end;
constructor TFrameSound.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
Name := TCommonFunctions.GlobalObjectNameGenerator(Self);
Caption := 'Sound options';
FSaveLibOnClose := True;
PanelSoundLibrary.BevelOuter := bvNone;
PanelSoundLibrary.Caption := '';
Panel1.BevelOuter := bvNone;
Panel1.Caption := '';
Panel2.Caption := '';
Panel4.BevelOuter := bvNone;
Panel4.Caption := '';
PanelVolume.BevelOuter := bvNone;
PanelVolume.Caption := '';
PanelSoundLibrary.AutoSize := True;
FrameSoundVolume := TFrameSoundVolume.Create(PanelVolume);
FrameSoundVolume.VerticalOrientation := False;
FrameSoundVolume.Anchors := [];
FrameSoundVolume.AnchorParallel(akTop, 0, PanelVolume);
FrameSoundVolume.AnchorToNeighbour(akLeft, 5, LabelVolume);
FrameSoundVolume.Parent := PanelVolume;
PanelVolume.OnMouseWheel := FrameSoundVolume.TrackBar1.OnMouseWheel;
Panel2.OnMouseWheel := FrameSoundVolume.TrackBar1.OnMouseWheel;
PanelVolume.AutoSize := True;
Panel1.AutoSize := True;
Panel4.AutoSize := True;
Self.AutoSize := True;
end;
procedure TFrameSound.SetFrameSoundLib(AFrameSoundLib: TFrameInputLibraryPath);
begin
FrameSoundLib := AFrameSoundLib;
FrameSoundLib.Anchors := [];
FrameSoundLib.AnchorParallel(akLeft, 0, PanelSoundLibrary);
FrameSoundLib.AnchorParallel(akTop, 0, PanelSoundLibrary);
FrameSoundLib.Parent := PanelSoundLibrary;
end;
class function TFrameSound.CreateForAllOptions(AOptionsDialog: TFormOptions;
ASpectrum: TSpectrum; AFrameSoundLib: TFrameInputLibraryPath): TFrameSound;
var
Fm: TFrameSound;
begin
Result := nil;
if Assigned(AOptionsDialog)
and Assigned(ASpectrum)
and Assigned(AFrameSoundLib)
then begin
Fm := TFrameSound.Create(AOptionsDialog);
try
Fm.SetFrameSoundLib(AFrameSoundLib);
Fm.FSpectrum := ASpectrum;
Fm.SetSoundMuted(ASpectrum.SoundMuted);
Fm.FSaveLibOnClose := False;
AOptionsDialog.AddHandlerFirstShow(@AFrameSoundLib.OnFormFirstShow);
AOptionsDialog.AddHandlerFirstShow(@Fm.FormOnShow);
AOptionsDialog.AddCloseQuery(@Fm.FormOnCloseQuery);
AOptionsDialog.AddHandlerClose(@Fm.FormCloseCallback);
AOptionsDialog.AddAnOptionControl(Fm, 'Sound');
Result := Fm;
except
FreeAndNil(Fm);
end;
end;
end;
function TFrameSound.IsStateValid: Boolean;
begin
Result := (FrameSoundLib = nil) or FrameSoundLib.IsStateValid;
FSaveLibOnClose := True;
end;
end.