-
Notifications
You must be signed in to change notification settings - Fork 2
/
modOutput.vb
546 lines (303 loc) · 14.1 KB
/
modOutput.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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
Option Strict Off
Option Explicit On
Module modOutput
Public Sub CreateBMS(ByRef strOutputPath As String, Optional ByVal Flag As Integer = 0)
On Error GoTo Err_Renamed
Dim strObjData(,) As String
Dim blnObjData(,) As Boolean
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim lngFFile As Integer
Dim intBPMNum As Integer
Dim intSTOPNum As Integer
Dim lngMaxMeasure As Integer
Dim lngTemp As Integer
Dim strTemp As String
Dim intArray() As Integer
Dim lngStop(MATERIAL_MAX) As Integer
Dim sngBPM(MATERIAL_MAX) As Single
If Flag = 0 Then frmMain.Text = g_strAppTitle & " - Now Saving..."
frmMain.Enabled = False
For i = 0 To MATERIAL_MAX
sngBPM(i) = 0
lngStop(i) = 0
Next i
'オブジェ整理
For i = 0 To UBound(g_Obj) - 1
With g_Obj(i)
If .intCh Then
If lngMaxMeasure < .intMeasure Then
lngMaxMeasure = .intMeasure
End If
Select Case .intCh
Case modInput.OBJ_CH.CH_EXBPM
If .sngValue > 0 And .sngValue < 256 And .sngValue = CInt(.sngValue) Then
.intCh = modInput.OBJ_CH.CH_BPM
Else
If intBPMNum > MATERIAL_MAX Then
Call MsgBox(g_Message(modMain.Message.ERR_OVERFLOW_BPM) & vbCrLf & g_Message(modMain.Message.ERR_SAVE_CANCEL), MsgBoxStyle.Critical, g_strAppTitle)
lngTemp = i - 1
GoTo Init
End If
intBPMNum = intBPMNum + 1
sngBPM(intBPMNum) = .sngValue
.sngValue = intBPMNum
End If
Case modInput.OBJ_CH.CH_STOP
If intSTOPNum > MATERIAL_MAX Then
Call MsgBox(g_Message(modMain.Message.ERR_OVERFLOW_STOP) & vbCrLf & g_Message(modMain.Message.ERR_SAVE_CANCEL), MsgBoxStyle.Critical, g_strAppTitle)
lngTemp = i - 1
GoTo Init
End If
intSTOPNum = intSTOPNum + 1
lngStop(intSTOPNum) = .sngValue
.sngValue = intSTOPNum
Case 11 To 29
If .intAtt = modMain.OBJ_ATT.OBJ_INVISIBLE Then
.intCh = .intCh + 20
ElseIf .intAtt = modMain.OBJ_ATT.OBJ_LONGNOTE Then
.intCh = .intCh + 40
End If
End Select
End If
End With
Next i
ReDim strObjData(132, lngMaxMeasure)
ReDim blnObjData(132, lngMaxMeasure)
For i = 0 To lngMaxMeasure
For j = LBound(strObjData, 1) To UBound(strObjData, 1)
strObjData(j, i) = New String("0", g_Measure(i).intLen * 2)
Next j
Next i
'オブジェからラインデータに変換
For i = 0 To UBound(g_Obj) - 1
With g_Obj(i)
Select Case .intCh
Case Is < 0
Case Is > 1000
Case Is > 100
strObjData(.intCh, .intMeasure) = Left(strObjData(.intCh, .intMeasure), .lngPosition * 2) & modInput.strFromNum(.sngValue) & Mid(strObjData(.intCh, .intMeasure), .lngPosition * 2 + 3)
For j = 101 To .intCh - 1
blnObjData(j, .intMeasure) = True
Next j
Case modInput.OBJ_CH.CH_BPM
strObjData(.intCh, .intMeasure) = Left(strObjData(.intCh, .intMeasure), .lngPosition * 2) & Right("0" & Hex(.sngValue), 2) & Mid(strObjData(.intCh, .intMeasure), .lngPosition * 2 + 3)
Case modInput.OBJ_CH.CH_EXBPM
strObjData(.intCh, .intMeasure) = Left(strObjData(.intCh, .intMeasure), .lngPosition * 2) & Right("0" & IIf(intBPMNum > 255, modInput.strFromNum(.sngValue), Hex(.sngValue)), 2) & Mid(strObjData(.intCh, .intMeasure), .lngPosition * 2 + 3)
Case modInput.OBJ_CH.CH_STOP
strObjData(.intCh, .intMeasure) = Left(strObjData(.intCh, .intMeasure), .lngPosition * 2) & Right("0" & IIf(intSTOPNum > 255, modInput.strFromNum(.sngValue), Hex(.sngValue)), 2) & Mid(strObjData(.intCh, .intMeasure), .lngPosition * 2 + 3)
Case Else
strObjData(.intCh, .intMeasure) = Left(strObjData(.intCh, .intMeasure), .lngPosition * 2) & modInput.strFromNum(.sngValue) & Mid(strObjData(.intCh, .intMeasure), .lngPosition * 2 + 3)
End Select
blnObjData(.intCh, .intMeasure) = True
End With
Next i
For i = LBound(strObjData, 2) To UBound(strObjData, 2)
For j = LBound(strObjData, 1) To UBound(strObjData, 1)
If blnObjData(j, i) Then
If strObjData(j, i) <> "00" Then
ReDim intArray(g_Measure(i).intLen + 1)
intArray(0) = g_Measure(i).intLen
strTemp = ""
lngTemp = 1
For k = 1 To Len(strObjData(j, i)) \ 2
If Mid(strObjData(j, i), k * 2 - 1, 2) = "00" Then
strTemp = strTemp & "0"
Else
intArray(lngTemp) = Len(strTemp)
lngTemp = lngTemp + 1
strTemp = "1"
End If
Next k
ReDim Preserve intArray(lngTemp)
intArray(lngTemp) = Len(strTemp)
lngTemp = intGetMaxDev(intArray)
If lngTemp Then
strTemp = ""
For k = 1 To Len(strObjData(j, i)) \ 2 Step lngTemp
strTemp = strTemp & Mid(strObjData(j, i), k * 2 - 1, 2)
Next k
strObjData(j, i) = strTemp
End If
End If
End If
Next j
Next i
lngFFile = FreeFile()
'出力開始
FileOpen(lngFFile, strOutputPath, OpenMode.Output)
With frmMain
PrintLine(lngFFile)
PrintLine(lngFFile, "*---------------------- HEADER FIELD")
PrintLine(lngFFile)
'If Flag Then Print #lngFFile, "#PATH_WAV " & g_BMS.strDir
If .cboPlayer.SelectedIndex > 1 Then
PrintLine(lngFFile, "#PLAYER 3")
Else
PrintLine(lngFFile, "#PLAYER " & .cboPlayer.SelectedIndex + 1)
End If
PrintLine(lngFFile, "#GENRE " & Trim(.txtGenre.Text))
PrintLine(lngFFile, "#TITLE " & Trim(.txtTitle.Text))
PrintLine(lngFFile, "#ARTIST " & Trim(.txtArtist.Text))
PrintLine(lngFFile, "#BPM " & Trim(.txtBPM.Text))
PrintLine(lngFFile, "#PLAYLEVEL " & Trim(.cboPlayLevel.Text))
PrintLine(lngFFile, "#RANK " & .cboPlayRank.SelectedIndex)
If Val(.txtTotal.Text) Then PrintLine(lngFFile, "#TOTAL " & .txtTotal.Text)
If Val(.txtVolume.Text) Then PrintLine(lngFFile, "#VOLWAV " & .txtVolume.Text)
PrintLine(lngFFile, "#STAGEFILE " & Trim(.txtStageFile.Text))
PrintLine(lngFFile)
For i = 1 To 1295
If Len(g_strWAV(i)) Then
PrintLine(lngFFile, "#WAV" & modInput.strFromNum(i) & " " & g_strWAV(i))
End If
Next i
PrintLine(lngFFile)
If Len(Trim(.txtMissBMP.Text)) Then
PrintLine(lngFFile, "#BMP00 " & .txtMissBMP.Text)
End If
For i = 1 To 1295
If Len(g_strBMP(i)) Then
PrintLine(lngFFile, "#BMP" & modInput.strFromNum(i) & " " & g_strBMP(i))
End If
Next i
PrintLine(lngFFile)
For i = 1 To 1295
If Len(g_strBGA(i)) Then
PrintLine(lngFFile, "#BGA" & modInput.strFromNum(i) & " " & g_strBGA(i))
End If
Next i
PrintLine(lngFFile)
If intBPMNum > 255 Then
For i = 1 To 1295
If sngBPM(i) Then
PrintLine(lngFFile, "#BPM" & Right("0" & modInput.strFromNum(i), 2) & " " & sngBPM(i))
End If
Next i
ElseIf intBPMNum Then
For i = 1 To 255
If sngBPM(i) Then
PrintLine(lngFFile, "#BPM" & Right("0" & Hex(i), 2) & " " & sngBPM(i))
End If
Next i
End If
PrintLine(lngFFile)
If intSTOPNum > 255 Then
For i = 1 To MATERIAL_MAX
If lngStop(i) Then
PrintLine(lngFFile, "#STOP" & Right("0" & modInput.strFromNum(i), 2) & " " & lngStop(i))
End If
Next i
ElseIf intSTOPNum Then
For i = 1 To 255
If lngStop(i) Then
PrintLine(lngFFile, "#STOP" & Right("0" & Hex(i), 2) & " " & lngStop(i))
End If
Next i
End If
PrintLine(lngFFile)
PrintLine(lngFFile, .txtExInfo.Text)
PrintLine(lngFFile)
End With
PrintLine(lngFFile)
PrintLine(lngFFile, "*---------------------- MAIN DATA FIELD")
PrintLine(lngFFile)
For i = 0 To UBound(blnObjData, 2)
For j = 101 To 132
If blnObjData(j, i) Then
PrintLine(lngFFile, "#" & Format(i, "000") & "01" & ":" & strObjData(j, i))
End If
Next j
With g_Measure(i)
If .intLen <> MEASURE_LENGTH Then
PrintLine(lngFFile, "#" & Format(i, "000") & "02:" & .intLen / MEASURE_LENGTH)
End If
End With
For j = 3 To 99
If blnObjData(j, i) Then
PrintLine(lngFFile, "#" & Format(i, "000") & Format(j, "00") & ":" & strObjData(j, i))
End If
Next j
PrintLine(lngFFile)
Next i
lngTemp = UBound(blnObjData, 2) + 1
For i = lngTemp To 999
With g_Measure(i)
If .intLen <> MEASURE_LENGTH Then
PrintLine(lngFFile, "#" & Format(i, "000") & "02:" & .intLen / MEASURE_LENGTH)
End If
End With
Next i
lngTemp = UBound(g_Obj) - 1
With g_BMS
.intPlayerType = frmMain.cboPlayer.SelectedIndex + 1
.strGenre = frmMain.txtGenre.Text
.strTitle = frmMain.txtTitle.Text
.strArtist = frmMain.txtArtist.Text
.lngPlayLevel = Val(frmMain.cboPlayLevel.Text)
.sngBPM = Val(frmMain.txtBPM.Text)
.intPlayRank = frmMain.cboPlayRank.SelectedIndex
.sngTotal = Val(frmMain.txtTotal.Text)
.intVolume = Val(frmMain.txtVolume.Text)
.strStageFile = frmMain.txtStageFile.Text
End With
Init:
FileClose(lngFFile)
For i = 0 To lngTemp
With g_Obj(i)
Select Case .intCh
Case modInput.OBJ_CH.CH_BPM
.intCh = modInput.OBJ_CH.CH_EXBPM
Case modInput.OBJ_CH.CH_EXBPM
.sngValue = sngBPM(.sngValue)
Case modInput.OBJ_CH.CH_STOP
.sngValue = lngStop(.sngValue)
Case 31 To 49
.intCh = .intCh - 20
Case 51 To 69
.intCh = .intCh - 40
End Select
End With
Next i
frmMain.Enabled = True
If Flag = 0 Then
g_BMS.blnSaveFlag = True
If Len(g_BMS.strDir) Then
If frmMain._mnuOptionsItem_1.Checked Then
frmMain.Text = g_strAppTitle & " - " & g_BMS.strFileName
Else
frmMain.Text = g_strAppTitle & " - " & g_BMS.strDir & g_BMS.strFileName
End If
End If
End If
Exit Sub
Err_Renamed:
Call MsgBox(g_Message(modMain.Message.ERR_SAVE_ERROR) & vbCrLf & g_Message(modMain.Message.ERR_SAVE_CANCEL) & vbCrLf & "Error No." & Err.Number & " " & Err.Description, MsgBoxStyle.Critical, g_strAppTitle)
frmMain.Enabled = True
frmMain.Text = g_strAppTitle & " - " & g_BMS.strDir & g_BMS.strFileName
End Sub
Private Function intGetMaxDev(ByRef BaseValue() As Integer) As Integer
Dim Count As Integer '配列の最大インデックス
Dim i As Integer 'カウンタ
Dim a, b As Integer '最大公約数を求める2つの要素
Count = UBound(BaseValue)
a = BaseValue(0)
'繰り返す回数は、(配列の数-1)回
For i = 1 To Count
b = BaseValue(i)
If b Then
Do While a <> b
If a > b Then
a = a - b
Else
b = b - a
End If
Loop
'1で等しい場合、最大公約数はない
If a = 1 Then intGetMaxDev = 0 : Exit Function
End If
Next i
'最大公約数を返す
intGetMaxDev = a
End Function
End Module