Skip to content

Commit 0623f3f

Browse files
committed
Fix detection of highest waveform
1 parent c4fa072 commit 0623f3f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/codegen.pas

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function FindUsedStuff(const Song: TSong): TUsedStuff;
4747
I, J: Integer;
4848
Pat: PPattern;
4949
Cell: TCell;
50+
Instr: TInstrument;
5051
InstValue: Integer;
5152
Highest: ^Integer;
5253
Waveform: Integer;
@@ -57,6 +58,17 @@ function FindUsedStuff(const Song: TSong): TUsedStuff;
5758
Result.HighestNoiseInst := -1;
5859
Result.HighestWaveform := -1;
5960

61+
for Instr in Song.Instruments.Wave do begin
62+
if not Instr.SubpatternEnabled then Continue;
63+
64+
for Cell in Instr.Subpattern do
65+
if Cell.EffectCode = $9 then begin
66+
Waveform := Cell.EffectParams.Value;
67+
if Waveform > Result.HighestWaveform then
68+
Result.HighestWaveform := Waveform;
69+
end;
70+
end;
71+
6072
for I := Low(Song.OrderMatrix) to High(Song.OrderMatrix) do begin
6173
case I of
6274
0, 1: Highest := @Result.HighestDutyInst;
@@ -71,6 +83,12 @@ function FindUsedStuff(const Song: TSong): TUsedStuff;
7183

7284
Pat := Song.Patterns.KeyData[Song.OrderMatrix[I, J]];
7385
for Cell in Pat^ do begin
86+
if (Cell.EffectCode = $9) and (I = 2) then begin // waveforms on wave channel
87+
Waveform := Cell.EffectParams.Value;
88+
if Waveform > Result.HighestWaveform then
89+
Result.HighestWaveform := Waveform;
90+
end;
91+
7492
if Cell.Instrument = 0 then Continue;
7593

7694
if InRange(Cell.Instrument, 0, 15) then

0 commit comments

Comments
 (0)