TempoControl.pas 2.99 KB
{ UNIT TempoControl.pas
--------------------------------- TempoControl -----------------------------
 MidiPlayer2 test program

 Copyright 2011 Silhwan Hyun, All Rights Reserved
 This unit is free. It may be used both in commercial and non-commercial software either in
  original or in modified form.
 This unit can be freely distributed in any way and by any means provided this copyright
  notice is preserved.

 Author : Silhwan Hyun   (e-mail addr : hyunsh@hanafos.com)

 Author's comment : Please let me know if you have any idea to improve or to debug this unit.


 Revision History

  Ver 0.9.0    May 28 2012
   - Initial release
----------------------------------------------------------------------------}

unit TempoControl;

{$DEFINE MULTI_LANGUAGE}

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, {$IFDEF MULTI_LANGUAGE}gnugettext,{$ENDIF} ComCtrls;

type
  TTempoControlForm = class(TForm)
    tbTempo: TTrackBar;
    tbPitch: TTrackBar;
    Tempo: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    btnClose: TButton;
    edTempo: TEdit;
    edPitch: TEdit;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    btnReset: TButton;
    procedure FormShow(Sender: TObject);
    procedure tbTempoChange(Sender: TObject);
    procedure tbPitchChange(Sender: TObject);
    procedure btnCloseClick(Sender: TObject);
    procedure btnResetClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  TempoControlForm: TTempoControlForm;

implementation

{$R *.dfm}

uses MIDITest;

procedure TTempoControlForm.btnCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TTempoControlForm.FormCreate(Sender: TObject);
begin
  {$IFDEF MULTI_LANGUAGE}
  TranslateComponent(self);
  {$ENDIF}
end;

procedure TTempoControlForm.FormShow(Sender: TObject);
begin
  tbTempo.Position := 250 - round(MainForm.MidiPlayer.Speed * 100.0);
  tbPitch.Position := 0 - MainForm.MidiPlayer.Pitch;
  edTempo.Text := intToStr(250 - tbTempo.Position) + '%';
  if tbPitch.Position < 0  then
    edPitch.Text := '+' + intToStr(0 - tbPitch.Position)
  else
    edPitch.Text := intToStr(0 - tbPitch.Position);
end;

procedure TTempoControlForm.tbPitchChange(Sender: TObject);
begin
  MainForm.MidiPlayer.Pitch := 0 - tbPitch.Position;
  if tbPitch.Position < 0  then
    edPitch.Text := '+' + intToStr(0 - tbPitch.Position)
  else
    edPitch.Text := intToStr(0 - tbPitch.Position);
end;

procedure TTempoControlForm.tbTempoChange(Sender: TObject);
begin
  MainForm.MidiPlayer.Speed := (250 - tbTempo.Position) / 100.0;
  edTempo.Text := intToStr(250 - tbTempo.Position) + '%';
end;

procedure TTempoControlForm.btnResetClick(Sender: TObject);
begin
  tbTempo.Position := 150;  // ** MainForm.MidiPlayer.Speed <= (250 - tbTempo.Position) / 100.0;
  tbPitch.Position := 0;
end;

end.