-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMake_Cytus2.py
1051 lines (910 loc) · 36.4 KB
/
Make_Cytus2.py
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
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from os import listdir
from os.path import isfile, join
import os
from pprint import pprint
import json
import re
import logging
def creat_flie(fliename, text):
try:
f = open(fliename, 'w+', encoding='utf8')
i = f.write(text)
f.close()
return 0
except Exception as e:
return e
def creat_C2(V2_data):
C2_data = {
"format_version": V2_data["format_version"],
"time_base": V2_data["time_base"],
"start_offset_time": 0,
"page_list": [],
"tempo_list": [{"tick": 0, "value": 0}],
"event_order_list": V2_data["event_order_list"],
"note_list": []
}
C2_data["tempo_list"][0]["value"] = V2_data["value"]
# 創造不會多給資料
C2_data["note_list"] = creat_note_list(V2_data)
C2_data["page_list"] = creat_page_list(V2_data)
return C2_data
#y = creat_note_list(V2_data)
def check_settings(V2_text):
error_txt = ''
error_txt += check_settings_title(V2_text, error_txt)
#error_txt += check_settings_note(V2_text,error_txt)
if error_txt == "":
tf = True
else:
tf = False
return [tf, error_txt]
def check_settings_title(V2_text, error_txt):
n = V2_text.split("\n")
textlist = [
"VERSION",
"BPM",
"PAGE_SHIFT",
"PAGE_SIZE",
"scan_line_direction_opposite",
"extension_of_time",
"auto_fix_type",
"change_type_to_LONG_form_x",
"change_type_to_SLIDE_form_x",
"format_version",
"beat",
"time_base",
"conversion_constant",
]
for i in range(0, len(textlist)):
t = n[i].split(" ")[0]
if textlist[i] != t:
error_txt += (textlist[i] + " 遺失或打錯(lose or error)\n")
return error_txt
def creat_note_list(V2_data):
note_list = []
note_template = {
"page_index": 0,
"type": 0,
"id": 0,
"tick": 0,
"x": 0.100000001490116,
"has_sibling": False,
"hold_tick": 0,
"next_id": 0,
"is_forward": False
}
for i in range(0, len(V2_data["note_list"])):
# print(i)
note_template["page_index"] = V2_data["note_list"][i]["C2_page_index"]
note_template["type"] = V2_data["note_list"][i]["C2_type"]
note_template["id"] = V2_data["note_list"][i]["id"]
note_template["tick"] = V2_data["note_list"][i]["C2_tick"]
note_template["x"] = V2_data["note_list"][i]["x"]
note_template["hold_tick"] = V2_data["note_list"][i]["C2_hold_tick"]
if V2_data["note_list"][i]["next_id"] == -1:
note_template["next_id"] = 0
else:
note_template["next_id"] = V2_data["note_list"][i]["next_id"]
if V2_data["note_list"][i]["end_id"] == 1:
note_template["next_id"] = -1
note_list.append(note_template.copy())
# print(json.dumps(note_list))
return note_list
def creat_page_list(V2_data):
page_list = V2_data["page_list"].copy()
for v in page_list:
del v["page_id"]
page_list[0]["scan_line_direction"] = page_list[2]["scan_line_direction"]
return page_list
def reset_page_list(V2_data):
len_note_list = len(V2_data["note_list"])
total_chart = V2_data["note_list"][len_note_list - 1]["C2_page_index"]
end_page_up_down = V2_data["note_list"][len_note_list - 1]["up_down"]
page_list = []
for i in range(total_chart - 1, -1, -1):
end_tick = (i + 1) * 960
start_tick = end_tick - 960
if i % 2:
if end_page_up_down == 222:
scan_line_direction = -1
else:
scan_line_direction = 1
else:
if end_page_up_down == 222:
scan_line_direction = 1
else:
scan_line_direction = -1
# print(i)
page_list_template = {
"start_tick": start_tick,
"end_tick": end_tick,
"scan_line_direction": scan_line_direction
}
page_list.append(page_list_template)
page_list.reverse()
return page_list
def V2_to_C2(V2_data):
# 以下放棄的註解( 雖然知道怎麼算了但還是不想改,讓使用者自己算最安全(X) )
# V2_data = offset_PAGE_SHIFT(V2_data) # 抵消掉PAGE_SHIFT帶來的誤差
# 抵消掉抵銷的時間...,到底喔...
# V2_data = offset_offset_PAGE_SHIFT(V2_data)
# V2_data = offset_offset_PAGE_SHIFT(V2_data)
if float(V2_data["extension_of_time"]) != 0:
V2_data = extension_of_time(V2_data) # 同時加減時間
V2_data = Bind(V2_data) # 綁定link(下一個)
V2_data = Bind2(V2_data) # 綁定CKlink(下一個)
V2_data = supplement_next_id(V2_data) # 綁定link(最後補-1)
V2_data = supplement_C2noteType(V2_data) # 綁定C2的note_type
V2_data = supplement_C2tempo_list_value(V2_data) # 設定C2的value
V2_data = supplement_C2_tick(V2_data) # 轉換C2_note的時間成tick
V2_data = supplement_C2_hold_tick(V2_data) # 轉換C2_note_hold的時間成tick
V2_data = supplement_end_id(V2_data) # 將是否為link結尾標記出來 是=1 否=0
# 綁定C2的page_index
V2_data = supplement_C2page_index(V2_data)
# 綁定掃線上下
V2_data = supplement_C2_up_down(V2_data)
# 綁定C2的page_id
V2_data = supplement_C2page_id(V2_data)
# 綁定C2的page_id
V2_data = supplement_C2_page_list_id(V2_data)
return V2_data
def extension_of_time(V2_data):
extension = float(V2_data["extension_of_time"])
# note_list
for i in range(0, len(V2_data["note_list"])):
note_time = float(V2_data["note_list"][i]["time"])
t = extension + note_time
V2_data["note_list"][i]["time"] = t
# BPM_list
for i in range(0, len(V2_data["BPM_list"])):
bpm_time = float(V2_data["BPM_list"][i]["time"])
t = extension + bpm_time
V2_data["BPM_list"][i]["time"] = t
# CHC_list
for i in range(0, len(V2_data["CHC_list"])):
chc_time = float(V2_data["CHC_list"][i]["time"])
t = extension + chc_time
V2_data["CHC_list"][i]["time"] = t
return V2_data
def offset_offset_PAGE_SHIFT(V2_data):
PAGE_SHIFT = float(V2_data["PAGE_SHIFT"])
C1_PAGE_SIZE = float(V2_data["PAGE_SIZE"])
setoff_time = (PAGE_SHIFT % C1_PAGE_SIZE)
#setoff_time = 0
for i in range(0, len(V2_data["note_list"])):
note_time = float(V2_data["note_list"][i]["time"])
V2_data["note_list"][i]["time"] = note_time - setoff_time
return V2_data
def fix_hold_error(V2_data):
for i in range(0, len(V2_data["note_list"])):
# tick_out 偵測
C2_hold_tick = V2_data["note_list"][i]["C2_hold_tick"]
hold_tick_out = V2_data["note_list"][i]["hold_tick_out"]
if C2_hold_tick > 0 and hold_tick_out == 99999:
C2_page_index = V2_data["note_list"][i]["C2_page_index"]
V2_data["note_list"][i]["C2_page_index"] = C2_page_index + 1
page_list_id = V2_data["note_list"][i]["page_list_id"]
V2_data["note_list"][i]["page_list_id"] = page_list_id + 1
start_tick = V2_data["note_list"][i]["start_tick"]
V2_data["note_list"][i]["start_tick"] = start_tick + 960
end_tick = V2_data["note_list"][i]["end_tick"]
V2_data["note_list"][i]["end_tick"] = end_tick + 960
up_down = V2_data["note_list"][i]["up_down"]
if up_down == 222:
V2_data["note_list"][i]["up_down"] = 8888
else:
V2_data["note_list"][i]["up_down"] = 222
V2_data["note_list"][i]["fix_error"] = 1
elif C2_hold_tick > 0 and hold_tick_out == 88888:
V2_data["note_list"][i]["C2_type"] = 2
V2_data["note_list"][i]["fix_error"] = 1
else:
V2_data["note_list"][i]["fix_error"] = 0
return V2_data
def click_error(V2_data):
for i in range(0, len(V2_data["note_list"])):
# tick_out 偵測標記
C2_tick = V2_data["note_list"][i]["C2_tick"]
start_tick = V2_data["note_list"][i]["start_tick"]
end_tick = V2_data["note_list"][i]["end_tick"]
tick_page = V2_data["note_list"][i]['tick_page']
if (C2_tick > end_tick) or (C2_tick < start_tick):
V2_data["note_list"][i]["note_tick_out"] = 99999
else:
V2_data["note_list"][i]["note_tick_out"] = 0
#i = 308
# hold_tick 過界偵測
hold_tick = float(V2_data["note_list"][i]["C2_hold_tick"])
all_tick = C2_tick + hold_tick
if (all_tick > end_tick) or (all_tick < start_tick):
if hold_tick > tick_page:
V2_data["note_list"][i]["hold_tick_out"] = 88888
else:
V2_data["note_list"][i]["hold_tick_out"] = 99999
else:
V2_data["note_list"][i]["hold_tick_out"] = 0
V2_data["note_list"][i]["fix_error"] = 0
return V2_data
def supplement_C2_page_list_id(V2_data):
for i in range(0, len(V2_data["note_list"])):
page_list_id = V2_data["note_list"][i]["C2_page_index"]
V2_data["note_list"][i]["page_list_id"] = page_list_id - 1
return V2_data
def supplement_C2page_id(V2_data):
for i in range(0, len(V2_data["note_list"])):
note_time = float(V2_data["note_list"][i]["time"])
end_tick = (V2_data["note_list"][i]["C2_page_index"]) * 960
start_tick = end_tick - 960
V2_data["note_list"][i]["start_tick"] = start_tick
V2_data["note_list"][i]["end_tick"] = end_tick
return V2_data
def offset_PAGE_SHIFT(V2_data):
PAGE_SHIFT = float(V2_data["PAGE_SHIFT"])
C1_PAGE_SIZE = float(V2_data["PAGE_SIZE"])
setoff_time = (PAGE_SHIFT % C1_PAGE_SIZE)
#setoff_time = 0
for i in range(0, len(V2_data["note_list"])):
note_time = float(V2_data["note_list"][i]["time"])
V2_data["note_list"][i]["time"] = note_time + setoff_time
return V2_data
def output_V1plus(fliename, V2_data_Bind_sup): # 雖然不是純 V1 www
text = 'BPM\t' + str(int(V2_data_Bind_sup["BPM"])) + '\n'
text = text + 'PAGE_SHIFT\t' + str(V2_data_Bind_sup["PAGE_SHIFT"]) + '\n'
text = text + 'PAGE_SIZE\t' + str(V2_data_Bind_sup["PAGE_SIZE"]) + '\n'
text = text + 'value\t' + str(V2_data_Bind_sup["value"]) + '\n'
col_name = [
"c1v2NoteType",
"tc1v2NoteId",
"tc1v2NoteTime",
"tc1v2NoteX",
"tc1v2HoldTime",
"tc1v1NextLink",
"c2v0NoteType",
"c2v0PageListId(first is 1)",
"c2v0PageListId(first is 0)",
"c2v0NoteTick",
"c2v0HoldTick",
"c2v0scan_line_direction(8888_up,222_down)",
"c2v0IsLinkEnd?(1=y,0=n)",
"c2v0StartTick",
"c2v0EndTick",
"NoteTimeOverrun",
"HoldTimeOverrun",
"FixHoldError"
]
for j in range(0, len(col_name)):
text += str(col_name[j]) + '\t'
text += '\n'
V2_data_Bind_len = len(V2_data_Bind_sup["note_list"])
n = V2_data_Bind_sup["note_list"]
for i in range(0, V2_data_Bind_len):
note = [
str(n[i]["type"]),
str(n[i]["id"]),
str(n[i]["time"]),
str(n[i]["x"]),
str(n[i]["hold"]),
str(n[i]["next_id"]),
str(n[i]["C2_type"]),
str(n[i]["C2_page_index"]),
str(n[i]["page_list_id"]),
str(n[i]["C2_tick"]),
str(n[i]["C2_hold_tick"]),
str(n[i]["up_down"]),
str(n[i]["end_id"]),
str(n[i]["start_tick"]),
str(n[i]["end_tick"]),
str(n[i]["note_tick_out"]),
str(n[i]["hold_tick_out"]),
str(n[i]["fix_error"])
]
for k in range(0, len(note)):
text += str(note[k]) + '\t'
text += '\n'
try:
f = open(fliename + ".v1plus", 'w+', encoding='utf8')
i = f.write(text)
f.close()
return 0
except Exception as e:
return e
def creat_C2V0plus(V2_data):
C2_data = {
"format_version": V2_data["format_version"],
"time_base": V2_data["time_base"],
"start_offset_time": 0,
"page_list": [],
"tempo_list": [{"tick": 0, "value": 0}],
"event_order_list": V2_data["event_order_list"],
"note_list": []
}
C2_data["tempo_list"][0]["value"] = V2_data["value"]
# 創造不會多給資料
C2_data["note_list"] = V2_data["note_list"]
C2_data["page_list"] = V2_data["page_list"]
return C2_data
def supplement_C2_up_down(V2_data):
PAGE_SHIFT = float(V2_data["PAGE_SHIFT"])
C1_PAGE_SIZE = float(V2_data["PAGE_SIZE"])
for i in range(0, len(V2_data["note_list"])):
note_time = float(V2_data["note_list"][i]["time"])
if PAGE_SHIFT >= 1:
if int((note_time + PAGE_SHIFT % 1 / C1_PAGE_SIZE) / C1_PAGE_SIZE) % 2:
V2_data["note_list"][i]["up_down"] = 8888 # 8888
else:
V2_data["note_list"][i]["up_down"] = 222 # 222
else:
if int((note_time + PAGE_SHIFT % 1 / C1_PAGE_SIZE) / C1_PAGE_SIZE) % 2:
V2_data["note_list"][i]["up_down"] = 222 # 222
else:
V2_data["note_list"][i]["up_down"] = 8888 # 8888
return V2_data
def supplement_C2_hold_tick(V2_data):
value = V2_data["value"]
BPM = float(V2_data["conversion_constant"]) / value
Beats = int(V2_data["beat"])
C1_PAGE_SIZE = 60 * Beats / BPM / 2
start_to_end_tick_base = 960
s_tick = C1_PAGE_SIZE / start_to_end_tick_base
for i in range(0, len(V2_data["note_list"])):
if float(V2_data["note_list"][i]["hold"]) == 0:
V2_data["note_list"][i]["C2_hold_tick"] = 0
continue
note_hold_time = float(V2_data["note_list"][i]["hold"])
C2_hold_tick = int(note_hold_time / s_tick)
V2_data["note_list"][i]["C2_hold_tick"] = C2_hold_tick
return V2_data
def supplement_C2_tick(V2_data):
value = V2_data["value"]
BPM = float(V2_data["conversion_constant"]) / value
Beats = int(V2_data["beat"])
C1_PAGE_SIZE = 60 * Beats / BPM / 2
start_to_end_tick_base = 960
s_tick = C1_PAGE_SIZE / start_to_end_tick_base
#PAGE_SHIFT = float(V2_data["PAGE_SHIFT"])
for i in range(0, len(V2_data["note_list"])):
note_time = float(V2_data["note_list"][i]["time"])
C2_tick = int(note_time / s_tick)
V2_data["note_list"][i]["C2_tick"] = C2_tick
return V2_data
def supplement_C2tempo_list_value(V2_data):
BPM = float(V2_data["BPM"])
value = float(V2_data["conversion_constant"]) / BPM
V2_data["value"] = int(value) * 2
return V2_data
def supplement_C2page_index(V2_data_type_sup):
BPM = float(V2_data_type_sup["BPM"])
PAGE_SHIFT = float(V2_data_type_sup["PAGE_SHIFT"])
PAGE_SIZE = float(V2_data_type_sup["PAGE_SIZE"])
for i in range(0, len(V2_data_type_sup["note_list"])):
note_time = float(V2_data_type_sup["note_list"][i]["time"])
page_index = int((note_time - (PAGE_SHIFT % PAGE_SIZE) +
PAGE_SHIFT % 1 / PAGE_SIZE) / PAGE_SIZE)
V2_data_type_sup["note_list"][i]["C2_page_index"] = page_index
return V2_data_type_sup
def supplement_C2noteType_ToAllNote(V2_data_Bind_sup):
for i in range(0, len(V2_data_Bind_sup["note_list"])):
V2_data_Bind_sup["note_list"][i]["C2_type"] = 0
return V2_data_Bind_sup
def supplement_C2noteType_ToLinkBody(V2_data_Bind_sup):
for i in range(0, len(V2_data_Bind_sup["link_list"])):
link_len = len(V2_data_Bind_sup["link_list"][i]["id_list"])
for j in range(0, link_len):
id = int(V2_data_Bind_sup["link_list"][i]["id_list"][j])
V2_data_Bind_sup["note_list"][id]["C2_type"] = 4
return V2_data_Bind_sup
def supplement_C2noteType_ToLinkhead(V2_data_Bind_sup):
for i in range(0, len(V2_data_Bind_sup["link_list"])):
id = int(V2_data_Bind_sup["link_list"][i]["id_list"][0])
V2_data_Bind_sup["note_list"][id]["C2_type"] = 3
return V2_data_Bind_sup
def supplement_C2noteType_ToCkLinkBody(V2_data_Bind_sup):
for i in range(0, len(V2_data_Bind_sup["CkLink_list"])):
link_len = len(V2_data_Bind_sup["CkLink_list"][i]["id_list"])
for j in range(0, link_len):
id = int(V2_data_Bind_sup["CkLink_list"][i]["id_list"][j])
V2_data_Bind_sup["note_list"][id]["C2_type"] = 7
return V2_data_Bind_sup
def supplement_C2noteType_ToCkLinkhead(V2_data_Bind_sup):
for i in range(0, len(V2_data_Bind_sup["CkLink_list"])):
id = int(V2_data_Bind_sup["CkLink_list"][i]["id_list"][0])
V2_data_Bind_sup["note_list"][id]["C2_type"] = 6
return V2_data_Bind_sup
def supplement_C2noteType_ToHold(V2_data_Bind_sup):
for i in range(0, len(V2_data_Bind_sup["note_list"])):
if float(V2_data_Bind_sup["note_list"][i]["hold"]) > 0:
V2_data_Bind_sup["note_list"][i]["C2_type"] = 1
return V2_data_Bind_sup
def supplement_C2noteType_ToHold2(V2_data_Bind_sup):
for i in range(0, len(V2_data_Bind_sup["note_list"])):
if str(V2_data_Bind_sup["note_list"][i]["type"]) == "HOLD":
V2_data_Bind_sup["note_list"][i]["C2_type"] = 1
return V2_data_Bind_sup
def supplement_C2noteType_ToLONG(V2_data_Bind_sup):
for i in range(0, len(V2_data_Bind_sup["note_list"])):
if str(V2_data_Bind_sup["note_list"][i]["type"]) == "LONG":
V2_data_Bind_sup["note_list"][i]["C2_type"] = 2
return V2_data_Bind_sup
def supplement_C2noteType_ToSLIDE(V2_data_Bind_sup):
for i in range(0, len(V2_data_Bind_sup["note_list"])):
if str(V2_data_Bind_sup["note_list"][i]["type"]) == "SLIDE":
V2_data_Bind_sup["note_list"][i]["C2_type"] = 5
return V2_data_Bind_sup
def supplement_C2noteType(V2_data_Bind_sup):
V2_data_Bind_sup = supplement_C2noteType_ToAllNote(V2_data_Bind_sup)
V2_data_Bind_sup = supplement_C2noteType_ToHold(V2_data_Bind_sup)
V2_data_Bind_sup = supplement_C2noteType_ToHold2(V2_data_Bind_sup)
V2_data_Bind_sup = supplement_C2noteType_ToLONG(V2_data_Bind_sup)
V2_data_Bind_sup = supplement_C2noteType_ToSLIDE(V2_data_Bind_sup)
V2_data_Bind_sup = supplement_C2noteType_ToLinkBody(V2_data_Bind_sup)
V2_data_Bind_sup = supplement_C2noteType_ToLinkhead(V2_data_Bind_sup)
V2_data_Bind_sup = supplement_C2noteType_ToCkLinkBody(V2_data_Bind_sup)
V2_data_Bind_sup = supplement_C2noteType_ToCkLinkhead(V2_data_Bind_sup)
return V2_data_Bind_sup
def supplement_end_id(V2_data):
for i in range(0, len(V2_data["note_list"])):
V2_data["note_list"][i]["end_id"] = 0
for j in range(0, len(V2_data["link_list"])):
link_len = len(V2_data["link_list"][j]["id_list"])
id = int(V2_data["link_list"][j]["id_list"][link_len - 1])
V2_data["note_list"][id]["end_id"] = 1
return V2_data
def supplement_next_id(V2_data_Bind):
for i in range(0, len(V2_data_Bind["note_list"])):
try:
V2_data_Bind["note_list"][i]["next_id"]
except Exception as e:
V2_data_Bind["note_list"][i]["next_id"] = -1
return V2_data_Bind
def Bind(V2_data):
len(V2_data["link_list"])
for i in range(0, len(V2_data["link_list"])):
link_len = len(V2_data["link_list"][i]["id_list"])
if link_len > 1:
for j in range(0, link_len - 1):
id = int(V2_data["link_list"][i]["id_list"][j])
V2_data["note_list"][id]["next_id"] = V2_data["link_list"][i]["id_list"][j + 1]
return V2_data
def Bind2(V2_data):
len(V2_data["CkLink_list"])
for i in range(0, len(V2_data["CkLink_list"])):
link_len = len(V2_data["CkLink_list"][i]["id_list"])
if link_len > 1:
for j in range(0, link_len - 1):
id = int(V2_data["CkLink_list"][i]["id_list"][j])
V2_data["note_list"][id]["next_id"] = V2_data["CkLink_list"][i]["id_list"][j + 1]
return V2_data
def get_extension(filename, reciprocal):
extension = filename.split(".")[reciprocal]
return extension
def get_V2_text(fliename):
try:
f = open(fliename, 'r+', encoding='utf8')
t = f.read()
f.close()
return t
except Exception as e:
return e
def get_V2_data(V2_text):
n = V2_text.split("\n")
ctrl_line = 13
data = {
"VERSION": int(n[0].split(" ")[-1]),
"BPM": float(n[1].split(" ")[-1]),
"PAGE_SHIFT": float(n[2].split(" ")[-1]),
"PAGE_SIZE": float(n[3].split(" ")[-1]),
"scan_line_direction_opposite": int(n[4].split(" ")[-1]),
"extension_of_time": float(n[5].split(" ")[-1]),
"auto_fix_type": int(n[6].split(" ")[-1]),
"change_type_to_LONG_form_x": int(n[7].split(" ")[-1]),
"change_type_to_SLIDE_form_x": int(n[8].split(" ")[-1]),
"format_version": int(n[9].split(" ")[-1]),
"beat": int(n[10].split(" ")[-1]),
"time_base": int(n[11].split(" ")[-1]),
"conversion_constant": int(n[12].split(" ")[-1]),
"note_list": [],
"link_list": [],
"CkLink_list":[],
"CHC_list": [],
"BPM_list": []
}
'''
# 原本打算把上面的"設定"做成"在哪行都能用"
# 剩至直接 for k in range(0,len(n)) 這種的,但懶癌發作zzz
# 暫時放棄,等哪天有心情吧
#(^^^現在想想還是嚴格點,會比較好閱讀 2018/06/17)
for j in range(0,ctrl_line):
n[j]
u = ['y','s','ewe']
'y' in u
u.index('y')
'''
eee = 0 # 錯誤的次數
for i in range(ctrl_line, len(n)):
if n[i] == '':
continue
rt = get_type(n[i])
rt = rt.upper() # 通通轉大寫,容錯率up~
# print(i)
# print(rt)
# print("-------")
# 預處理,刪同樣的code
isin = 'NOTECHCBPMHOLDLONGSLIDE'
if rt == 'LINK' or rt == 'CKLINK':
# 該方法修正了LINK有2個空白連在一起會出事的問題
r = re.compile('\d+')
j = r.findall(str(n[i]))
elif rt in isin and rt != '':
# 該方式可直接從excel複製進來就能直接轉
r1 = re.sub(' ', '', str(n[i]))
j = r1.split('\t')
else:
eee += 1 # 錯誤次數+1
print("type錯誤!請修正後再來,以下詳情:")
print("type erroe! plz fix this and try again, error detailed:")
print("出錯行數 ; error line :")
print(i + 1)
print("錯誤的內容 ; error text")
print(n[i])
# 開始處理標頭以外的東東
if rt == 'NOTE':
type = "NOTE"
x = float(j[3])
# 設定用x設定的SLIDE x
slide = int(n[8].split(" ")[-1])
if slide > 100 and slide < 1000 and slide != 0:
# 設定用x設定的SLIDE type
# w = str(float(j[3]))
# w = str(0.200456)[-3:-1]
# int(1.900456)
if int(float(j[3]) * 1000000) % 1000 == slide:
type = "SLIDE"
x = change_type_form_x(float(j[3]), slide)
#x = int(x*1000000 - slide)/1000000
# slide = 456
# 設定用x設定的LONG x
long = int(n[7].split(" ")[-1])
if long > 100 and long < 1000 and long != 0:
# 設定用x設定的LONG type
if int(float(j[3]) * 1000000 % 1000) == long:
x = change_type_form_x(float(j[3]), long)
type = "LONG"
# x = x - (long*0.000001)
k = {
"type": type,
"id": int(j[1]),
"time": float(j[2]),
"x": x,
"hold": float(j[4])
}
data["note_list"].append(k)
elif rt == 'LINK':
k = {
"type": "LINK",
"id_list": []
}
k["id_list"] = j
data["link_list"].append(k)
elif rt == 'CKLINK':
k = {
"type": "CKLINK",
"id_list": []
}
k["id_list"] = j
data["CkLink_list"].append(k)
elif rt == 'CHC':
k = {
"type": "CHC",
"mode": int(j[1]),
"time": float(j[2]),
}
data["CHC_list"].append(k)
elif rt == 'BPM':
k = {
"type": "BPM",
"BPM": float(j[1]),
"time": float(j[2]),
}
data["BPM_list"].append(k)
elif rt == 'SLIDE':
k = {
"type": "SLIDE",
"id": int(j[1]),
"time": float(j[2]),
"x": float(j[3]),
"hold": float(j[4])
}
data["note_list"].append(k)
elif rt == 'LONG':
k = {
"type": "LONG",
"id": int(j[1]),
"time": float(j[2]),
"x": float(j[3]),
"hold": float(j[4])
}
data["note_list"].append(k)
elif rt == 'HOLD':
k = {
"type": "HOLD",
"id": int(j[1]),
"time": float(j[2]),
"x": float(j[3]),
"hold": float(j[4])
}
data["note_list"].append(k)
if eee != 0:
return [False, eee]
return [True, data]
# -------------------------------------------------------------------------------
def change_type_form_x(x, v):
x2 = str(x)
# x = 0.165456
p = x2.find('.')
x3 = x2[(p + 4):(p + 7)]
if x3 == str(v):
x4 = float((str(x2[0:(p + 4)]) + '000'))
return x4
else:
return x
# change_type_form_x(0.287456,456)
# v = 456
def get_type(t):
# 後來才想到正則去解,但算了 目前能用且沒多大的影響
# print(t)
# print(type(t))
s = ""
i = 0
while 1:
# print("-------")
# print(i)
# print(t[i])
if t[i] == " " or t[i] == "\t":
# print(s)
return s
else:
s += t[i]
i += 1
def chang_CHC_BPM(V2_data):
page_list = get_new_page_list(V2_data)
# len(page_list)
V2_data = reset_page_index(V2_data, page_list)
page_list = reset_page_list_up_down(V2_data, page_list)
event_order_list = set_CHC(V2_data)
V2_data["page_list"] = page_list
V2_data["event_order_list"] = event_order_list
return V2_data
def get_new_page_list(V2_data):
end_tick = 0
o_page_time = float(V2_data["PAGE_SIZE"])
page_base = 960
len_note_list = len(V2_data["note_list"])
O_bpm = float(V2_data["BPM"])
# set_bpm = set_bpm.clear()
set_bpm = V2_data["BPM_list"].copy()
set_bpm.insert(0, {'BPM': O_bpm, 'time': 0, 'type': 'BPM'}) # 插入原始BPM較好處理
end_time = float(V2_data["note_list"][len_note_list - 1]["time"])
set_bpm.append({'BPM': set_bpm[len(set_bpm) - 1]['BPM'],
'time': end_time, 'type': 'BPM'}) # 插入最後的BPM較好處理
print("set_bpm = \n",set_bpm)
print("============================")
page_list = []
page_id = 0
# l=2
for l in range(0, len(set_bpm)-1): #抓後面比前面 所以-1
#if l >= (len(set_bpm) - 1):
# break
# set_bpm[3]
print("l = ",l)
print("BPM = ",set_bpm[l])
#先將BPM抓出來,才能做比例(做單幕時間)
now_bpm = set_bpm[l]["BPM"]
proportion = O_bpm / now_bpm
#差時抓出來後除單幕時間等於數量
gap_time = float(set_bpm[l + 1]["time"]) - float(set_bpm[l]["time"])
near = gap_time / (o_page_time*proportion)
# near = 11.01
print("near = ",near)
print("----------------")
#找出逼近哪個幕值,此值將為生產多少的幕
if int(round(near % 1, 1)*10) > 5:
w = 1
else:
w = 0
v = int(near) + w
#因為next time的bug(?) 所以先在尾末加多的幕出來
#之後再看是要怎麼修
if l == len(set_bpm)-2:
v += 50
pass
#比對與原BPM的比例去決定生產幕的時間
#now_bpm = set_bpm[l]["BPM"]
for k in range(v):
# print("k = ",k)
#proportion = O_bpm / now_bpm
start_tick = end_tick
end_tick = end_tick + (page_base * proportion)
i = end_tick
page_list_template = {
"start_tick": int(start_tick),
"end_tick": int(end_tick),
"scan_line_direction": -1,
"page_id": int(page_id)
}
page_list.append(page_list_template)
page_id += 1
# page_list
return page_list
def time_to_C2tick(V2_data, time):
value = V2_data["value"]
BPM = float(V2_data["conversion_constant"]) / value
Beats = int(V2_data["beat"])
C1_PAGE_SIZE = 60 * Beats / BPM / 2
start_to_end_tick_base = 960
s_tick = C1_PAGE_SIZE / start_to_end_tick_base
# PAGE_SHIFT = float(V2_data["PAGE_SHIFT"])
note_time = float(time)
C2_tick = int(note_time / s_tick)
return C2_tick
# time_to_C2tick(V2_data, 91.935768)
def offset_PAGE_SHIFT_of_time(V2_data, time):
PAGE_SHIFT = float(V2_data["PAGE_SHIFT"])
C1_PAGE_SIZE = float(V2_data["PAGE_SIZE"])
setoff_time = (PAGE_SHIFT % C1_PAGE_SIZE)
re_time = float(time) + float(setoff_time)
return re_time
def reset_page_index(V2_data, page_list):
page_list_pointer = 0
i = 0
while i < len(V2_data["note_list"]):
cut = V2_data["note_list"]
x = cut[i]["C2_tick"]
#print("page_list_pointer = " + str(page_list_pointer))
#print("i =" + str(i))
#logging.debug("page_list_pointer = " + str(page_list_pointer))
#logging.debug("i =" + str(i))
st = page_list[page_list_pointer]["start_tick"]
ed = page_list[page_list_pointer]["end_tick"]
#print("st = " + str(st))
#print("x =" + str(x))
#print("ed =" + str(ed))
#print(x < ed and x > st)
# print("-----------------------")
#logging.debug("st = " + str(st))
#logging.debug("x =" + str(x))
#logging.debug("ed =" + str(ed))
#logging.debug(str(x < ed and x > st))
# logging.debug("-----------------------")
if x <= ed and x > st:
cut[i]['C2_page_index'] = page_list_pointer
cut[i]['start_tick'] = st
cut[i]['end_tick'] = ed
cut[i]['tick_page'] = ed - st
i += 1
else:
page_list_pointer += 1
return reset_page_up_down(V2_data)
# i=254
# page_list[143]["start_tick"]
# page_list[106]["start_tick"]
def reset_page_up_down(V2_data):
# opposite = 0
# opposite = 1
opposite = V2_data["scan_line_direction_opposite"]
for i in range(0, len(V2_data["note_list"])):
cut = V2_data["note_list"]
yy = cut[i]["C2_page_index"] % 2
# print("i =",i)
# print("yy = ",yy)
if opposite == 0:
if yy == 1:
cut[i]["up_down"] = 8888
else:
cut[i]["up_down"] = 222
else:
if yy == 1:
cut[i]["up_down"] = 222
else:
cut[i]["up_down"] = 8888
# print(cut[i]["up_down"])
return V2_data
def reset_page_list_up_down(V2_data, page_list):
# 將上面8888 222 結果同步回去page_list
len_note_list = len(V2_data["note_list"])
end_page_up_down = V2_data["note_list"][len_note_list - 1]["up_down"]
len_page_list = len(page_list)
for k in range(len_page_list - 1, 0, -1):
# print(k)
if k % 2:
if end_page_up_down == 222:
page_list[k]["scan_line_direction"] = -1
else:
page_list[k]["scan_line_direction"] = 1
else:
if end_page_up_down == 222:
page_list[k]["scan_line_direction"] = 1
else:
page_list[k]["scan_line_direction"] = -1
return page_list
# i=20
def set_CHC(V2_data):
event_order_list = []
CHC_list = V2_data["CHC_list"]
for i in range(0, len(CHC_list)):
yyyy = offset_PAGE_SHIFT_of_time(V2_data, CHC_list[i]["time"])
tick = time_to_C2tick(V2_data, yyyy)
if CHC_list[i]["mode"] == 1:
type = 0
args = 'R'
else: # 有點小危險
type = 1
args = 'G'
CHC_template = {
"tick": tick,
"event_list": [{
"type": type, # 1+G 0+R
"args": args
}]
}
event_order_list.append(CHC_template)
return event_order_list
def Make_Cytus2():
mypath = os.getcwd()
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
# i=6
for i in range(0, len(onlyfiles)):
j = str(onlyfiles[i])
fliename = j
if get_extension(j, -1) == 'txt' and (get_extension(j, -2) == 'hard' or get_extension(j, -2) == 'esey'):
V2_fliename = fliename
V2_text = get_V2_text(j)
# logging.info("轉換對象(Conversion object):" + fliename)
print("轉換對象(Conversion object):" + fliename)
carry_on = check_settings(V2_text) # [true or false,error text]
if carry_on[0]:
KeepOn_and_V2Data = get_V2_data(V2_text)