MMEQDlg.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:12k
- {========================================================================}
- {= (c) 1995-98 SwiftSoft Ronald Dittrich =}
- {========================================================================}
- {= All Rights Reserved =}
- {========================================================================}
- {= D 01099 Dresden = Fax.: +49 (0)351-8037944 =}
- {= Loewenstr.7a = info@swiftsoft.de =}
- {========================================================================}
- {= Actual versions on http://www.swiftsoft.de/mmtools.html =}
- {========================================================================}
- {= This code is for reference purposes only and may not be copied or =}
- {= distributed in any format electronic or otherwise except one copy =}
- {= for backup purposes. =}
- {= =}
- {= No Delphi Component Kit or Component individually or in a collection=}
- {= subclassed or otherwise from the code in this unit, or associated =}
- {= .pas, .dfm, .dcu, .asm or .obj files may be sold or distributed =}
- {= without express permission from SwiftSoft. =}
- {= =}
- {= For more licence informations please refer to the associated =}
- {= HelpFile. =}
- {========================================================================}
- {= $Date: 06.09.98 - 14:25:28 $ =}
- {========================================================================}
- unit MMEQDlg;
- {$I COMPILER.INC}
- interface
- uses
- {$IFDEF WIN32}
- Windows,
- {$ELSE}
- WinTypes,
- WinProcs,
- {$ENDIF}
- SysUtils,
- Messages,
- Consts,
- Classes,
- Dialogs,
- StdCtrls,
- Controls,
- ExtCtrls,
- Forms,
- Mask,
- ComCtrls,
- MMObj,
- MMUtils,
- MMSpin,
- MMEQ,
- MMDIBCv,
- MMSpectr,
- MMDSPObj,
- MMEdit;
- type
- {-- TMMEQDlg ----------------------------------------------------------------}
- TMMEQDlgForm = class(TForm)
- OpenDialog: TOpenDialog;
- SaveDialog: TSaveDialog;
- btnSave: TButton;
- btnLoad: TButton;
- btnReset: TButton;
- btnCancel: TButton;
- btnOK: TButton;
- btnClear: TButton;
- FilterComboBox: TComboBox;
- spinf1: TMMSpinButton;
- spinf2: TMMSpinButton;
- spinGain: TMMSpinButton;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Bevel1: TBevel;
- Label4: TLabel;
- btnAdd: TButton;
- Spectrum: TMMSpectrum;
- TmpEQ: TMMEqualizer;
- mef1: TMMFloatNumberEdit;
- mef2: TMMFloatNumberEdit;
- meGain: TMMFloatNumberEdit;
- procedure btnResetClick(Sender: TObject);
- procedure btnLoadClick(Sender: TObject);
- procedure btnSaveClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure btnClearClick(Sender: TObject);
- procedure FilterComboBoxChange(Sender: TObject);
- procedure spinChange(Sender: TObject);
- procedure btnAddClick(Sender: TObject);
- procedure maskKeyPress(Sender: TObject; var Key: Char);
- procedure maskExit(Sender: TObject);
- procedure FormShow(Sender: TObject);
- private
- FTitle: String;
- FEQ: TMMEqualizer;
- FBandChange: Boolean;
- procedure SetTitle(aValue: String);
- procedure SetEQ(aValue: TMMEqualizer);
- procedure SetBandChange(aValue: Boolean);
- procedure UpdateControls;
- procedure FillComboBox;
- public
- property BandChange: Boolean read FBandChange write SetBandChange;
- property Title: String read FTitle write SetTitle;
- property Equalizer: TMMEqualizer read FEQ write SetEQ;
- end;
- {-- TMMEqualizerDialog ------------------------------------------------------}
- TMMEqualizerDialog = class(TMMNonVisualComponent)
- private
- FSource : TMMEqualizer;
- FTitle : string;
- FBandChange: Boolean;
- procedure SetSource(aSource: TMMEqualizer);
- protected
- procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- public
- constructor Create(AOwner: TComponent); override;
- function Execute: Boolean;
- published
- property AllowBandChange: Boolean read FBandChange write FBandChange;
- property Source: TMMEqualizer read FSource write SetSource;
- property Title: string read FTitle write FTitle;
- end;
- var
- MMEQDlgForm: TMMEQDlgForm;
- implementation
- {$R *.DFM}
- {== TMMEQDlgForm ==============================================================}
- procedure TMMEQDlgForm.FormCreate(Sender: TObject);
- begin
- FTitle := Caption;
- FEQ := nil;
- FBandChange := True;
- FilterComboBox.ItemIndex := -1;
- end;
- {-- TMMEQDlgForm --------------------------------------------------------------}
- procedure TMMEQDlgForm.FormShow(Sender: TObject);
- begin
- {$IFDEF BUILD_ACTIVEX}
- TmpEQ.Left := -50;
- {$ENDIF}
- end;
- {-- TMMEQDlgForm --------------------------------------------------------------}
- procedure TMMEQDlgForm.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- if (ModalResult = mrOK) then
- begin
- if (FEQ <> nil) then FEQ.Assign(TmpEQ);
- end;
- end;
- {-- TMMEQDlgForm --------------------------------------------------------------}
- procedure TMMEQDlgForm.SetTitle(aValue: String);
- begin
- if (aValue <> FTitle) then
- begin
- FTitle := aValue;
- Caption := FTitle + ' - ' + TmpEQ.Description;
- end;
- end;
- {-- TMMEQDlgForm --------------------------------------------------------------}
- procedure TMMEQDlgForm.SetBandChange(aValue: Boolean);
- begin
- if (aValue <> FBandChange) then
- begin
- FBandChange := aValue;
- btnAdd.Enabled := FBandChange;
- btnClear.Enabled := FBandChange;
- end;
- end;
- {-- TMMEQDlgForm --------------------------------------------------------------}
- procedure TMMEQDlgForm.FillComboBox;
- var
- i,old: integer;
- begin
- with FilterComboBox,TmpEQ do
- begin
- old := Max(ItemIndex,0);
- Items.Clear;
- for i := 0 to Filters.Count-1 do
- with Filters[i] do
- begin
- Items.Add(IntToStr(i+1));
- end;
- if (old >= 0) and (old < Items.Count) then ItemIndex := old;
- FilterComboBoxChange(FilterComboBox);
- end;
- end;
- {-- TMMEQDlgForm --------------------------------------------------------------}
- procedure TMMEQDlgForm.FilterComboBoxChange(Sender: TObject);
- begin
- with FilterComboBox,TmpEQ do
- begin
- if (ItemIndex >= 0) then
- with TmpEQ.Filters[ItemIndex] do
- begin
- mef1.Value := f1;
- mef2.Value := f2;
- meGain.Value := Gain;
- spinf1.Value := Trunc(f1*100);
- spinf2.Value := Trunc(f2*100);
- spinGain.Value := Trunc(Gain*100);
- mef1.Enabled := True;
- mef2.Enabled := True;
- meGain.Enabled := True;
- spinf1.Enabled := True;
- spinf2.Enabled := True;
- spinGain.Enabled:= True;
- end
- else
- begin
- mef1.Value := 0;
- mef2.Value := 0;
- meGain.Value := 0;
- spinf1.Value := 0;
- spinf2.Value := 0;
- spinGain.Value := 0;
- mef1.Enabled := False;
- mef2.Enabled := False;
- meGain.Enabled := False;
- spinf1.Enabled := False;
- spinf2.Enabled := False;
- spinGain.Enabled:= False;
- end;
- end;
- end;
- {-- TMMEQDlgForm --------------------------------------------------------------}
- procedure TMMEQDlgForm.spinChange(Sender: TObject);
- begin
- if FilterComboBox.ItemIndex >= 0 then
- with TmpEQ.Filters[FilterComboBox.ItemIndex] do
- begin
- if Sender = spinf1 then
- begin
- f1 := spinf1.Value/100;
- mef1.Value := f1;
- end
- else if Sender = spinf2 then
- begin
- f2 := spinf2.Value/100;
- mef2.Value := f2;
- end
- else
- begin
- Gain := spinGain.Value/100;
- meGain.Value := Gain;
- end;
- end;
- end;
- {-- TMMEQDlgForm --------------------------------------------------------------}
- procedure TMMEQDlgForm.maskKeyPress(Sender: TObject; var Key: Char);
- begin
- if (Key = #13) then TMaskEdit(Sender).OnExit(Sender);
- end;
- {-- TMMEQDlgForm --------------------------------------------------------------}
- procedure TMMEQDlgForm.maskExit(Sender: TObject);
- begin
- spinf1.Value := Trunc(mef1.Value*100);
- spinf2.Value := Trunc(mef2.Value*100);
- spinGain.Value := Trunc(meGain.Value*100);
- end;
- {-- TMMEQDlgForm --------------------------------------------------------------}
- procedure TMMEQDlgForm.UpdateControls;
- begin
- with TmpEQ do
- begin
- Caption := Title + ' - '+ Description;
- FillComboBox;
- end;
- end;
- {-- TMMEQDlgForm --------------------------------------------------------------}
- procedure TMMEQDlgForm.SetEQ(aValue: TMMEqualizer);
- begin
- if (aValue <> Nil) then
- begin
- FEQ := aValue;
- TmpEQ.assign(aValue);
- if (TmpEQ.FFTLength > 512) then
- Spectrum.FFTLength := 512
- else
- Spectrum.FFTLength := 256;
- UpdateControls;
- end;
- end;
- {-- TMMEQDlgForm --------------------------------------------------------------}
- procedure TMMEQDlgForm.btnAddClick(Sender: TObject);
- var
- idx: integer;
- begin
- if not FBandChange then exit;
- idx := TmpEQ.Filters.AddObject(TMMEQFilter.Create);
- FillComboBox;
- FilterComboBox.ItemIndex := idx;
- UpdateControls;
- end;
- {-- TMMEQDlgForm --------------------------------------------------------------}
- procedure TMMEQDlgForm.btnResetClick(Sender: TObject);
- begin
- TmpEQ.assign(FEQ);
- UpdateControls;
- end;
- {-- TMMEQDlgForm --------------------------------------------------------------}
- procedure TMMEQDlgForm.btnClearClick(Sender: TObject);
- begin
- if not FBandChange then exit;
- TmpEQ.Filters.FreeAll;
- UpdateControls;
- end;
- {-- TMMEQDlgForm --------------------------------------------------------------}
- procedure TMMEQDlgForm.btnLoadClick(Sender: TObject);
- begin
- if OpenDialog.Execute then
- begin
- TmpEQ.Filters.LoadFromFile(OpenDialog.FileName);
- FilterComboBox.ItemIndex := -1;
- UpdateControls;
- end;
- end;
- {-- TMMEQDlgForm --------------------------------------------------------------}
- procedure TMMEQDlgForm.btnSaveClick(Sender: TObject);
- begin
- if SaveDialog.Execute then
- begin
- TmpEQ.Filters.SaveToFile(SaveDialog.FileName);
- end;
- end;
- {== TMMEqualizerDialog ========================================================}
- constructor TMMEqualizerDialog.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- FTitle := 'Equalizer Editor';
- FSource := nil;
- FBandChange := True;
- ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
- if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
- end;
- {-- TMMEqualizerDialog --------------------------------------------------------}
- procedure TMMEqualizerDialog.SetSource(aSource: TMMEqualizer);
- begin
- if Longint(aSource) = Longint(Self) then exit;
- if (aSource is TMMEqualizer) or (aSource = Nil) then
- begin
- if (FSource <> aSource) then
- begin
- FSource := aSource;
- end;
- end;
- end;
- {-- TMMEqualizerDialog --------------------------------------------------------}
- procedure TMMEqualizerDialog.Notification(AComponent: TComponent; Operation: TOperation);
- begin
- inherited Notification(AComponent, Operation);
- if (Operation = opRemove) and (AComponent = FSource) then
- FSource := Nil;
- end;
- {-- TMMEqualizerDialog --------------------------------------------------------}
- function TMMEqualizerDialog.Execute: Boolean;
- begin
- Result := False;
- if assigned(FSource) then
- begin
- with TMMEQDlgForm.Create(Application) do
- try
- Equalizer := (Self.FSource as TMMEqualizer);
- Title := Self.FTitle;
- BandChange := Self.FBandChange;
- Result := (ShowModal = mrOK);
- finally
- Free;
- end;
- end;
- end;
- end.