@@ -99,12 +99,43 @@ end; |
| 99 |
|
99 |
|
| 100 |
procedure ReadSongFromStreamV2(S: TStream; out ASong: TSongV2); |
100 |
procedure ReadSongFromStreamV2(S: TStream; out ASong: TSongV2); |
| 101 |
var |
101 |
var |
| 102 |
i: Integer; |
102 |
i, n: Integer; |
| 103 |
SongV1: TSongV1 absolute ASong; |
103 |
pat: PPattern; |
| 104 |
begin |
104 |
begin |
| 105 |
ReadSongFromStreamV1(S, SongV1); |
105 |
// Read the fixed elements first |
|
|
106 |
n := SizeOf(TSongV2) |
|
|
107 |
- SizeOf(TPatternMap) |
|
|
108 |
- SizeOf(TOrderMatrix) |
|
|
109 |
- SizeOf(TRoutineBank); |
|
|
110 |
|
|
|
111 |
S.Read(ASong, n); |
|
|
112 |
|
|
|
113 |
// ASong.Patterns.Clear; |
|
|
114 |
|
|
|
115 |
// Create the patterns |
|
|
116 |
ASong.Patterns := TPatternMap.Create; |
|
|
117 |
// Read the pattern count |
|
|
118 |
S.Read(n, SizeOf(Integer)); |
|
|
119 |
for i:=0 to n - 1 do begin |
|
|
120 |
// Allocate memory for each pattern ... |
|
|
121 |
New(pat); |
|
|
122 |
// and read the pattern content |
|
|
123 |
S.Read(pat^, SizeOf(TPattern)); |
|
|
124 |
// Add the pattern to the list |
|
|
125 |
ASong.Patterns.Add(i, pat); |
|
|
126 |
end; |
|
|
127 |
|
|
|
128 |
// Read the OrderMatrix |
|
|
129 |
for i := 0 to 3 do |
|
|
130 |
begin |
|
|
131 |
// Read length of each OrderMatrix array |
|
|
132 |
S.Read(n, SizeOf(Integer)); |
|
|
133 |
// Allocate memory for it |
|
|
134 |
SetLength(ASong.OrderMatrix[i], n); |
|
|
135 |
// Read content of OrderMatrix array |
|
|
136 |
S.Read(ASong.OrderMatrix[i, 0], n*SizeOf(Integer)); |
|
|
137 |
end; |
| 106 |
|
138 |
|
| 107 |
// Read routines |
|
|
| 108 |
for I := Low(TRoutineBank) to High(TRoutineBank) do |
139 |
for I := Low(TRoutineBank) to High(TRoutineBank) do |
| 109 |
ASong.Routines[I] := S.ReadAnsiString; |
140 |
ASong.Routines[I] := S.ReadAnsiString; |
| 110 |
end; |
141 |
end; |
@@ -115,7 +146,10 @@ var |
| 115 |
pPat: PPattern; |
146 |
pPat: PPattern; |
| 116 |
begin |
147 |
begin |
| 117 |
// Write the fixed record elements first |
148 |
// Write the fixed record elements first |
| 118 |
n := SizeOf(TSong) - SizeOf(TPatternMap) - SizeOf(TOrderMatrix); |
149 |
n := SizeOf(TSongV2) |
|
|
150 |
- SizeOf(TPatternMap) |
|
|
151 |
- SizeOf(TOrderMatrix) |
|
|
152 |
- SizeOf(TRoutineBank); |
| 119 |
S.Write(ASong, n); |
153 |
S.Write(ASong, n); |
| 120 |
|
154 |
|
| 121 |
// Write the pattern count |
155 |
// Write the pattern count |