MMRvbDlg.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:18k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. {========================================================================}
  2. {=                (c) 1995-98 SwiftSoft Ronald Dittrich                 =}
  3. {========================================================================}
  4. {=                          All Rights Reserved                         =}
  5. {========================================================================}
  6. {=  D 01099 Dresden             = Tel.: +0351-8012255                   =}
  7. {=  Loewenstr.7a                = info@swiftsoft.de                     =}
  8. {========================================================================}
  9. {=  Actual versions on http://www.swiftsoft.de/mmtools.html             =}
  10. {========================================================================}
  11. {=  This code is for reference purposes only and may not be copied or   =}
  12. {=  distributed in any format electronic or otherwise except one copy   =}
  13. {=  for backup purposes.                                                =}
  14. {=                                                                      =}
  15. {=  No Delphi Component Kit or Component individually or in a collection=}
  16. {=  subclassed or otherwise from the code in this unit, or associated   =}
  17. {=  .pas, .dfm, .dcu, .asm or .obj files may be sold or distributed     =}
  18. {=  without express permission from SwiftSoft.                          =}
  19. {=                                                                      =}
  20. {=  For more licence informations please refer to the associated        =}
  21. {=  HelpFile.                                                           =}
  22. {========================================================================}
  23. {=  $Date: 20.01.1998 - 18:00:00 $                                      =}
  24. {========================================================================}
  25. unit MMRvbDlg;
  26. {$I COMPILER.INC}
  27. interface
  28. uses
  29. {$IFDEF WIN32}
  30.     Windows,
  31. {$ELSE}
  32.     WinTypes,
  33.     WinProcs,
  34. {$ENDIF}
  35.     SysUtils,
  36.     Messages,
  37.     Consts,
  38.     Classes,
  39.     Dialogs,
  40.     StdCtrls,
  41.     Controls,
  42.     ExtCtrls,
  43.     Forms,
  44.     MMObj,
  45.     MMUtils,
  46.     MMReverb,
  47.     MMLEDS,
  48.     MMSpin,
  49.     MMSlider,
  50.     MMString,
  51.     MMEdit;
  52. type
  53.   {-- TMMReverbDlg ------------------------------------------------------}
  54.   TMMReverbDlg = class(TForm)
  55.     OpenDialog: TOpenDialog;
  56.     SaveDialog: TSaveDialog;
  57.     btnSave: TButton;
  58.     btnLoad: TButton;
  59.     btnReset: TButton;
  60.     btnCancel: TButton;
  61.     btnOK: TButton;
  62.     Label1: TLabel;
  63.     Bevel2: TBevel;
  64.     Label3: TLabel;
  65.     Label5: TLabel;
  66.     Bevel4: TBevel;
  67.     Label6: TLabel;
  68.     Label7: TLabel;
  69.     Label8: TLabel;
  70.     Bevel5: TBevel;
  71.     Label17: TLabel;
  72.     CheckBoxFilter: TCheckBox;
  73.     Label4: TLabel;
  74.     Label18: TLabel;
  75.     Label19: TLabel;
  76.     btnPreview: TButton;
  77.     btnClear: TButton;
  78.     Label20: TLabel;
  79.     CheckBoxLine1: TCheckBox;
  80.     CheckBoxLine2: TCheckBox;
  81.     CheckBoxLine3: TCheckBox;
  82.     CheckBoxLine4: TCheckBox;
  83.     CheckBoxLine5: TCheckBox;
  84.     CheckBoxLine6: TCheckBox;
  85.     CheckBoxLine7: TCheckBox;
  86.     CheckBoxLine8: TCheckBox;
  87.     Label2: TLabel;
  88.     LED1: TMMLED;
  89.     Label9: TLabel;
  90.     Timer1: TTimer;
  91.     SliderInputGain: TMMSlider;
  92.     SliderInputPan: TMMSlider;
  93.     SliderOutputGain: TMMSlider;
  94.     spinDelay1: TMMSpinButton;
  95.     spinGain1: TMMSpinButton;
  96.     spinDelay2: TMMSpinButton;
  97.     spinDelay3: TMMSpinButton;
  98.     spinDelay4: TMMSpinButton;
  99.     spinDelay5: TMMSpinButton;
  100.     spinDelay6: TMMSpinButton;
  101.     spinDelay7: TMMSpinButton;
  102.     spinDelay8: TMMSpinButton;
  103.     spinFeedBack: TMMSpinButton;
  104.     spinGain2: TMMSpinButton;
  105.     spinGain3: TMMSpinButton;
  106.     spinGain4: TMMSpinButton;
  107.     spinGain5: TMMSpinButton;
  108.     spinGain6: TMMSpinButton;
  109.     spinGain7: TMMSpinButton;
  110.     spinGain8: TMMSpinButton;
  111.     edInputGain: TMMNumberEdit;
  112.     edInputPan: TMMNumberEdit;
  113.     edOutputGain: TMMNumberEdit;
  114.     Bevel1: TBevel;
  115.     Bevel3: TBevel;
  116.     edDelay1: TMMNumberEdit;
  117.     edDelay2: TMMNumberEdit;
  118.     edDelay3: TMMNumberEdit;
  119.     edDelay4: TMMNumberEdit;
  120.     edDelay5: TMMNumberEdit;
  121.     edDelay6: TMMNumberEdit;
  122.     edDelay7: TMMNumberEdit;
  123.     edDelay8: TMMNumberEdit;
  124.     edGain1: TMMNumberEdit;
  125.     edGain2: TMMNumberEdit;
  126.     edGain3: TMMNumberEdit;
  127.     edGain4: TMMNumberEdit;
  128.     edGain5: TMMNumberEdit;
  129.     edGain6: TMMNumberEdit;
  130.     edGain7: TMMNumberEdit;
  131.     edGain8: TMMNumberEdit;
  132.     edFeedBack: TMMNumberEdit;
  133.     procedure btnResetClick(Sender: TObject);
  134.     procedure btnLoadClick(Sender: TObject);
  135.     procedure btnSaveClick(Sender: TObject);
  136.     procedure SliderTrack(Sender: TObject);
  137.     procedure FormCreate(Sender: TObject);
  138.     procedure FormDestroy(Sender: TObject);
  139.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  140.     procedure btnPreviewClick(Sender: TObject);
  141.     procedure btnClearClick(Sender: TObject);
  142.     procedure CheckBoxLineClick(Sender: TObject);
  143.     procedure Timer1Timer(Sender: TObject);
  144.     procedure edExit(Sender: TObject);
  145.     procedure spinChange(Sender: TObject);
  146.     procedure edGainExit(Sender: TObject);
  147.   private
  148.     FOldEvent: TNotifyEvent;
  149.     FReverb,FOrigReverb,FTmpReverb: TMMReverb;
  150.     FTitle: String;
  151.     procedure SetTitle(aValue: String);
  152.     procedure SetReverb(aValue: TMMReverb);
  153.     procedure UpdateControls;
  154.     procedure UpdateReverb;
  155.     procedure Overflow(Sender: TObject);
  156.   public
  157.     property Title: String read FTitle write SetTitle;
  158.     property Reverb: TMMReverb write SetReverb;
  159.   end;
  160.   {-- TMMReverbDialog ---------------------------------------------------}
  161.   TMMReverbDialog = class(TMMNonVisualComponent)
  162.   private
  163.     FPreview: Boolean;
  164.     FSource: TMMReverb;
  165.     FTitle : string;
  166.     procedure SetSource(aSource: TMMReverb);
  167.   protected
  168.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  169.   public
  170.     constructor Create(AOwner: TComponent); override;
  171.     function Execute: Boolean;
  172.   published
  173.     property Preview: Boolean read FPreview write FPreview;
  174.     property Source: TMMReverb read FSource write SetSource;
  175.     property Title: string read FTitle write FTitle;
  176.   end;
  177. var
  178.   MMReverbDlg: TMMReverbDlg;
  179. implementation
  180. {$R *.DFM}
  181. {== TMMReverbDlg ========================================================}
  182. procedure TMMReverbDlg.FormCreate(Sender: TObject);
  183. var
  184.    i: integer;
  185. begin
  186.    FTitle := Caption;
  187.    FReverb := nil;
  188.    FTmpReverb := TMMReverb.Create(Self);
  189.    FOrigReverb := TMMReverb.Create(Self);
  190.    {$IFDEF BUILD_ACTIVEX}
  191.    FTmpReverb.Left := -50;
  192.    FOrigReverb.Left := -50;
  193.    {$ENDIF}
  194.    for i := 0 to ComponentCount-1 do
  195.    if (Components[i] is TMMSpinButton) then
  196.    begin
  197.       if (TMMSpinButton(Components[i]).FocusControl <> nil) then
  198.           TMMSpinButton(Components[i]).FocusControl.Tag := Longint(Components[i]);
  199.    end;
  200. end;
  201. {-- TMMReverbDialog -----------------------------------------------------}
  202. procedure TMMReverbDlg.FormClose(Sender: TObject; var Action: TCloseAction);
  203. begin
  204.    if (ModalResult <> mrOK) then
  205.    begin
  206.       if (FReverb <> nil) then
  207.       begin
  208.          FReverb.Assign(FOrigReverb);
  209.          FReverb.OnPcmOverflow := FOldEvent;
  210.       end;
  211.    end
  212.    else
  213.    begin
  214.       UpdateReverb;
  215.       if (FReverb <> nil) then
  216.       begin
  217.          FReverb.Assign(FTmpReverb);
  218.          FReverb.OnPcmOverflow := FOldEvent;
  219.       end;
  220.    end;
  221. end;
  222. {-- TMMReverbDlg --------------------------------------------------------}
  223. procedure TMMReverbDlg.FormDestroy(Sender: TObject);
  224. begin
  225.    FTmpReverb.Free;
  226.    FOrigReverb.Free;
  227. end;
  228. {-- TMMReverbDlg --------------------------------------------------------}
  229. procedure TMMReverbDlg.SetTitle(aValue: String);
  230. begin
  231.    if (aValue <> FTitle) then
  232.    begin
  233.       FTitle := aValue;
  234.       Caption := FTitle + ' -  ' + FTmpReverb.Description;
  235.    end;
  236. end;
  237. {-- TMMReverbDlg --------------------------------------------------------}
  238. procedure TMMReverbDlg.UpdateControls;
  239. begin
  240.    with FTmpReverb do
  241.    begin
  242.       Caption                  := Title + ' -  '+ Description;
  243.       SliderInputGain.Position := InputGain;
  244.       edInputGain.Value        := InputGain;
  245.       SliderInputPan.Position  := InputPan;
  246.       edInputPan.Value         := InputPan;
  247.       SliderOutputGain.Position:= OutputGain;
  248.       edOutputGain.Value       := OutputGain;
  249.       SpinFeedBack.Value       := FeedBack;
  250.       CheckBoxFilter.Checked   := Filter;
  251.       SpinDelay1.MaxValue  := MaxDelay;
  252.       SpinDelay1.Value     := Echos[0].Delay;
  253.       SpinGain1.Value      := Echos[0].Gain;
  254.       CheckBoxLine1.Checked:= True;
  255.       SpinDelay2.MaxValue  := MaxDelay;
  256.       SpinDelay2.Value     := Echos[1].Delay;
  257.       SpinGain2.Value      := Echos[1].Gain;
  258.       CheckBoxLine2.Checked:= True;
  259.       SpinDelay3.MaxValue  := MaxDelay;
  260.       SpinDelay3.Value     := Echos[2].Delay;
  261.       SpinGain3.Value      := Echos[2].Gain;
  262.       CheckBoxLine3.Checked:= True;
  263.       SpinDelay4.MaxValue  := MaxDelay;
  264.       SpinDelay4.Value     := Echos[3].Delay;
  265.       SpinGain4.Value      := Echos[3].Gain;
  266.       CheckBoxLine4.Checked:= True;
  267.       SpinDelay5.MaxValue  := MaxDelay;
  268.       SpinDelay5.Value     := Echos[4].Delay;
  269.       SpinGain5.Value      := Echos[4].Gain;
  270.       CheckBoxLine5.Checked:= True;
  271.       SpinDelay6.MaxValue  := MaxDelay;
  272.       SpinDelay6.Value     := Echos[5].Delay;
  273.       SpinGain6.Value      := Echos[5].Gain;
  274.       CheckBoxLine6.Checked:= True;
  275.       SpinDelay7.MaxValue  := MaxDelay;
  276.       SpinDelay7.Value     := Echos[6].Delay;
  277.       SpinGain7.Value      := Echos[6].Gain;
  278.       CheckBoxLine7.Checked:= True;
  279.       SpinDelay8.MaxValue  := MaxDelay;
  280.       SpinDelay8.Value     := Echos[7].Delay;
  281.       SpinGain8.Value      := Echos[7].Gain;
  282.       CheckBoxLine8.Checked:= True;
  283.    end;
  284. end;
  285. {-- TMMReverbDlg --------------------------------------------------------}
  286. procedure TMMReverbDlg.UpdateReverb;
  287. begin
  288.    with FTmpReverb do
  289.    begin
  290.       InputGain  := SliderInputGain.Position;
  291.       InputPan   := SliderInputPan.Position;
  292.       OutputGain := SliderOutputGain.Position;
  293.       FeedBack   := SpinFeedBack.Value;
  294.       Filter     := CheckBoxFilter.Checked;
  295.       if CheckBoxLine1.Checked then
  296.          Echos[0].SetParams(SpinDelay1.Value,SpinGain1.Value)
  297.       else
  298.          Echos[0].SetParams(0,0);
  299.       if CheckBoxLine2.Checked then
  300.          Echos[1].SetParams(SpinDelay2.Value,SpinGain2.Value)
  301.       else
  302.          Echos[1].SetParams(0,0);
  303.       if CheckBoxLine3.Checked then
  304.          Echos[2].SetParams(SpinDelay3.Value,SpinGain3.Value)
  305.       else
  306.          Echos[2].SetParams(0,0);
  307.       if CheckBoxLine4.Checked then
  308.          Echos[3].SetParams(SpinDelay4.Value,SpinGain4.Value)
  309.       else
  310.          Echos[3].SetParams(0,0);
  311.       if CheckBoxLine5.Checked then
  312.          Echos[4].SetParams(SpinDelay5.Value,SpinGain5.Value)
  313.       else
  314.          Echos[4].SetParams(0,0);
  315.       if CheckBoxLine6.Checked then
  316.          Echos[5].SetParams(SpinDelay6.Value,SpinGain6.Value)
  317.       else
  318.          Echos[5].SetParams(0,0);
  319.       if CheckBoxLine7.Checked then
  320.          Echos[6].SetParams(SpinDelay7.Value,SpinGain7.Value)
  321.       else
  322.          Echos[6].SetParams(0,0);
  323.       if CheckBoxLine8.Checked then
  324.          Echos[7].SetParams(SpinDelay8.Value,SpinGain8.Value)
  325.       else
  326.          Echos[7].SetParams(0,0);
  327.    end;
  328. end;
  329. {-- TMMReverbDlg --------------------------------------------------------}
  330. procedure TMMReverbDlg.SetReverb(aValue: TMMReverb);
  331. begin
  332.    if (aValue <> Nil) then
  333.    begin
  334.       FReverb := aValue;
  335.       FOldEvent := FReverb.OnPcmOverflow;
  336.       FReverb.OnPcmOverflow := Overflow;
  337.       FTmpReverb.assign(aValue);
  338.       FOrigReverb.assign(aValue);
  339.       UpdateControls;
  340.    end;
  341. end;
  342. {-- TMMReverbDlg --------------------------------------------------------}
  343. procedure TMMReverbDlg.btnResetClick(Sender: TObject);
  344. begin
  345.    FTmpReverb.assign(FOrigReverb);
  346.    UpdateControls;
  347. end;
  348. {-- TMMReverbDlg --------------------------------------------------------}
  349. procedure TMMReverbDlg.btnClearClick(Sender: TObject);
  350. var
  351.    i: integer;
  352. begin
  353.    with FTmpReverb do
  354.    begin
  355.       InputGain  := 50;
  356.       InputPan   := 0;
  357.       OutputGain := 50;
  358.       FeedBack   := 0;
  359.       Filter     := False;
  360.       for i := 0 to Echos.Count-1 do
  361.       begin
  362.          Echos[i].Delay := 0;
  363.          Echos[i].Gain := 0;
  364.       end;
  365.       UpdateControls;
  366.    end;
  367. end;
  368. {-- TMMReverbDlg --------------------------------------------------------}
  369. procedure TMMReverbDlg.btnLoadClick(Sender: TObject);
  370. begin
  371.    if OpenDialog.Execute then
  372.    begin
  373.       FTmpReverb.Echos.LoadFromFile(OpenDialog.FileName);
  374.       UpdateControls;
  375.    end;
  376. end;
  377. {-- TMMReverbDlg --------------------------------------------------------}
  378. procedure TMMReverbDlg.btnSaveClick(Sender: TObject);
  379. begin
  380.    if SaveDialog.Execute then
  381.    begin
  382.       UpdateReverb;
  383.       FTmpReverb.Echos.SaveToFile(SaveDialog.FileName);
  384.    end;
  385. end;
  386. {-- TMMReverbDlg --------------------------------------------------------}
  387. procedure TMMReverbDlg.SliderTrack(Sender: TObject);
  388. begin
  389.    if (Sender = SliderInputGain) then
  390.    begin
  391.       edInputGain.Value := SliderInputGain.Position;
  392.    end
  393.    else if (Sender = SliderInputPan) then
  394.    begin
  395.       edInputPan.Value := SliderInputPan.Position;
  396.    end
  397.    else if (Sender = SliderOutputGain) then
  398.    begin
  399.       edOutputGain.Value := SliderOutputGain.Position;
  400.    end;
  401. end;
  402. {-- TMMReverbDlg --------------------------------------------------------}
  403. procedure TMMReverbDlg.edGainExit(Sender: TObject);
  404. begin
  405.    if (Sender = edInputGain) then
  406.    begin
  407.       SliderInputGain.Position := edInputGain.Value;
  408.    end
  409.    else if (Sender = edInputPan) then
  410.    begin
  411.       SliderInputPan.Position := edInputPan.Value;
  412.    end
  413.    else if (Sender = edOutputGain) then
  414.    begin
  415.       SliderOutputGain.Position := edOutputGain.Value;
  416.    end;
  417. end;
  418. {-- TMMReverbDialog -----------------------------------------------------}
  419. procedure TMMReverbDlg.edExit(Sender: TObject);
  420. var
  421.    spin: TMMSpinButton;
  422. begin
  423.    if TMMNumberEdit(Sender).Tag <> 0 then
  424.    begin
  425.       spin := TMMSpinButton(TMMNumberEdit(Sender).Tag);
  426.       spin.Value := TMMNumberEdit(Sender).Value;
  427.    end;
  428. end;
  429. {-- TMMReverbDialog -----------------------------------------------------}
  430. procedure TMMReverbDlg.spinChange(Sender: TObject);
  431. var
  432.    Val: integer;
  433. begin
  434.    if (TMMSpinButton(Sender).FocusControl <> nil) then
  435.    begin
  436.       Val := TMMSpinButton(Sender).Value;
  437.       TMMNumberEdit(TMMSpinButton(Sender).FocusControl).Value := Val;
  438.    end;
  439. end;
  440. {-- TMMReverbDlg --------------------------------------------------------}
  441. procedure TMMReverbDlg.CheckBoxLineClick(Sender: TObject);
  442. begin
  443.    with (Sender as TCheckBox) do
  444.    begin
  445.       if Checked then
  446.       begin
  447.          TMMSpinButton(Self.FindComponent('spinDelay'+Name[Length(Name)])).Enabled := True;
  448.          TMMSpinButton(Self.FindComponent('spinGain'+Name[Length(Name)])).Enabled := True;
  449.          TMMNumberEdit(Self.FindComponent('edDelay'+Name[Length(Name)])).Enabled := True;
  450.          TMMNumberEdit(Self.FindComponent('edGain'+Name[Length(Name)])).Enabled := True;
  451.       end
  452.       else
  453.       begin
  454.          TMMSpinButton(Self.FindComponent('spinDelay'+Name[Length(Name)])).Enabled := False;
  455.          TMMSpinButton(Self.FindComponent('spinGain'+Name[Length(Name)])).Enabled := False;
  456.          TMMNumberEdit(Self.FindComponent('edDelay'+Name[Length(Name)])).Enabled := False;
  457.          TMMNumberEdit(Self.FindComponent('edGain'+Name[Length(Name)])).Enabled := False;
  458.       end;
  459.    end
  460. end;
  461. {-- TMMReverbDlg --------------------------------------------------------}
  462. procedure TMMReverbDlg.btnPreviewClick(Sender: TObject);
  463. begin
  464.    UpdateReverb;
  465.    if (FReverb <> nil) then FReverb.assign(FTmpReverb);
  466. end;
  467. {-- TMMReverbDlg --------------------------------------------------------}
  468. procedure TMMReverbDlg.Overflow(Sender: TObject);
  469. begin
  470.    LED1.Enabled := True;
  471.    Timer1.Enabled := True;
  472. end;
  473. {-- TMMReverbDlg --------------------------------------------------------}
  474. procedure TMMReverbDlg.Timer1Timer(Sender: TObject);
  475. begin
  476.    LED1.Enabled := False;
  477.    Timer1.Enabled := False;
  478. end;
  479. {== TMMReverbDialog =====================================================}
  480. constructor TMMReverbDialog.Create(AOwner: TComponent);
  481. begin
  482.    inherited Create(AOwner);
  483.    FPreview := True;
  484.    FTitle := 'Reverb Editor';
  485.    FSource := nil;
  486.    ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
  487.    if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
  488. end;
  489. {-- TMMReverbDialog -----------------------------------------------------}
  490. procedure TMMReverbDialog.SetSource(aSource: TMMReverb);
  491. begin
  492.    if Longint(aSource) = Longint(Self) then exit;
  493.    if (aSource is TMMReverb) or (aSource = Nil) then
  494.    begin
  495.       if (FSource <> aSource) then
  496.       begin
  497.          FSource := aSource;
  498.       end;
  499.    end;
  500. end;
  501. {-- TMMReverbDialog -----------------------------------------------------}
  502. procedure TMMReverbDialog.Notification(AComponent: TComponent; Operation: TOperation);
  503. begin
  504.    inherited Notification(AComponent, Operation);
  505.    if (Operation = opRemove) and (AComponent = FSource) then
  506.       FSource := Nil;
  507. end;
  508. {-- TMMReverbDialog -----------------------------------------------------}
  509. function TMMReverbDialog.Execute: Boolean;
  510. begin
  511.    Result := False;
  512.    if assigned(FSource) then
  513.    begin
  514.       MMReverbDlg := TMMReverbDlg.Create(Application);
  515.       try
  516.          MMreverbDlg.btnPreview.Enabled := FPreview;
  517.          MMReverbDlg.Reverb := (FSource as TMMReverb);
  518.          MMReverbDlg.Title := FTitle;
  519.          Result := (MMReverbDlg.ShowModal = mrOK);
  520.       finally
  521.          MMReverbDlg.Free;
  522.       end;
  523.    end;
  524. end;
  525. end.