MMRvbDlg.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:18k
- {========================================================================}
- {= (c) 1995-98 SwiftSoft Ronald Dittrich =}
- {========================================================================}
- {= All Rights Reserved =}
- {========================================================================}
- {= D 01099 Dresden = Tel.: +0351-8012255 =}
- {= 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: 20.01.1998 - 18:00:00 $ =}
- {========================================================================}
- unit MMRvbDlg;
- {$I COMPILER.INC}
- interface
- uses
- {$IFDEF WIN32}
- Windows,
- {$ELSE}
- WinTypes,
- WinProcs,
- {$ENDIF}
- SysUtils,
- Messages,
- Consts,
- Classes,
- Dialogs,
- StdCtrls,
- Controls,
- ExtCtrls,
- Forms,
- MMObj,
- MMUtils,
- MMReverb,
- MMLEDS,
- MMSpin,
- MMSlider,
- MMString,
- MMEdit;
- type
- {-- TMMReverbDlg ------------------------------------------------------}
- TMMReverbDlg = class(TForm)
- OpenDialog: TOpenDialog;
- SaveDialog: TSaveDialog;
- btnSave: TButton;
- btnLoad: TButton;
- btnReset: TButton;
- btnCancel: TButton;
- btnOK: TButton;
- Label1: TLabel;
- Bevel2: TBevel;
- Label3: TLabel;
- Label5: TLabel;
- Bevel4: TBevel;
- Label6: TLabel;
- Label7: TLabel;
- Label8: TLabel;
- Bevel5: TBevel;
- Label17: TLabel;
- CheckBoxFilter: TCheckBox;
- Label4: TLabel;
- Label18: TLabel;
- Label19: TLabel;
- btnPreview: TButton;
- btnClear: TButton;
- Label20: TLabel;
- CheckBoxLine1: TCheckBox;
- CheckBoxLine2: TCheckBox;
- CheckBoxLine3: TCheckBox;
- CheckBoxLine4: TCheckBox;
- CheckBoxLine5: TCheckBox;
- CheckBoxLine6: TCheckBox;
- CheckBoxLine7: TCheckBox;
- CheckBoxLine8: TCheckBox;
- Label2: TLabel;
- LED1: TMMLED;
- Label9: TLabel;
- Timer1: TTimer;
- SliderInputGain: TMMSlider;
- SliderInputPan: TMMSlider;
- SliderOutputGain: TMMSlider;
- spinDelay1: TMMSpinButton;
- spinGain1: TMMSpinButton;
- spinDelay2: TMMSpinButton;
- spinDelay3: TMMSpinButton;
- spinDelay4: TMMSpinButton;
- spinDelay5: TMMSpinButton;
- spinDelay6: TMMSpinButton;
- spinDelay7: TMMSpinButton;
- spinDelay8: TMMSpinButton;
- spinFeedBack: TMMSpinButton;
- spinGain2: TMMSpinButton;
- spinGain3: TMMSpinButton;
- spinGain4: TMMSpinButton;
- spinGain5: TMMSpinButton;
- spinGain6: TMMSpinButton;
- spinGain7: TMMSpinButton;
- spinGain8: TMMSpinButton;
- edInputGain: TMMNumberEdit;
- edInputPan: TMMNumberEdit;
- edOutputGain: TMMNumberEdit;
- Bevel1: TBevel;
- Bevel3: TBevel;
- edDelay1: TMMNumberEdit;
- edDelay2: TMMNumberEdit;
- edDelay3: TMMNumberEdit;
- edDelay4: TMMNumberEdit;
- edDelay5: TMMNumberEdit;
- edDelay6: TMMNumberEdit;
- edDelay7: TMMNumberEdit;
- edDelay8: TMMNumberEdit;
- edGain1: TMMNumberEdit;
- edGain2: TMMNumberEdit;
- edGain3: TMMNumberEdit;
- edGain4: TMMNumberEdit;
- edGain5: TMMNumberEdit;
- edGain6: TMMNumberEdit;
- edGain7: TMMNumberEdit;
- edGain8: TMMNumberEdit;
- edFeedBack: TMMNumberEdit;
- procedure btnResetClick(Sender: TObject);
- procedure btnLoadClick(Sender: TObject);
- procedure btnSaveClick(Sender: TObject);
- procedure SliderTrack(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure btnPreviewClick(Sender: TObject);
- procedure btnClearClick(Sender: TObject);
- procedure CheckBoxLineClick(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- procedure edExit(Sender: TObject);
- procedure spinChange(Sender: TObject);
- procedure edGainExit(Sender: TObject);
- private
- FOldEvent: TNotifyEvent;
- FReverb,FOrigReverb,FTmpReverb: TMMReverb;
- FTitle: String;
- procedure SetTitle(aValue: String);
- procedure SetReverb(aValue: TMMReverb);
- procedure UpdateControls;
- procedure UpdateReverb;
- procedure Overflow(Sender: TObject);
- public
- property Title: String read FTitle write SetTitle;
- property Reverb: TMMReverb write SetReverb;
- end;
- {-- TMMReverbDialog ---------------------------------------------------}
- TMMReverbDialog = class(TMMNonVisualComponent)
- private
- FPreview: Boolean;
- FSource: TMMReverb;
- FTitle : string;
- procedure SetSource(aSource: TMMReverb);
- protected
- procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- public
- constructor Create(AOwner: TComponent); override;
- function Execute: Boolean;
- published
- property Preview: Boolean read FPreview write FPreview;
- property Source: TMMReverb read FSource write SetSource;
- property Title: string read FTitle write FTitle;
- end;
- var
- MMReverbDlg: TMMReverbDlg;
- implementation
- {$R *.DFM}
- {== TMMReverbDlg ========================================================}
- procedure TMMReverbDlg.FormCreate(Sender: TObject);
- var
- i: integer;
- begin
- FTitle := Caption;
- FReverb := nil;
- FTmpReverb := TMMReverb.Create(Self);
- FOrigReverb := TMMReverb.Create(Self);
- {$IFDEF BUILD_ACTIVEX}
- FTmpReverb.Left := -50;
- FOrigReverb.Left := -50;
- {$ENDIF}
- for i := 0 to ComponentCount-1 do
- if (Components[i] is TMMSpinButton) then
- begin
- if (TMMSpinButton(Components[i]).FocusControl <> nil) then
- TMMSpinButton(Components[i]).FocusControl.Tag := Longint(Components[i]);
- end;
- end;
- {-- TMMReverbDialog -----------------------------------------------------}
- procedure TMMReverbDlg.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- if (ModalResult <> mrOK) then
- begin
- if (FReverb <> nil) then
- begin
- FReverb.Assign(FOrigReverb);
- FReverb.OnPcmOverflow := FOldEvent;
- end;
- end
- else
- begin
- UpdateReverb;
- if (FReverb <> nil) then
- begin
- FReverb.Assign(FTmpReverb);
- FReverb.OnPcmOverflow := FOldEvent;
- end;
- end;
- end;
- {-- TMMReverbDlg --------------------------------------------------------}
- procedure TMMReverbDlg.FormDestroy(Sender: TObject);
- begin
- FTmpReverb.Free;
- FOrigReverb.Free;
- end;
- {-- TMMReverbDlg --------------------------------------------------------}
- procedure TMMReverbDlg.SetTitle(aValue: String);
- begin
- if (aValue <> FTitle) then
- begin
- FTitle := aValue;
- Caption := FTitle + ' - ' + FTmpReverb.Description;
- end;
- end;
- {-- TMMReverbDlg --------------------------------------------------------}
- procedure TMMReverbDlg.UpdateControls;
- begin
- with FTmpReverb do
- begin
- Caption := Title + ' - '+ Description;
- SliderInputGain.Position := InputGain;
- edInputGain.Value := InputGain;
- SliderInputPan.Position := InputPan;
- edInputPan.Value := InputPan;
- SliderOutputGain.Position:= OutputGain;
- edOutputGain.Value := OutputGain;
- SpinFeedBack.Value := FeedBack;
- CheckBoxFilter.Checked := Filter;
- SpinDelay1.MaxValue := MaxDelay;
- SpinDelay1.Value := Echos[0].Delay;
- SpinGain1.Value := Echos[0].Gain;
- CheckBoxLine1.Checked:= True;
- SpinDelay2.MaxValue := MaxDelay;
- SpinDelay2.Value := Echos[1].Delay;
- SpinGain2.Value := Echos[1].Gain;
- CheckBoxLine2.Checked:= True;
- SpinDelay3.MaxValue := MaxDelay;
- SpinDelay3.Value := Echos[2].Delay;
- SpinGain3.Value := Echos[2].Gain;
- CheckBoxLine3.Checked:= True;
- SpinDelay4.MaxValue := MaxDelay;
- SpinDelay4.Value := Echos[3].Delay;
- SpinGain4.Value := Echos[3].Gain;
- CheckBoxLine4.Checked:= True;
- SpinDelay5.MaxValue := MaxDelay;
- SpinDelay5.Value := Echos[4].Delay;
- SpinGain5.Value := Echos[4].Gain;
- CheckBoxLine5.Checked:= True;
- SpinDelay6.MaxValue := MaxDelay;
- SpinDelay6.Value := Echos[5].Delay;
- SpinGain6.Value := Echos[5].Gain;
- CheckBoxLine6.Checked:= True;
- SpinDelay7.MaxValue := MaxDelay;
- SpinDelay7.Value := Echos[6].Delay;
- SpinGain7.Value := Echos[6].Gain;
- CheckBoxLine7.Checked:= True;
- SpinDelay8.MaxValue := MaxDelay;
- SpinDelay8.Value := Echos[7].Delay;
- SpinGain8.Value := Echos[7].Gain;
- CheckBoxLine8.Checked:= True;
- end;
- end;
- {-- TMMReverbDlg --------------------------------------------------------}
- procedure TMMReverbDlg.UpdateReverb;
- begin
- with FTmpReverb do
- begin
- InputGain := SliderInputGain.Position;
- InputPan := SliderInputPan.Position;
- OutputGain := SliderOutputGain.Position;
- FeedBack := SpinFeedBack.Value;
- Filter := CheckBoxFilter.Checked;
- if CheckBoxLine1.Checked then
- Echos[0].SetParams(SpinDelay1.Value,SpinGain1.Value)
- else
- Echos[0].SetParams(0,0);
- if CheckBoxLine2.Checked then
- Echos[1].SetParams(SpinDelay2.Value,SpinGain2.Value)
- else
- Echos[1].SetParams(0,0);
- if CheckBoxLine3.Checked then
- Echos[2].SetParams(SpinDelay3.Value,SpinGain3.Value)
- else
- Echos[2].SetParams(0,0);
- if CheckBoxLine4.Checked then
- Echos[3].SetParams(SpinDelay4.Value,SpinGain4.Value)
- else
- Echos[3].SetParams(0,0);
- if CheckBoxLine5.Checked then
- Echos[4].SetParams(SpinDelay5.Value,SpinGain5.Value)
- else
- Echos[4].SetParams(0,0);
- if CheckBoxLine6.Checked then
- Echos[5].SetParams(SpinDelay6.Value,SpinGain6.Value)
- else
- Echos[5].SetParams(0,0);
- if CheckBoxLine7.Checked then
- Echos[6].SetParams(SpinDelay7.Value,SpinGain7.Value)
- else
- Echos[6].SetParams(0,0);
- if CheckBoxLine8.Checked then
- Echos[7].SetParams(SpinDelay8.Value,SpinGain8.Value)
- else
- Echos[7].SetParams(0,0);
- end;
- end;
- {-- TMMReverbDlg --------------------------------------------------------}
- procedure TMMReverbDlg.SetReverb(aValue: TMMReverb);
- begin
- if (aValue <> Nil) then
- begin
- FReverb := aValue;
- FOldEvent := FReverb.OnPcmOverflow;
- FReverb.OnPcmOverflow := Overflow;
- FTmpReverb.assign(aValue);
- FOrigReverb.assign(aValue);
- UpdateControls;
- end;
- end;
- {-- TMMReverbDlg --------------------------------------------------------}
- procedure TMMReverbDlg.btnResetClick(Sender: TObject);
- begin
- FTmpReverb.assign(FOrigReverb);
- UpdateControls;
- end;
- {-- TMMReverbDlg --------------------------------------------------------}
- procedure TMMReverbDlg.btnClearClick(Sender: TObject);
- var
- i: integer;
- begin
- with FTmpReverb do
- begin
- InputGain := 50;
- InputPan := 0;
- OutputGain := 50;
- FeedBack := 0;
- Filter := False;
- for i := 0 to Echos.Count-1 do
- begin
- Echos[i].Delay := 0;
- Echos[i].Gain := 0;
- end;
- UpdateControls;
- end;
- end;
- {-- TMMReverbDlg --------------------------------------------------------}
- procedure TMMReverbDlg.btnLoadClick(Sender: TObject);
- begin
- if OpenDialog.Execute then
- begin
- FTmpReverb.Echos.LoadFromFile(OpenDialog.FileName);
- UpdateControls;
- end;
- end;
- {-- TMMReverbDlg --------------------------------------------------------}
- procedure TMMReverbDlg.btnSaveClick(Sender: TObject);
- begin
- if SaveDialog.Execute then
- begin
- UpdateReverb;
- FTmpReverb.Echos.SaveToFile(SaveDialog.FileName);
- end;
- end;
- {-- TMMReverbDlg --------------------------------------------------------}
- procedure TMMReverbDlg.SliderTrack(Sender: TObject);
- begin
- if (Sender = SliderInputGain) then
- begin
- edInputGain.Value := SliderInputGain.Position;
- end
- else if (Sender = SliderInputPan) then
- begin
- edInputPan.Value := SliderInputPan.Position;
- end
- else if (Sender = SliderOutputGain) then
- begin
- edOutputGain.Value := SliderOutputGain.Position;
- end;
- end;
- {-- TMMReverbDlg --------------------------------------------------------}
- procedure TMMReverbDlg.edGainExit(Sender: TObject);
- begin
- if (Sender = edInputGain) then
- begin
- SliderInputGain.Position := edInputGain.Value;
- end
- else if (Sender = edInputPan) then
- begin
- SliderInputPan.Position := edInputPan.Value;
- end
- else if (Sender = edOutputGain) then
- begin
- SliderOutputGain.Position := edOutputGain.Value;
- end;
- end;
- {-- TMMReverbDialog -----------------------------------------------------}
- procedure TMMReverbDlg.edExit(Sender: TObject);
- var
- spin: TMMSpinButton;
- begin
- if TMMNumberEdit(Sender).Tag <> 0 then
- begin
- spin := TMMSpinButton(TMMNumberEdit(Sender).Tag);
- spin.Value := TMMNumberEdit(Sender).Value;
- end;
- end;
- {-- TMMReverbDialog -----------------------------------------------------}
- procedure TMMReverbDlg.spinChange(Sender: TObject);
- var
- Val: integer;
- begin
- if (TMMSpinButton(Sender).FocusControl <> nil) then
- begin
- Val := TMMSpinButton(Sender).Value;
- TMMNumberEdit(TMMSpinButton(Sender).FocusControl).Value := Val;
- end;
- end;
- {-- TMMReverbDlg --------------------------------------------------------}
- procedure TMMReverbDlg.CheckBoxLineClick(Sender: TObject);
- begin
- with (Sender as TCheckBox) do
- begin
- if Checked then
- begin
- TMMSpinButton(Self.FindComponent('spinDelay'+Name[Length(Name)])).Enabled := True;
- TMMSpinButton(Self.FindComponent('spinGain'+Name[Length(Name)])).Enabled := True;
- TMMNumberEdit(Self.FindComponent('edDelay'+Name[Length(Name)])).Enabled := True;
- TMMNumberEdit(Self.FindComponent('edGain'+Name[Length(Name)])).Enabled := True;
- end
- else
- begin
- TMMSpinButton(Self.FindComponent('spinDelay'+Name[Length(Name)])).Enabled := False;
- TMMSpinButton(Self.FindComponent('spinGain'+Name[Length(Name)])).Enabled := False;
- TMMNumberEdit(Self.FindComponent('edDelay'+Name[Length(Name)])).Enabled := False;
- TMMNumberEdit(Self.FindComponent('edGain'+Name[Length(Name)])).Enabled := False;
- end;
- end
- end;
- {-- TMMReverbDlg --------------------------------------------------------}
- procedure TMMReverbDlg.btnPreviewClick(Sender: TObject);
- begin
- UpdateReverb;
- if (FReverb <> nil) then FReverb.assign(FTmpReverb);
- end;
- {-- TMMReverbDlg --------------------------------------------------------}
- procedure TMMReverbDlg.Overflow(Sender: TObject);
- begin
- LED1.Enabled := True;
- Timer1.Enabled := True;
- end;
- {-- TMMReverbDlg --------------------------------------------------------}
- procedure TMMReverbDlg.Timer1Timer(Sender: TObject);
- begin
- LED1.Enabled := False;
- Timer1.Enabled := False;
- end;
- {== TMMReverbDialog =====================================================}
- constructor TMMReverbDialog.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- FPreview := True;
- FTitle := 'Reverb Editor';
- FSource := nil;
- ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
- if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
- end;
- {-- TMMReverbDialog -----------------------------------------------------}
- procedure TMMReverbDialog.SetSource(aSource: TMMReverb);
- begin
- if Longint(aSource) = Longint(Self) then exit;
- if (aSource is TMMReverb) or (aSource = Nil) then
- begin
- if (FSource <> aSource) then
- begin
- FSource := aSource;
- end;
- end;
- end;
- {-- TMMReverbDialog -----------------------------------------------------}
- procedure TMMReverbDialog.Notification(AComponent: TComponent; Operation: TOperation);
- begin
- inherited Notification(AComponent, Operation);
- if (Operation = opRemove) and (AComponent = FSource) then
- FSource := Nil;
- end;
- {-- TMMReverbDialog -----------------------------------------------------}
- function TMMReverbDialog.Execute: Boolean;
- begin
- Result := False;
- if assigned(FSource) then
- begin
- MMReverbDlg := TMMReverbDlg.Create(Application);
- try
- MMreverbDlg.btnPreview.Enabled := FPreview;
- MMReverbDlg.Reverb := (FSource as TMMReverb);
- MMReverbDlg.Title := FTitle;
- Result := (MMReverbDlg.ShowModal = mrOK);
- finally
- MMReverbDlg.Free;
- end;
- end;
- end;
- end.