-
Notifications
You must be signed in to change notification settings - Fork 1
/
clSequence.vb
217 lines (183 loc) · 5.91 KB
/
clSequence.vb
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
Imports System.IO
<Serializable()> Public Class clSequence
Const MAX_SEQ As Integer = 256
Public n As Short
Public temp As Short
Structure _SEQENTRY
Public note As Short
Public shape As Byte
Public xtra As Byte
End Structure
Structure _SEQ
Public seq() As _SEQENTRY
End Structure
Public seqs(MAX_SEQ - 1 + 1) As _SEQ
Public count As Integer
Sub New()
Dim i, j As Integer
Dim se As _SEQENTRY
n = MAX_SEQ - 1
se.note = -1
se.shape = 0
se.xtra = 0
For i = 0 To MAX_SEQ - 1 + 1
ReDim seqs(i).seq(255) ' seqs.A
For j = 0 To 255
seqs(i).seq(j) = se
Next
Next
' temporäre Dummy-Sequence
temp = MAX_SEQ - 1 + 1
For i = 0 To 30
seqs(temp).seq(i).note = 0
seqs(temp).seq(i).shape = 0
seqs(temp).seq(i).xtra = 0
Next
i += 1
seqs(temp).seq(i).note = 1 * 12
seqs(temp).seq(i).shape = 0
seqs(temp).seq(i).xtra = 0
i += 1
seqs(temp).seq(i).note = &HFF ' End
seqs(temp).seq(i).shape = 0
seqs(temp).seq(i).xtra = 0
count = 0
End Sub
Public Sub clear()
Dim i, j As Integer
Dim se As _SEQENTRY
se.note = -1
se.shape = 0
se.xtra = 0
For i = 0 To MAX_SEQ - 1 + 1
For j = 0 To 255
seqs(i).seq(j) = se
Next
Next
End Sub
Public Sub save(ByVal fs As FileStream)
Dim i, j As Integer
For i = 0 To MAX_SEQ - 1
For j = 0 To 255
fs.WriteByte((seqs(i).seq(j).note >> 8) And &HFF)
fs.WriteByte(seqs(i).seq(j).note And &HFF)
fs.WriteByte(seqs(i).seq(j).shape)
fs.WriteByte(seqs(i).seq(j).xtra)
Next
Next
End Sub
Function depack(ByVal n As Integer, ByRef packed() As Byte) As Integer
Dim i As Integer = 0
Dim pi As Integer = 0
Dim b As Byte
Dim counter As Short = 0
Dim counterInit As Short = 0
Dim se As _SEQENTRY
For Each se In seqs(n).seq
se.note = -1
se.shape = 0
se.xtra = 0
Next
Do While pi < 64 ' max 64 Bytes
counter -= 1
If counter < 0 Then
counter = counterInit
Do
b = packed(pi)
pi += 1
Select Case b
Case &HFF
seqs(n).seq(i).note = &HFF
Debug.WriteLine(n.ToString & ": " & i.ToString)
Return (i)
Case &HFE 'nach &Hfe, &Hxx folgt sofort Note
counter = packed(pi)
pi += 1
counterInit = counter
Case &HFD 'Pause
counter = packed(pi)
pi += 1
counterInit = counter
Exit Do
Case Else
seqs(n).seq(i).note = b
b = packed(pi)
pi += 1
seqs(n).seq(i).shape = b
If (b And &HE0) > 0 Then
seqs(n).seq(i).xtra = packed(pi)
pi += 1
End If
Exit Do
End Select
Loop
End If
i += 1
Loop
seqs(n).seq(i).note = &HFF ' end
End Function
'for unpacked sequences (TFMX)
Function coyp(ByVal n As Integer, ByRef packed() As Byte) As Integer
Dim i As Integer
Dim pi As Integer = 0
For i = 0 To 31
seqs(n).seq(i).note = packed(pi) - 1
pi += 1
seqs(n).seq(i).shape = packed(pi)
pi += 1
Next
seqs(n).seq(i).note = &HFF ' end
End Function
' sequence compress, needed by TFMX-import because TFMX-sequences are straight datas
'Sub compress(ByVal n As Short)
' Dim i, j, k, l As Short
' Dim note, shape As Byte
' Dim cseq(63) As Byte
' For i = 0 To n
' k = 0
' note = Seq(i, 0)
' shape = Seq(i, 1)
' j = 2
' If (note = 0) And (shape = 0) Then
' Do While (Seq(i, j) = 0) And (Seq(i, j + 1) = 0) And (j < 32)
' j += 2
' Loop
' If j = 32 Then
' cseq(k) = &HFD
' cseq(k + 1) = 31
' cseq(k + 2) = &HFF
' k += 3
' Else
' cseq(k) = &HFD
' cseq(k + 1) = j \ 2
' k += 2
' note = Seq(i, j)
' shape = Seq(i, j + 1)
' j += 2
' End If
' End If
' Do While j < 32
' l = 0
' Do While (Seq(i, j) = 0) And (Seq(i, j + 1) = 0) And (j < 32)
' j += 2
' l += 1
' Loop
' If l > 0 Then
' cseq(k) = &HFE
' cseq(k + 1) = l
' k += 2
' End If
' cseq(k) = note
' cseq(k + 1) = shape
' k += 2
' note = Seq(i, j)
' shape = Seq(i, j + 1)
' j += 2
' Loop
' cseq(k) = &HFF
' For j = 0 To k
' Seq(i, j) = cseq(j)
' Next
' Next
'End Sub
End Class