-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfrmTransposePatternDlg.pas
199 lines (175 loc) · 5.83 KB
/
frmTransposePatternDlg.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
unit frmTransposePatternDlg;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TTransposePatternDlg = class(TForm)
cmdOK: TButton;
cmdCancel: TButton;
lblTransposeBy: TLabel;
cboTranspose: TComboBox;
Label1: TLabel;
txtPatternNum: TEdit;
udnPatternNum: TUpDown;
lblRangeErrorMsg: TLabel;
procedure cmdOKClick(Sender: TObject);
procedure txtPatternNumChange(Sender: TObject);
procedure cboTransposeChange(Sender: TObject);
procedure cboTransposeClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
function IsOffScale: boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
TransposePatternDlg: TTransposePatternDlg;
implementation
uses frmSTMainWnd;
{$R *.dfm}
procedure TTransposePatternDlg.cboTransposeChange(Sender: TObject);
begin
if IsOffScale then
lblRangeErrorMsg.Show
else
lblRangeErrorMsg.Hide;
end;
procedure TTransposePatternDlg.cboTransposeClick(Sender: TObject);
begin
if IsOffScale then
lblRangeErrorMsg.Show
else
lblRangeErrorMsg.Hide;
end;
procedure TTransposePatternDlg.cmdOKClick(Sender: TObject);
var
i, iTrans, iCh1, iCh2: integer;
begin
STMainWnd.UndoPattern := STMainWnd.Song.Pattern[udnPatternNum.Position];
STMainWnd.UndoSvgPattern := STMainWnd.Song.SvgPatternData[udnPatternNum.Position];
iTrans := cboTranspose.ItemIndex - 12;
for i := 1 to STMainWnd.Song.Pattern[udnPatternNum.Position].Length do
begin
iCh1 := STMainWnd.Song.Pattern[udnPatternNum.Position].Chan[1][i];
iCh2 := STMainWnd.Song.Pattern[udnPatternNum.Position].Chan[2][i];
// If channel 1 note is not a rest (255 or $82) then change it by the transposition amount
if (iCh1 <> 255) and
(iCh1 <> $82) then
begin
inc(iCh1,iTrans);
if (STMainWnd.Song.PreferredEngine = 'P1D') or
(STMainWnd.Song.PreferredEngine = 'P1S') or
(STMainWnd.Song.PreferredEngine = 'SVG') then
begin
if (iCh1 >= 107) and (iCh1 <= 119) then
dec(iCh1,107);
if (iCh1 < 0) and (iCh1 >= -6) then
inc(iCh1,107);
end;
end;
// If channel 2 note is not a rest (255 or $82) then change it by the transposition amount
if (iCh2 <> 255) and
(iCh2 <> $82) then
begin
inc(iCh2,iTrans);
if (STMainWnd.Song.PreferredEngine = 'P1D') or
(STMainWnd.Song.PreferredEngine = 'P1S') or
(STMainWnd.Song.PreferredEngine = 'SVG') then
begin
if (iCh2 >= 107) and (iCh2 <= 119) then
dec(iCh2,107);
if (iCh2 < 0) and (iCh2 >= -6) then
inc(iCh2,107);
end;
end;
// If channel 1 note is off-scale then make it a rest
if (iCh1 < 0) or ((iCh1 > 59) and (iCh1 < 101)) or
((iCh1 > 107) and (iCh1 < $80)) then
iCh1 := 255;
// If channel 2 note is off-scale then make it a rest
if (iCh2 < 0) or ((iCh2 > 59) and (iCh2 < 101)) or
((iCh2 > 107) and (iCh2 < $80)) then
iCh2 := 255;
// If current channel 1 note is not a rest or note-off (255 or $82) then transpose it
if (STMainWnd.Song.Pattern[udnPatternNum.Position].Chan[1][i] <> 255) and
(STMainWnd.Song.Pattern[udnPatternNum.Position].Chan[1][i] <> $82) then
STMainWnd.Song.Pattern[udnPatternNum.Position].Chan[1][i] := iCh1;
// If current channel 2 note is not a rest or note-off (255 or $82) then transpose it
if (STMainWnd.Song.Pattern[udnPatternNum.Position].Chan[2][i] <> 255) and
(STMainWnd.Song.Pattern[udnPatternNum.Position].Chan[2][i] <> $82) then
STMainWnd.Song.Pattern[udnPatternNum.Position].Chan[2][i] := iCh2;
end;
Self.ModalResult := mrOK;
end;
procedure TTransposePatternDlg.FormShow(Sender: TObject);
begin
cboTranspose.ItemIndex := 12;
lblRangeErrorMsg.Hide;
end;
function TTransposePatternDlg.IsOffScale(): boolean;
var
i, iCh1, iCh2, iTrans, iTopNote: integer;
begin
iTrans := cboTranspose.ItemIndex - 12;
Result := false;
if STMainWnd.Song.PreferredEngine = 'TMB' then
iTopNote := $34
else if STMainWnd.Song.PreferredEngine = 'SFX' then
iTopNote := $33
else if STMainWnd.Song.PreferredEngine = 'MSD' then
iTopNote := $24
else if STMainWnd.Song.PreferredEngine = 'P1D' then
iTopNote := $3B
else if STMainWnd.Song.PreferredEngine = 'P1S' then
iTopNote := $3B
else if STMainWnd.Song.PreferredEngine = 'SVG' then
iTopNote := $3B
else
iTopNote := $33;
for i := 1 to STMainWnd.Song.Pattern[udnPatternNum.Position].Length do
begin
iCh1 := STMainWnd.Song.Pattern[udnPatternNum.Position].Chan[1][i];
iCh2 := STMainWnd.Song.Pattern[udnPatternNum.Position].Chan[2][i];
if (STMainWnd.Song.PreferredEngine = 'P1D') or
(STMainWnd.Song.PreferredEngine = 'P1S') or
(STMainWnd.Song.PreferredEngine = 'SVG') then
begin
if (iCh1 <> 255) and (iCh1 <> $82) then
begin
inc(iCh1,6);
if (iCh1 > 106) and (iCh1 < 113) then dec(iCh1,107);
end;
if (iCh2 <> 255) and (iCh2 <> $82) then
begin
inc(iCh2,6);
if (iCh2 > 106) and (iCh2 < 113) then dec(iCh2,107);
end;
end;
if (iCh1 <> 255) and
(iCh1 <> $82) and
((iCh1 + iTrans > iTopNote) or
(iCh1 + iTrans < $0)) then
begin
Result := true;
break;
end;
if (iCh2 <> 255) and
(iCh2 <> $82) and
((iCh2 + iTrans > iTopNote) or
(iCh2 + iTrans < $0)) then
begin
Result := true;
break;
end;
end;
end;
procedure TTransposePatternDlg.txtPatternNumChange(Sender: TObject);
begin
if IsOffScale then
lblRangeErrorMsg.Show
else
lblRangeErrorMsg.Hide;
end;
end.