-
Notifications
You must be signed in to change notification settings - Fork 1
/
frmAdjustSongTempoDlg.pas
95 lines (76 loc) · 2.06 KB
/
frmAdjustSongTempoDlg.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
unit frmAdjustSongTempoDlg;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TAdjustSongTempoDlg = class(TForm)
cmdOK: TButton;
cmdCancel: TButton;
Label1: TLabel;
lblRangeErrorMsg: TLabel;
cboAdjust: TComboBox;
procedure FormShow(Sender: TObject);
procedure cboAdjustClick(Sender: TObject);
procedure cmdOKClick(Sender: TObject);
private
function IsOffScale: boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
AdjustSongTempoDlg: TAdjustSongTempoDlg;
implementation
{$R *.dfm}
uses frmSTMainWnd;
function TAdjustSongTempoDlg.IsOffScale(): boolean;
var
iLowest, iHighest, iPat: integer;
iAdjust: integer;
begin
Result := false;
iLowest := 21; iHighest := 0;
for iPat := 0 to 255 do
begin
if STMainWnd.Song.IsPatternUsed(iPat) then
begin
if STMainWnd.Song.Pattern[iPat].Tempo < iLowest then
iLowest := STMainWnd.Song.Pattern[iPat].Tempo;
if STMainWnd.Song.Pattern[iPat].Tempo > iHighest then
iHighest := STMainWnd.Song.Pattern[iPat].Tempo;
end;
end;
iAdjust := cboAdjust.ItemIndex - 10;
if (iLowest + iAdjust) < 1 then Result := true;
if (iHighest + iAdjust) > 20 then Result := true;
end;
procedure TAdjustSongTempoDlg.cboAdjustClick(Sender: TObject);
begin
if IsOffScale() then
lblRangeErrorMsg.Show
else
lblRangeErrorMsg.Hide;
end;
procedure TAdjustSongTempoDlg.cmdOKClick(Sender: TObject);
var
iPat, i: integer;
begin
for iPat := 0 to 255 do
begin
if STMainWnd.Song.IsPatternUsed(iPat) then
begin
i := STMainWnd.Song.Pattern[iPat].Tempo + (cboAdjust.ItemIndex - 10);
if i < 1 then i := 1;
if i > 20 then i := 20;
STMainWnd.Song.Pattern[iPat].Tempo := i;
end;
end;
Self.ModalResult := mrOK;
end;
procedure TAdjustSongTempoDlg.FormShow(Sender: TObject);
begin
cboAdjust.ItemIndex := 10;
lblRangeErrorMsg.Hide;
end;
end.