-
Notifications
You must be signed in to change notification settings - Fork 1
/
Preset.vb
385 lines (348 loc) · 16.3 KB
/
Preset.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
Public Class PresetSeq
Public SequenceName As String, BaseSpeed As Integer, SoundSpeed As Integer, BassSpeed As Integer, Mode As String
Public Function Serialize(pMult As Boolean) As XElement
Dim res As New XElement("Sequencer" + If(pMult, "Mult", ""),
New XElement("ActiveSequence", SequenceName),
New XElement("BaseSpeed", BaseSpeed),
New XElement("SoundSpeed", SoundSpeed),
New XElement("BassSpeed", BassSpeed),
New XElement("Mode", Mode)
)
Return res
End Function
Public Sub fromXML(xml As XElement, pMult As Boolean)
Dim x = If(pMult, xml.<SequencerMult>, xml.<Sequencer>)
SequenceName = x.<ActiveSequence>.Value
BaseSpeed = x.<BaseSpeed>.Value
SoundSpeed = x.<SoundSpeed>.Value
BassSpeed = x.<BassSpeed>.Value
Mode = x.<Mode>.Value
End Sub
End Class
Public Class PresetSound
Public Compressor As Integer, Delay As Integer, Noisegate As Integer, Soften As Integer, CompressorB As Integer, DelayB As Integer, NoisegateB As Integer
Public Function Serialize() As XElement
Dim res As New XElement("Sound",
New XElement("Compressor", Compressor),
New XElement("Delay", Delay),
New XElement("Noisegate", Noisegate),
New XElement("Soften", Soften),
New XElement("CompressorB", CompressorB),
New XElement("DelayB", DelayB),
New XElement("NoisegateB", NoisegateB)
)
Return res
End Function
Public Sub fromXML(xml As XElement)
With xml
Compressor = .<Sound>.<Compressor>.Value
Delay = .<Sound>.<Delay>.Value
Noisegate = .<Sound>.<Noisegate>.Value
Soften = .<Sound>.<Soften>.Value
CompressorB = .<Sound>.<CompressorB>.Value
DelayB = .<Sound>.<DelayB>.Value
NoisegateB = .<Sound>.<NoisegateB>.Value
End With
End Sub
End Class
Public Class Preset
Public Name As String
Public AffectedFixtures As New Dictionary(Of FixtureTemplate, FixtureValues)
Public Seq As New PresetSeq
Public SeqMult As New PresetSeq
Public Sound As New PresetSound
Public Sub New(xPreset As XElement)
Name = xPreset.<Name>.Value
Seq.fromXML(xPreset, False)
SeqMult.fromXML(xPreset, True)
Sound.fromXML(xPreset)
For Each xFixt As XElement In xPreset.<AffectedFixture>
Dim fixtureName As String = xFixt.<Name>.Value
Dim fix As FixtureTemplate = _MainForm.Fixtures.First(Function(fff) fff.Name.ToUpper = fixtureName.ToUpper)
If fix Is Nothing Then
MsgBox(String.Format("<Preset> «{0}» refers <Fixture> «{1}» that does not exist on this file", Name, fixtureName), MsgBoxStyle.Critical)
Continue For
End If
AffectedFixtures.Add(fix, New FixtureValues(xFixt))
Next
End Sub
Public Function ChannelShow(pFixtures As List(Of FixtureTemplate), pChannelType As ChannelType) As ChannelData.Modes
Dim res As ChannelData.Modes = ChannelData.Modes.Hide
For Each f As FixtureTemplate In Me.AffectedFixtures.Keys
If Not pFixtures.Contains(f) Then Continue For
If Not Me.AffectedFixtures.ContainsKey(f) Then Continue For
If Me.AffectedFixtures(f).ChannelMode(pChannelType) = ChannelData.Modes.Hide Then Continue For
If Me.AffectedFixtures(f).ChannelMode(pChannelType) = ChannelData.Modes.Show Then Return Me.AffectedFixtures(f).ChannelMode(pChannelType)
Next
Return res
End Function
Public Property UserValue(pFixtures As List(Of FixtureTemplate), pChannelType As ChannelType) As Integer
Get
Dim res As Integer = Channel.ValueUnkown
For Each f As FixtureTemplate In Me.AffectedFixtures.Keys
If Not pFixtures.Contains(f) Then Continue For
If Not f.Channels.ContainsKey(pChannelType) Then Continue For
Return Me.AffectedFixtures(f).UserValue(pChannelType)
Next
Return res
End Get
Set(value As Integer)
For Each f As KeyValuePair(Of FixtureTemplate, FixtureValues) In Me.AffectedFixtures
If Not pFixtures.Contains(f.Key) Then Continue For
f.Value.UserValue(pChannelType) = value
Next
End Set
End Property
Public Property SoundControllerPercent(pFixtures As List(Of FixtureTemplate), pChannelType As ChannelType) As Integer
Get
Dim res As Integer = Channel.ValueUnkown
For Each f As FixtureTemplate In Me.AffectedFixtures.Keys
If Not pFixtures.Contains(f) Then Continue For
If Not f.Channels.ContainsKey(pChannelType) Then Continue For
Return Me.AffectedFixtures(f).SoundControllerPercent(pChannelType)
Next
Return res
End Get
Set(value As Integer)
For Each f As KeyValuePair(Of FixtureTemplate, FixtureValues) In Me.AffectedFixtures
If Not pFixtures.Contains(f.Key) Then Continue For
f.Value.SoundControllerPercent(pChannelType) = value
Next
End Set
End Property
Public Property SoundControllerBassPercent(pFixtures As List(Of FixtureTemplate), pChannelType As ChannelType) As Integer
Get
Dim res As Integer = Channel.ValueUnkown
For Each f As FixtureTemplate In Me.AffectedFixtures.Keys
If Not pFixtures.Contains(f) Then Continue For
If Not f.Channels.ContainsKey(pChannelType) Then Continue For
Return Me.AffectedFixtures(f).SoundControllerBassPercent(pChannelType)
Next
Return res
End Get
Set(value As Integer)
For Each f As KeyValuePair(Of FixtureTemplate, FixtureValues) In Me.AffectedFixtures
If Not pFixtures.Contains(f.Key) Then Continue For
f.Value.SoundControllerBassPercent(pChannelType) = value
Next
End Set
End Property
Public Property SeqControllerPercent(pFixtures As List(Of FixtureTemplate), pChannelType As ChannelType) As Integer
Get
Dim res As Integer = Channel.ValueUnkown
For Each f As FixtureTemplate In Me.AffectedFixtures.Keys
If Not pFixtures.Contains(f) Then Continue For
If Not f.Channels.ContainsKey(pChannelType) Then Continue For
Return Me.AffectedFixtures(f).SeqControllerPercent(pChannelType)
Next
Return res
End Get
Set(value As Integer)
For Each f As KeyValuePair(Of FixtureTemplate, FixtureValues) In Me.AffectedFixtures
If Not pFixtures.Contains(f.Key) Then Continue For
f.Value.SeqControllerPercent(pChannelType) = value
Next
End Set
End Property
Public Property SeqControllerPercentMult(pFixtures As List(Of FixtureTemplate), pChannelType As ChannelType) As Integer
Get
Dim res As Integer = Channel.ValueUnkown
For Each f As FixtureTemplate In Me.AffectedFixtures.Keys
If Not pFixtures.Contains(f) Then Continue For
If Not f.Channels.ContainsKey(pChannelType) Then Continue For
Return Me.AffectedFixtures(f).SeqControllerPercentMult(pChannelType)
Next
Return res
End Get
Set(value As Integer)
For Each f As KeyValuePair(Of FixtureTemplate, FixtureValues) In Me.AffectedFixtures
If Not pFixtures.Contains(f.Key) Then Continue For
f.Value.SeqControllerPercentMult(pChannelType) = value
Next
End Set
End Property
Public ReadOnly Property TotalValue(pFixtures As List(Of FixtureTemplate), pChannelType As ChannelType) As Integer
Get
Dim res As Integer = 0
For Each f As FixtureTemplate In Me.AffectedFixtures.Keys
If Not pFixtures.Contains(f) Then Continue For
If Not f.Channels.ContainsKey(pChannelType) Then Continue For
Return Me.AffectedFixtures(f).TotalValue(pChannelType)
Next
Return res
End Get
End Property
Friend Function Serialize() As XElement
Dim res As New XElement("Preset",
New XElement("Name", Name)
)
res.Add(Seq.Serialize(False))
res.Add(SeqMult.Serialize(True))
res.Add(Sound.Serialize())
For Each f As KeyValuePair(Of FixtureTemplate, FixtureValues) In Me.AffectedFixtures
Dim resf As New XElement("AffectedFixture",
New XElement("Name", f.Key.Name),
New XElement("SeqControllerIdx", f.Value.SeqControllerIdx)
)
For Each p As ChannelData In f.Value.Channels.Values
Dim resp As New XElement("PresetChannel",
New XElement("Type", p.ChannelType.Type),
New XElement("Mode", p.Mode.ToString),
New XElement("SoundControllerPercent", p.SoundControllerPercent),
New XElement("SoundControllerPercentBass", p.SoundControllerBassPercent),
New XElement("SeqControllerPercent", p.SeqControllerPercent),
New XElement("SeqControllerPercentMult", p.SeqControllerPercentMult),
New XElement("Value", p.UserValue)
)
resf.Add(resp)
Next p
res.Add(resf)
Next f
Return res
End Function
End Class
''' <summary>
''' this is kinda propertybag where I keep a fixture's values for a certain Preset, allowing me to temporarly change into a different preset and then come back to the original preset with its values
''' </summary>
Public Class FixtureValues
Public Channels As New Dictionary(Of ChannelType, ChannelData)
Public SeqControllerIdx As Integer
Friend Sub New(ByVal fld As XElement)
SeqControllerIdx = fld.<SeqControllerIdx>.Value
For Each xPc As XElement In fld.<PresetChannel>
Channels.Add(ChannelTypes.ByName(xPc.<Type>.Value),
New ChannelData(
ChannelTypes.ByName(xPc.<Type>.Value),
EnumByString(xPc.<Mode>.Value, GetType(ChannelData.Modes)),
CInt(xPc.<Value>.Value),
CInt(xPc.<SoundControllerPercent>.Value),
CInt(xPc.<SoundControllerPercentBass>.Value),
CInt(xPc.<SeqControllerPercent>.Value),
CInt(xPc.<SeqControllerPercentMult>.Value)
)
)
Next
End Sub
Public ReadOnly Property ChannelMode(pChannelType As ChannelType) As ChannelData.Modes
Get
If Not Channels.ContainsKey(pChannelType) Then Return ChannelData.Modes.Ignore
Return Channels(pChannelType).Mode
End Get
End Property
Public Property UserValue(pChannelType As ChannelType) As Integer
Get
If Not Channels.ContainsKey(pChannelType) Then Return Channel.ValueUnkown
Return Channels(pChannelType).UserValue
End Get
Set(value As Integer)
If Not Channels.ContainsKey(pChannelType) Then Return
Channels(pChannelType).UserValue = value
End Set
End Property
Public Property SoundControllerPercent(pChannelType As ChannelType) As Integer
Get
If Not Channels.ContainsKey(pChannelType) Then Return 0
Return Channels(pChannelType).SoundControllerPercent
End Get
Set(value As Integer)
If Not Channels.ContainsKey(pChannelType) Then Return
Channels(pChannelType).SoundControllerPercent = value
End Set
End Property
Public Property SoundControllerBassPercent(pChannelType As ChannelType) As Integer
Get
If Not Channels.ContainsKey(pChannelType) Then Return 0
Return Channels(pChannelType).SoundControllerBassPercent
End Get
Set(value As Integer)
If Not Channels.ContainsKey(pChannelType) Then Return
Channels(pChannelType).SoundControllerBassPercent = value
End Set
End Property
Public Property SeqControllerPercent(pChannelType As ChannelType) As Integer
Get
If Not Channels.ContainsKey(pChannelType) Then Return 0
Return Channels(pChannelType).SeqControllerPercent
End Get
Set(value As Integer)
If Not Channels.ContainsKey(pChannelType) Then Return
Channels(pChannelType).SeqControllerPercent = value
End Set
End Property
Public Property SeqControllerPercentMult(pChannelType As ChannelType) As Integer
Get
If Not Channels.ContainsKey(pChannelType) Then Return 0
Return Channels(pChannelType).SeqControllerPercentMult
End Get
Set(value As Integer)
If Not Channels.ContainsKey(pChannelType) Then Return
Channels(pChannelType).SeqControllerPercentMult = value
End Set
End Property
''' <summary>
''' 0~255
''' </summary>
Public Function TotalValue(pChannelType As ChannelType) As Integer
If Not Channels.ContainsKey(pChannelType) Then Return 0
With Channels(pChannelType)
Dim res = .UserValue _
+ _MainForm._frmSound.SoundController / 100 * .SoundControllerPercent _
+ _MainForm._frmSound.SoundControllerBass / 100 * .SoundControllerBassPercent _
+ _MainForm._frmSeq.SeqController(SeqControllerIdx) / 100 * .SeqControllerPercent
res = res * _MainForm._frmSeqMult.SeqController(SeqControllerIdx) / 255 * .SeqControllerPercentMult / 100 + res * (1 - .SeqControllerPercentMult / 100)
Return Math.Max(Math.Min(res, 255), 0)
End With
End Function
Public Function ValueToSend(pChannelType As ChannelType) As Integer
If Not Channels.ContainsKey(pChannelType) Then Return Channel.ValueUnkown
With Channels(pChannelType)
If .UserValue < 0 Then Return Channel.ValueUnkown
If pChannelType.Equals(ChannelTypes.Red) OrElse pChannelType.Equals(ChannelTypes.Green) OrElse pChannelType.Equals(ChannelTypes.Blue) Then
With HSVtoRGB(TotalValue(ChannelTypes.Red) / 255 * 360, TotalValue(ChannelTypes.Green) / 2.55, TotalValue(ChannelTypes.Blue) / 2.55)
If pChannelType.Equals(ChannelTypes.Red) Then Return .r
If pChannelType.Equals(ChannelTypes.Green) Then Return .g
If pChannelType.Equals(ChannelTypes.Blue) Then Return .b
End With
End If
End With
Return TotalValue(pChannelType)
End Function
End Class
Public Class ChannelData
Public Enum Modes
''' <summary>
''' dont ever (on any preset) show to user, send to DMX
''' </summary>
Hide
''' <summary>
''' show to user, dont allow him to change, dont send to DMX
''' </summary>
Ignore
''' <summary>
''' show to user, dont allow him to change, send to DMX
''' </summary>
[ReadOnly]
''' <summary>
''' show to user, allow him to change, send to DMX
''' </summary>
Show
End Enum
Public ChannelType As ChannelType
Public Mode As Modes
Public UserValue As Integer
'Public SoundControllerValue As Integer
Public SoundControllerPercent As Integer
Public SoundControllerBassPercent As Integer
'Public SeqControllerValue As Integer
Public SeqControllerPercent As Integer
Public SeqControllerPercentMult As Integer
Public Sub New(pChannelType As ChannelType, pMode As Modes, pUserValue As Integer, pSoundControllerPercent As Integer, pSoundControllerBassPercent As Integer, pSeqControllerPercent As Integer, pSeqControllerPercentMult As Integer)
ChannelType = pChannelType
Mode = pMode
UserValue = pUserValue
SoundControllerPercent = pSoundControllerPercent
SoundControllerBassPercent = pSoundControllerBassPercent
SeqControllerPercent = pSeqControllerPercent
SeqControllerPercentMult = pSeqControllerPercentMult
End Sub
End Class