forked from Gota7/SequenceConvert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSSEQ.cs
131 lines (108 loc) · 3.83 KB
/
SSEQ.cs
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
using GotaSequenceLib;
using GotaSoundIO.IO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SequenceConvert {
/// <summary>
/// DS Sequence container.
/// </summary>
public class SSEQ : SequenceFile {
/// <summary>
/// Read the file.
/// </summary>
/// <param name="r">The reader.</param>
public override void Read(FileReader r) {
//Read the sequence.
FileHeader header;
r.OpenFile<NHeader>(out header);
//Data block.
uint dataSize;
r.OpenBlock(0, out _, out _);
uint off = r.ReadUInt32();
dataSize = (uint)(header.FileSize - off);
r.Jump(off, true);
var data = r.ReadBytes((int)dataSize).ToList();
//Remove padding.
for (int i = data.Count - 1; i >= 0; i--) {
if (data[i] == 0) {
data.RemoveAt(i);
} else {
break;
}
}
//Set raw data.
RawData = data.ToArray();
}
/// <summary>
/// Write the file.
/// </summary>
/// <param name="w">The writer.</param>
public override void Write(FileWriter w) {
//Simple.
w.InitFile<NHeader>("SSEQ", ByteOrder.LittleEndian, null, 1);
w.InitBlock("DATA");
w.Write((uint)0x1C);
w.Write(RawData);
w.Pad(4);
w.CloseBlock();
w.CloseFile();
}
/// <summary>
/// Convert the file to text.
/// </summary>
/// <returns>The file as text.</returns>
public new string[] ToText() {
//Command list.
ReadCommandData(true);
List<string> l = new List<string>();
//Add header.
l.Add(";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;");
l.Add(";");
l.Add("; " + Name + ".smft");
l.Add("; Generated By Gota's Sequence Tools");
l.Add(";");
l.Add(";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;");
l.Add("");
//For each command. Last one isn't counted.
for (int i = 0; i < Commands.Count - 1; i++) {
//Add labels.
bool labelAdded = false;
var labels = PublicLabels.Where(x => x.Value == i).Select(x => x.Key);
bool label0Added = false;
foreach (var label in labels) {
if (i != 0 && !labelAdded && Commands[i - 1].CommandType == SequenceCommands.Fin) {
l.Add(" ");
}
if (i == 0) {
label0Added = true;
}
l.Add(label + ":");
labelAdded = true;
}
if (OtherLabels.Contains(i)) {
if (i != 0 && !labelAdded && Commands[i - 1].CommandType == SequenceCommands.Fin) {
l.Add(" ");
}
if (i != 0) { l.Add("_command_" + i + ":"); }
//else if (Commands[i - 1].CommandType == SequenceCommands.Fin) { l.Add("Command_" + i + ":"); }
labelAdded = true;
}
if (i == 0 && !label0Added) {
l.Add("Sequence_Start:");
}
//Add command.
l.Add("\t" + Commands[i].ToString());
}
//Return the list.
return l.ToArray();
}
/// <summary>
/// Sequence platform.
/// </summary>
/// <returns>The sequence platform.</returns>
public override SequencePlatform Platform() => new Nitro();
}
}