@@ -7,9 +7,11 @@ unit Song; |
| 7 |
|
7 |
|
| 8 |
interface |
8 |
interface |
| 9 |
|
9 |
|
| 10 |
uses Classes, HugeDatatypes, instruments, Constants, waves, math; |
10 |
uses Classes, HugeDatatypes, instruments, Constants, waves, math, sysutils; |
| 11 |
|
11 |
|
| 12 |
type |
12 |
type |
|
|
13 |
ESongVersionException = class(Exception); |
|
|
14 |
|
| 13 |
TSongV1 = packed record |
15 |
TSongV1 = packed record |
| 14 |
Version: Integer; |
16 |
Version: Integer; |
| 15 |
|
17 |
|
@@ -102,7 +104,7 @@ type |
| 102 |
|
104 |
|
| 103 |
{ TSong } |
105 |
{ TSong } |
| 104 |
|
106 |
|
| 105 |
TSong = TSongV5; |
107 |
TSong = TSongV6; |
| 106 |
|
108 |
|
| 107 |
procedure WriteSongToStream(S: TStream; const ASong: TSong); |
109 |
procedure WriteSongToStream(S: TStream; const ASong: TSong); |
| 108 |
procedure ReadSongFromStream(S: TStream; out ASong: TSong); |
110 |
procedure ReadSongFromStream(S: TStream; out ASong: TSong); |
@@ -114,7 +116,7 @@ function UpgradeSong(S: TSongV1): TSong; overload; |
| 114 |
function UpgradeSong(S: TSongV2): TSong; overload; |
116 |
function UpgradeSong(S: TSongV2): TSong; overload; |
| 115 |
function UpgradeSong(S: TSongV3): TSong; overload; |
117 |
function UpgradeSong(S: TSongV3): TSong; overload; |
| 116 |
function UpgradeSong(S: TSongV4): TSong; overload; |
118 |
function UpgradeSong(S: TSongV4): TSong; overload; |
| 117 |
function UpgradeSong(S: TSongV5): TSong; overload; |
119 |
//function UpgradeSong(S: TSongV5): TSong; overload; |
| 118 |
|
120 |
|
| 119 |
function OptimizeSong(const S: TSong): TSong; |
121 |
function OptimizeSong(const S: TSong): TSong; |
| 120 |
function PatternIsUsed(Idx: Integer; const Song: TSong): Boolean; |
122 |
function PatternIsUsed(Idx: Integer; const Song: TSong): Boolean; |
@@ -435,6 +437,9 @@ begin |
| 435 |
6: begin |
437 |
6: begin |
| 436 |
ReadSongFromStreamV6(S, ASong); |
438 |
ReadSongFromStreamV6(S, ASong); |
| 437 |
end; |
439 |
end; |
|
|
440 |
else begin |
|
|
441 |
raise ESongVersionException.Create(IntToStr(Version)); |
|
|
442 |
end; |
| 438 |
end; |
443 |
end; |
| 439 |
end; |
444 |
end; |
| 440 |
|
445 |
|
@@ -673,7 +678,7 @@ var |
| 673 |
Result := False; |
678 |
Result := False; |
| 674 |
end; |
679 |
end; |
| 675 |
|
680 |
|
| 676 |
procedure ConvertPattern(var Pat: TPattern); |
681 |
procedure ConvertPattern(var Pat: TPatternV1); |
| 677 |
var |
682 |
var |
| 678 |
I: Integer; |
683 |
I: Integer; |
| 679 |
Regs: TRegisters; |
684 |
Regs: TRegisters; |
@@ -722,9 +727,44 @@ begin |
| 722 |
end; |
727 |
end; |
| 723 |
|
728 |
|
| 724 |
function UpgradeSong(S: TSongV4): TSong; |
729 |
function UpgradeSong(S: TSongV4): TSong; |
|
|
730 |
var |
|
|
731 |
SV6: TSongV6; |
|
|
732 |
I: Integer; |
|
|
733 |
|
|
|
734 |
function ConvertPattern(Pat: PPatternV1): PPattern; |
|
|
735 |
var |
|
|
736 |
J: Integer; |
|
|
737 |
begin |
|
|
738 |
New(Result); |
|
|
739 |
for J := Low(TPatternV1) to High(TPatternV1) do begin |
|
|
740 |
Result^[J].Instrument := Pat^[J].Instrument; |
|
|
741 |
Result^[J].EffectCode := Pat^[J].EffectCode; |
|
|
742 |
Result^[J].EffectParams.Value := Pat^[J].EffectParams.Value; |
|
|
743 |
Result^[J].Note := Pat^[J].Note; |
|
|
744 |
Result^[J].Volume := 0; |
|
|
745 |
end; |
|
|
746 |
end; |
| 725 |
begin |
747 |
begin |
| 726 |
S.Version := 5; |
748 |
SV6.Version:=6; |
| 727 |
Result := S; |
749 |
|
|
|
750 |
SV6.Name:=S.Name; |
|
|
751 |
SV6.Artist:=S.Artist; |
|
|
752 |
SV6.Comment:=S.Comment; |
|
|
753 |
|
|
|
754 |
SV6.Instruments:=S.Instruments; |
|
|
755 |
SV6.Waves := S.Waves; |
|
|
756 |
|
|
|
757 |
SV6.TicksPerRow:=S.TicksPerRow; |
|
|
758 |
SV6.OrderMatrix:=S.OrderMatrix; |
|
|
759 |
|
|
|
760 |
SV6.Routines:=S.Routines; |
|
|
761 |
|
|
|
762 |
SV6.Patterns := TPatternMap.Create; |
|
|
763 |
// Update patterns to new format |
|
|
764 |
for I := 0 to S.Patterns.Count-1 do |
|
|
765 |
SV6.Patterns.Add(S.Patterns.Keys[I], ConvertPattern(S.Patterns.Data[I])); |
|
|
766 |
|
|
|
767 |
Result := SV6; |
| 728 |
end; |
768 |
end; |
| 729 |
|
769 |
|
| 730 |
function OptimizeSong(const S: TSong): TSong; |
770 |
function OptimizeSong(const S: TSong): TSong; |