@@ -80,9 +80,11 @@ type |
| 80 |
Routines: TRoutineBank; |
80 |
Routines: TRoutineBank; |
| 81 |
end; |
81 |
end; |
| 82 |
|
82 |
|
|
|
83 |
TSongV5 = TSongV4; // no structural differences |
|
|
84 |
|
| 83 |
{ TSong } |
85 |
{ TSong } |
| 84 |
|
86 |
|
| 85 |
TSong = TSongV4; |
87 |
TSong = TSongV5; |
| 86 |
|
88 |
|
| 87 |
procedure WriteSongToStream(S: TStream; const ASong: TSong); |
89 |
procedure WriteSongToStream(S: TStream; const ASong: TSong); |
| 88 |
procedure ReadSongFromStream(S: TStream; out ASong: TSong); |
90 |
procedure ReadSongFromStream(S: TStream; out ASong: TSong); |
@@ -260,13 +262,55 @@ begin |
| 260 |
ASong.Routines[I] := S.ReadAnsiString; |
262 |
ASong.Routines[I] := S.ReadAnsiString; |
| 261 |
end; |
263 |
end; |
| 262 |
|
264 |
|
|
|
265 |
procedure ReadSongFromStreamV5(S: TStream; out ASong: TSongV5); |
|
|
266 |
var |
|
|
267 |
i, n, PatKey: Integer; |
|
|
268 |
pat: PPattern; |
|
|
269 |
begin |
|
|
270 |
// Read the fixed elements first |
|
|
271 |
n := SizeOf(TSongV5) |
|
|
272 |
- SizeOf(TPatternMap) |
|
|
273 |
- SizeOf(TOrderMatrix) |
|
|
274 |
- SizeOf(TRoutineBank); |
|
|
275 |
|
|
|
276 |
S.Read(ASong, n); |
|
|
277 |
|
|
|
278 |
// Create the patterns |
|
|
279 |
ASong.Patterns := TPatternMap.Create; |
|
|
280 |
// Read the pattern count |
|
|
281 |
S.Read(n, SizeOf(Integer)); |
|
|
282 |
for i:=0 to n - 1 do begin |
|
|
283 |
// Read pattern key |
|
|
284 |
S.Read(PatKey, SizeOf(Integer)); |
|
|
285 |
// Allocate memory for each pattern ... |
|
|
286 |
New(pat); |
|
|
287 |
// and read the pattern content |
|
|
288 |
S.Read(pat^, SizeOf(TPattern)); |
|
|
289 |
// Add the pattern to the list |
|
|
290 |
ASong.Patterns.Add(PatKey, pat); |
|
|
291 |
end; |
|
|
292 |
|
|
|
293 |
// Read the OrderMatrix |
|
|
294 |
for i := 0 to 3 do |
|
|
295 |
begin |
|
|
296 |
// Read length of each OrderMatrix array |
|
|
297 |
S.Read(n, SizeOf(Integer)); |
|
|
298 |
// Allocate memory for it |
|
|
299 |
SetLength(ASong.OrderMatrix[i], n); |
|
|
300 |
// Read content of OrderMatrix array |
|
|
301 |
S.Read(ASong.OrderMatrix[i, 0], n*SizeOf(Integer)); |
|
|
302 |
end; |
|
|
303 |
|
|
|
304 |
for I := Low(TRoutineBank) to High(TRoutineBank) do |
|
|
305 |
ASong.Routines[I] := S.ReadAnsiString; |
|
|
306 |
end; |
|
|
307 |
|
| 263 |
procedure WriteSongToStream(S: TStream; const ASong: TSong); |
308 |
procedure WriteSongToStream(S: TStream; const ASong: TSong); |
| 264 |
var |
309 |
var |
| 265 |
i, n: Integer; |
310 |
i, n: Integer; |
| 266 |
pPat: PPattern; |
|
|
| 267 |
begin |
311 |
begin |
| 268 |
// Write the fixed record elements first |
312 |
// Write the fixed record elements first |
| 269 |
n := SizeOf(TSongV4) |
313 |
n := SizeOf(TSongV5) |
| 270 |
- SizeOf(TPatternMap) |
314 |
- SizeOf(TPatternMap) |
| 271 |
- SizeOf(TOrderMatrix) |
315 |
- SizeOf(TOrderMatrix) |
| 272 |
- SizeOf(TRoutineBank); |
316 |
- SizeOf(TRoutineBank); |
@@ -277,8 +321,8 @@ begin |
| 277 |
// Write the patterns |
321 |
// Write the patterns |
| 278 |
for i := 0 to ASong.Patterns.Count-1 do |
322 |
for i := 0 to ASong.Patterns.Count-1 do |
| 279 |
begin |
323 |
begin |
| 280 |
pPat := ASong.Patterns[i]; |
324 |
S.Write(ASong.Patterns.Keys[i], SizeOf(Integer)); |
| 281 |
S.Write(pPat^, SizeOf(pPat^)); |
325 |
S.Write(ASong.Patterns.Data[i]^, SizeOf(TPattern)); |
| 282 |
end; |
326 |
end; |
| 283 |
|
327 |
|
| 284 |
// Write the OrderMatrix arrays |
328 |
// Write the OrderMatrix arrays |
@@ -300,6 +344,7 @@ var |
| 300 |
SV1: TSongV1; |
344 |
SV1: TSongV1; |
| 301 |
SV2: TSongV2; |
345 |
SV2: TSongV2; |
| 302 |
SV3: TSongV3; |
346 |
SV3: TSongV3; |
|
|
347 |
SV4: TSongV4; |
| 303 |
begin |
348 |
begin |
| 304 |
S.Read(Version, SizeOf(Integer)); |
349 |
S.Read(Version, SizeOf(Integer)); |
| 305 |
S.Seek(0, soBeginning); |
350 |
S.Seek(0, soBeginning); |
@@ -316,7 +361,13 @@ begin |
| 316 |
ReadSongFromStreamV3(S, SV3); |
361 |
ReadSongFromStreamV3(S, SV3); |
| 317 |
ASong := UpgradeSong(SV3); |
362 |
ASong := UpgradeSong(SV3); |
| 318 |
end; |
363 |
end; |
| 319 |
4: ReadSongFromStreamV4(S, ASong); |
364 |
4: begin |
|
|
365 |
ReadSongFromStreamV4(S, SV4); |
|
|
366 |
ASong := UpgradeSong(SV4); |
|
|
367 |
end; |
|
|
368 |
5: begin |
|
|
369 |
ReadSongFromStreamV5(S, ASong); |
|
|
370 |
end; |
| 320 |
end; |
371 |
end; |
| 321 |
end; |
372 |
end; |
| 322 |
|
373 |
|
@@ -602,6 +653,7 @@ end; |
| 602 |
|
653 |
|
| 603 |
function UpgradeSong(S: TSongV4): TSong; |
654 |
function UpgradeSong(S: TSongV4): TSong; |
| 604 |
begin |
655 |
begin |
|
|
656 |
S.Version := 5; |
| 605 |
Result := S; |
657 |
Result := S; |
| 606 |
end; |
658 |
end; |
| 607 |
|
659 |
|