📄 mmfirdlg.pas
字号:
procedure TMMFIRDlgForm.spinChange(Sender: TObject);
begin
if UpdateSpins and UpdateFilters and (FilterComboBox.ItemIndex >= 0) then
with TmpFIR.Filters[FilterComboBox.ItemIndex] do
begin
if Sender = spinf1 then
begin
f1 := spinf1.Value/100;
mef1.Value := f1;
mef1.Update;
end
else
begin
Gain := spinGain.Value/100;
meGain.Value := Gain;
meGain.Update;
end;
with Envelope.Points[FilterComboBox.ItemIndex] do
begin
X_Value := Trunc(f1*100);
Y_Value := DBToVolume(Gain);
end;
Envelope.Refresh;
end;
end;
{-- TMMFIRDlgForm -------------------------------------------------------------}
procedure TMMFIRDlgForm.mefExit(Sender: TObject);
begin
spinf1.Value := Trunc(mef1.Value*100);
spinGain.Value := Trunc(meGain.Value*100);
end;
{-- TMMFIRDlgForm -------------------------------------------------------------}
procedure TMMFIRDlgForm.mefKeyPress(Sender: TObject; var Key: Char);
begin
if (Key = #13) then TMaskEdit(Sender).OnExit(Sender);
end;
{-- TMMFIRDlgForm -------------------------------------------------------------}
procedure TMMFIRDlgForm.spinOrderChange(Sender: TObject);
begin
with TmpFIR do
begin
Order := spinOrder.Value;
edOrder.Value := Order;
end;
end;
{-- TMMFIRDlgForm -------------------------------------------------------------}
procedure TMMFIRDlgForm.edOrderExit(Sender: TObject);
var
val: integer;
begin
val := Max(edOrder.Value,1);
if (val mod 2 = 0) then inc(Val);
spinOrder.Value := val;
end;
{-- TMMFIRDlgForm -------------------------------------------------------------}
procedure TMMFIRDlgForm.edOrderKeyPress(Sender: TObject; var Key: Char);
begin
if (Key = #13) then TEdit(Sender).OnExit(Sender);
end;
{-- TMMFIRDlgForm -------------------------------------------------------------}
procedure TMMFIRDlgForm.EnvelopeTrackBegin(Sender: TObject);
var
Pos: TPoint;
i: integer;
begin
GetCursorPos(Pos);
Pos := Envelope.ScreenToClient(Pos);
i := Envelope.FindPointAtPos(Pos.X, Pos.Y);
if (i >= 0) and (i < FilterComboBox.Items.Count) then
begin
FilterComboBox.ItemIndex := i;
UpdateMaskEdits;
end;
end;
{-- TMMFIRDlgForm -------------------------------------------------------------}
procedure TMMFIRDlgForm.EnvelopeTrack(Sender: TObject);
var
f1,Gain: Float;
begin
with FilterComboBox,Envelope do
begin
if (ItemIndex >= 0) then
with Envelope.Points[ItemIndex] do
begin
UpdateFilters := False;
f1 := X_Value/100;
Gain := VolumeToDB(Y_Value);
mef1.Value := f1;
meGain.Value := Gain;
spinf1.Value := Trunc(f1*100);
spinGain.Value := Trunc(Gain*100);
UpdateFilters := True;
end
end;
end;
{-- TMMFIRDlgForm -------------------------------------------------------------}
procedure TMMFIRDlgForm.EnvelopeTrackEnd(Sender: TObject);
begin
Envelope.Locator := -1;
end;
{-- TMMFIRDlgForm -------------------------------------------------------------}
procedure TMMFIRDlgForm.EnvelopeChange(Sender: TObject);
var
i: integer;
begin
if UpdateFilters then
with TmpFIR do
begin
Filters.BeginUpdate;
try
Filters.FreeAll;
for i := 0 to Envelope.Count-1 do
with Envelope.Points[i] do
begin
Filters.AddObject(TMMFIRFilterItem.CreateEx(X_Value/100,
VolumeToDB(Y_Value)));
end;
finally
Filters.EndUpdate;
end;
FillComboBox;
end;
end;
{-- TMMFIRDlgForm -------------------------------------------------------------}
procedure TMMFIRDlgForm.UpdateControls;
var
i: integer;
begin
with TmpFIR do
begin
Caption := Title + ' - '+ Description;
FillComboBox;
spinOrder.MaxValue := MAXTAPS;
edOrder.MaxValue := MAXTAPS;
spinOrder.Value := TmpFIR.Order;
edOrder.Value := TmpFIR.Order;
with Envelope do
begin
UpdateFilters := False;
try
RangeMinX := 0;
RangeMaxX := (SampleRate div 2)*100;
DispMinX := 0;
DispMaxX := (SampleRate div 2)*100;
RangeMinY := 0;
RangeMaxY := 2*VOLUMEBASE;
DispMinY := 0;
DispMaxY := 2*VOLUMEBASE;
BaseY := VOLUMEBASE;
GridWidthX:= RangeMaxX / 16;
GridWidthY:= RangeMaxY / 10;
Clear;
if (Filters.Count > 0) then
Envelope.Points[0].Y_Value := DBToVolume(Filters[0].Gain);
for i := 1 to Filters.Count-2 do
with Filters[i] do
begin
AddPoint(TMMEnvelopePoint.CreateEx(Trunc(f1*100),
DBToVolume(Gain),
False),False);
end;
if (Filters.Count > 1) then
Envelope.Points[Envelope.Count-1].Y_Value := DBToVolume(Filters[Filters.Count-1].Gain);
finally
UpdateFilters := True;
end;
end;
end;
end;
{-- TMMFIRDlgForm -------------------------------------------------------------}
procedure TMMFIRDlgForm.SetFIR(aValue: TMMFIRFilter);
begin
if (aValue <> Nil) then
begin
FFIR := aValue;
TmpFIR.assign(aValue);
UpdateControls;
EnvelopeChange(Envelope);
end;
end;
{-- TMMFIRDlgForm -------------------------------------------------------------}
procedure TMMFIRDlgForm.btnResetClick(Sender: TObject);
begin
SetFIR(FFIR);
end;
{-- TMMFIRDlgForm -------------------------------------------------------------}
procedure TMMFIRDlgForm.btnClearClick(Sender: TObject);
begin
Envelope.Clear;
end;
{-- TMMFIRDlgForm -------------------------------------------------------------}
procedure TMMFIRDlgForm.btnLoadClick(Sender: TObject);
begin
if OpenDialog.Execute then
begin
TmpFIR.Filters.LoadFromFile(OpenDialog.FileName);
FilterComboBox.ItemIndex := -1;
UpdateControls;
end;
end;
{-- TMMFIRDlgForm -------------------------------------------------------------}
procedure TMMFIRDlgForm.btnSaveClick(Sender: TObject);
begin
if SaveDialog.Execute then
begin
TmpFIR.Filters.SaveToFile(SaveDialog.FileName);
end;
end;
{== TMMFIRFilterDialog ========================================================}
constructor TMMFIRFilterDialog.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FTitle := 'FIR-Filter Editor';
FSource := nil;
ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
end;
{-- TMMFIRFilterDialog --------------------------------------------------------}
procedure TMMFIRFilterDialog.SetSource(aSource: TMMFIRFilter);
begin
if Longint(aSource) = Longint(Self) then exit;
if (aSource is TMMFIRFilter) or (aSource = Nil) then
begin
if (FSource <> aSource) then
begin
FSource := aSource;
end;
end;
end;
{-- TMMFIRFilterDialog --------------------------------------------------------}
procedure TMMFIRFilterDialog.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FSource) then
FSource := Nil;
end;
{-- TMMFIRFilterDialog --------------------------------------------------------}
function TMMFIRFilterDialog.Execute: Boolean;
begin
Result := False;
if assigned(FSource) then
begin
with TMMFIRDlgForm.Create(Application) do
try
FIRFilter := (Self.FSource as TMMFIRFilter);
Title := Self.FTitle;
Result := (ShowModal = mrOK);
finally
Free;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -