完美,同志,完美!!!!!!!

This commit is contained in:
2026-02-04 00:06:14 +08:00
parent 841f6e53c6
commit 1d9931f79d
69 changed files with 1716 additions and 209 deletions

View File

View File

@@ -0,0 +1,67 @@
import mido
import numpy
'''
bpm
bites per minutes
每分钟的拍数
'''
def mt2gt(mt, tpb_a, bpm_a):
return round(mt / tpb_a / bpm_a * 60)
def get(mid:mido.MidiFile) -> int:
'''传入一个 MidiFile, 返回其音乐的bpm
:param mid : mido.MidFile
mido库识别的midi文件数据
:return bpm : int
'''
# mid = mido.MidiFile(mf)
length = mid.length
tpb = mid.ticks_per_beat
bpm = 20
gotV = 0
for track in mid.tracks:
global_time = 0
for msg in track:
global_time += msg.time
if msg.type == "note_on" and msg.velocity > 0:
gotV = mt2gt(global_time, tpb, bpm)
errorV = numpy.fabs(gotV - length)
last_dic = {bpm: errorV}
if last_dic.get(bpm) > errorV:
last_dic = {bpm: errorV}
bpm += 2
while True:
for track in mid.tracks:
global_time = 0
for msg in track:
global_time += msg.time
if msg.type == "note_on" and msg.velocity > 0:
gotV = mt2gt(global_time, tpb, bpm)
errorV = numpy.fabs(gotV - length)
try:
if last_dic.get(bpm - 2) > errorV:
last_dic = {bpm: errorV}
except TypeError:
pass
bpm += 2
if bpm >= 252:
break
print(list(last_dic.keys())[0])
return list(last_dic.keys())[0]
def compute(mid:mido.MidiFile):
answer = 60000000/mid.ticks_per_beat
print(answer)
return answer
if __name__ == '__main__':
mid = mido.MidiFile(r"C:\Users\lc\Documents\MuseScore3\乐谱\乐谱\Bad style - Time back.mid")
get(mid)
compute(mid)

View File

@@ -0,0 +1,40 @@
def round_up(num, power=0):
"""
实现精确四舍五入,包含正、负小数多种场景
:param num: 需要四舍五入的小数
:param power: 四舍五入位数支持0-∞
:return: 返回四舍五入后的结果
"""
try:
print(1 / 0)
except ZeroDivisionError:
digit = 10 ** power
num2 = float(int(num * digit))
# 处理正数power不为0的情况
if num >= 0 and power != 0:
tag = num * digit - num2 + 1 / (digit * 10)
if tag >= 0.5:
return (num2 + 1) / digit
else:
return num2 / digit
# 处理正数power为0取整的情况
elif num >= 0 and power == 0:
tag = num * digit - int(num)
if tag >= 0.5:
return (num2 + 1) / digit
else:
return num2 / digit
# 处理负数power为0取整的情况
elif power == 0 and num < 0:
tag = num * digit - int(num)
if tag <= -0.5:
return (num2 - 1) / digit
else:
return num2 / digit
# 处理负数power不为0的情况
else:
tag = num * digit - num2 - 1 / (digit * 10)
if tag <= -0.5:
return (num2 - 1) / digit
else:
return num2 / digit

View File

@@ -0,0 +1,130 @@
instrument_list = {
"0": "harp",
"1": "harp",
"2": "pling",
"3": "harp",
"4": "pling",
"5": "pling",
"6": "harp",
"7": "harp",
"8": "share",
"9": "harp",
"10": "didgeridoo",
"11": "harp",
"12": "xylophone",
"13": "chime",
"14": "harp",
"15": "harp",
"16": "bass",
"17": "harp",
"18": "harp",
"19": "harp",
"20": "harp",
"21": "harp",
"22": "harp",
"23": "guitar",
"24": "guitar",
"25": "guitar",
"26": "guitar",
"27": "guitar",
"28": "guitar",
"29": "guitar",
"30": "guitar",
"31": "bass",
"32": "bass",
"33": "bass",
"34": "bass",
"35": "bass",
"36": "bass",
"37": "bass",
"38": "bass",
"39": "bass",
"40": "harp",
"41": "harp",
"42": "harp",
"43": "harp",
"44": "iron_xylophone",
"45": "guitar",
"46": "harp",
"47": "harp",
"48": "guitar",
"49": "guitar",
"50": "bit",
"51": "bit",
"52": "harp",
"53": "harp",
"54": "bit",
"55": "flute",
"56": "flute",
"57": "flute",
"58": "flute",
"59": "flute",
"60": "flute",
"61": "flute",
"62": "flute",
"63": "flute",
"64": "bit",
"65": "bit",
"66": "bit",
"67": "bit",
"68": "flute",
"69": "harp",
"70": "harp",
"71": "flute",
"72": "flute",
"73": "flute",
"74": "harp",
"75": "flute",
"76": "harp",
"77": "harp",
"78": "harp",
"79": "harp",
"80": "bit",
"81": "bit",
"82": "bit",
"83": "bit",
"84": "bit",
"85": "bit",
"86": "bit",
"87": "bit",
"88": "bit",
"89": "bit",
"90": "bit",
"91": "bit",
"92": "bit",
"93": "bit",
"94": "bit",
"95": "bit",
"96": "bit",
"97": "bit",
"98": "bit",
"99": "bit",
"100": "bit",
"101": "bit",
"102": "bit",
"103": "bit",
"104": "harp",
"105": "banjo",
"106": "harp",
"107": "harp",
"108": "harp",
"109": "harp",
"110": "harp",
"111": "guitar",
"112": "harp",
"113": "bell",
"114": "harp",
"115": "cow_bell",
"116": "basedrum",
"117": "bass",
"118": "bit",
"119": "basedrum",
"120": "guitar",
"121": "harp",
"122": "harp",
"123": "harp",
"124": "harp",
"125": "hat",
"126": "basedrum",
"127": "snare",
}

View File

@@ -0,0 +1,250 @@
zip_name = {
-1: "-1.Acoustic_Kit_打击乐.zip",
0: "0.Acoustic_Grand_Piano_大钢琴.zip",
1: "1.Bright_Acoustic_Piano_亮音大钢琴.zip",
10: "10.Music_Box_八音盒.zip",
100: "100.FX_brightness_合成特效-亮音.zip",
101: "101.FX_goblins_合成特效-小妖.zip",
102: "102.FX_echoes_合成特效-回声.zip",
103: "103.FX_sci-fi_合成特效-科幻.zip",
104: "104.Sitar_锡塔尔.zip",
105: "105.Banjo_班卓.zip",
106: "106.Shamisen_三味线.zip",
107: "107.Koto_筝.zip",
108: "108.Kalimba_卡林巴.zip",
109: "109.Bagpipe_风笛.zip",
11: "11.Vibraphone_电颤琴.zip",
110: "110.Fiddle_古提琴.zip",
111: "111.Shanai_唢呐.zip",
112: "112.Tinkle_Bell_铃铛.zip",
113: "113.Agogo_拉丁打铃.zip",
114: "114.Steel_Drums_钢鼓.zip",
115: "115.Woodblock_木块.zip",
116: "116.Taiko_Drum_太鼓.zip",
117: "117.Melodic_Tom_嗵鼓.zip",
118: "118.Synth_Drum_合成鼓.zip",
119: "119.Reverse_Cymbal_镲波形反转.zip",
12: "12.Marimba_马林巴.zip",
13: "13.Xylophone_木琴.zip",
14: "14.Tubular_Bells_管钟.zip",
15: "15.Dulcimer_扬琴.zip",
16: "16.Drawbar_Organ_击杆风琴.zip",
17: "17.Percussive_Organ_打击型风琴.zip",
18: "18.Rock_Organ_摇滚风琴.zip",
19: "19.Church_Organ_管风琴.zip",
2: "2.Electric_Grand_Piano_电子大钢琴.zip",
20: "20.Reed_Organ_簧风琴.zip",
21: "21.Accordion_手风琴.zip",
22: "22.Harmonica_口琴.zip",
23: "23.Tango_Accordian_探戈手风琴.zip",
24: "24.Acoustic_Guitar_(nylon)_尼龙弦吉他.zip",
25: "25.Acoustic_Guitar(steel)_钢弦吉他.zip",
26: "26.Electric_Guitar_(jazz)_爵士乐电吉他.zip",
27: "27.Electric_Guitar_(clean)_清音电吉他.zip",
28: "28.Electric_Guitar_(muted)_弱音电吉他.zip",
29: "29.Overdriven_Guitar_驱动音效吉他.zip",
3: "3.Honky-Tonk_Piano_酒吧钢琴.zip",
30: "30.Distortion_Guitar_失真音效吉他.zip",
31: "31.Guitar_Harmonics_吉他泛音.zip",
32: "32.Acoustic_Bass_原声贝司.zip",
33: "33.Electric_Bass(finger)_指拨电贝司.zip",
34: "34.Electric_Bass(pick)_拨片拨电贝司.zip",
35: "35.Fretless_Bass_无品贝司.zip",
36: "36.Slap_Bass_A_击弦贝司A.zip",
37: "37.Slap_Bass_B_击弦贝司B.zip",
38: "38.Synth_Bass_A_合成贝司A.zip",
39: "39.Synth_Bass_B_合成贝司B.zip",
4: "4.Electric_Piano_1_电钢琴A.zip",
40: "40.Violin_小提琴.zip",
41: "41.Viola_中提琴.zip",
42: "42.Cello_大提琴.zip",
43: "43.Contrabass_低音提琴.zip",
44: "44.Tremolo_Strings_弦乐震音.zip",
45: "45.Pizzicato_Strings_弦乐拨奏.zip",
46: "46.Orchestral_Harp_竖琴.zip",
47: "47.Timpani_定音鼓.zip",
48: "48.String_Ensemble_A_弦乐合奏A.zip",
49: "49.String_Ensemble_B_弦乐合奏B.zip",
5: "5.Electric_Piano_2_电钢琴B.zip",
50: "50.SynthStrings_A_合成弦乐A.zip",
51: "51.SynthStrings_B_合成弦乐B.zip",
52: "52.Choir_Aahs_合唱“啊”音.zip",
53: "53.Voice_Oohs_人声“哦”音.zip",
54: "54.Synth_Voice_合成人声.zip",
55: "55.Orchestra_Hit_乐队打击乐.zip",
56: "56.Trumpet_小号.zip",
57: "57.Trombone_长号.zip",
58: "58.Tuba_大号.zip",
59: "59.Muted_Trumpet_弱音小号.zip",
6: "6.Harpsichord_拨弦古钢琴.zip",
60: "60.French_Horn_圆号.zip",
61: "61.Brass_Section_铜管组.zip",
62: "62.Synth_Brass_A_合成铜管A.zip",
63: "63.Synth_Brass_A_合成铜管B.zip",
64: "64.Soprano_Sax_高音萨克斯.zip",
65: "65.Alto_Sax_中音萨克斯.zip",
66: "66.Tenor_Sax_次中音萨克斯.zip",
67: "67.Baritone_Sax_上低音萨克斯.zip",
68: "68.Oboe_双簧管.zip",
69: "69.English_Horn_英国管.zip",
7: "7.Clavinet_击弦古钢琴.zip",
70: "70.Bassoon_大管.zip",
71: "71.Clarinet_单簧管.zip",
72: "72.Piccolo_短笛.zip",
73: "73.Flute_长笛.zip",
74: "74.Recorder_竖笛.zip",
75: "75.Pan_Flute_排笛.zip",
76: "76.Bottle_Blow_吹瓶口.zip",
77: "77.Skakuhachi_尺八.zip",
78: "78.Whistle_哨.zip",
79: "79.Ocarina_洋埙.zip",
8: "8.Celesta_钢片琴.zip",
80: "80.Lead_square_合成主音-方波.zip",
81: "81.Lead_sawtooth_合成主音-锯齿波.zip",
82: "82.Lead_calliope_lead_合成主音-汽笛风琴.zip",
83: "83.Lead_chiff_lead_合成主音-吹管.zip",
84: "84.Lead_charang_合成主音5-吉他.zip",
85: "85.Lead_voice_合成主音-人声.zip",
86: "86.Lead_fifths_合成主音-五度.zip",
87: "87.Lead_bass+lead_合成主音-低音加主音.zip",
88: "88.Pad_new_age_合成柔音-新时代.zip",
89: "89.Pad_warm_合成柔音-暖音.zip",
9: "9.Glockenspiel_钟琴.zip",
90: "90.Pad_polysynth_合成柔音-复合成.zip",
91: "91.Pad_choir_合成柔音-合唱.zip",
92: "92.Pad_bowed_合成柔音-弓弦.zip",
93: "93.Pad_metallic_合成柔音-金属.zip",
94: "94.Pad_halo_合成柔音-光环.zip",
95: "95.Pad_sweep_合成柔音-扫弦.zip",
96: "96.FX_rain_合成特效-雨.zip",
97: "97.FX_soundtrack_合成特效-音轨.zip",
98: "98.FX_crystal_合成特效-水晶.zip",
99: "99.FX_atmosphere_合成特效-大气.zip",
}
mcpack_name = {
-1: "-1.Acoustic_Kit_打击乐.mcpack",
0: "0.Acoustic_Grand_Piano_大钢琴.mcpack",
1: "1.Bright_Acoustic_Piano_亮音大钢琴.mcpack",
10: "10.Music_Box_八音盒.mcpack",
100: "100.FX_brightness_合成特效-亮音.mcpack",
101: "101.FX_goblins_合成特效-小妖.mcpack",
102: "102.FX_echoes_合成特效-回声.mcpack",
103: "103.FX_sci-fi_合成特效-科幻.mcpack",
104: "104.Sitar_锡塔尔.mcpack",
105: "105.Banjo_班卓.mcpack",
106: "106.Shamisen_三味线.mcpack",
107: "107.Koto_筝.mcpack",
108: "108.Kalimba_卡林巴.mcpack",
109: "109.Bagpipe_风笛.mcpack",
11: "11.Vibraphone_电颤琴.mcpack",
110: "110.Fiddle_古提琴.mcpack",
111: "111.Shanai_唢呐.mcpack",
112: "112.Tinkle_Bell_铃铛.mcpack",
113: "113.Agogo_拉丁打铃.mcpack",
114: "114.Steel_Drums_钢鼓.mcpack",
115: "115.Woodblock_木块.mcpack",
116: "116.Taiko_Drum_太鼓.mcpack",
117: "117.Melodic_Tom_嗵鼓.mcpack",
118: "118.Synth_Drum_合成鼓.mcpack",
119: "119.Reverse_Cymbal_镲波形反转.mcpack",
12: "12.Marimba_马林巴.mcpack",
13: "13.Xylophone_木琴.mcpack",
14: "14.Tubular_Bells_管钟.mcpack",
15: "15.Dulcimer_扬琴.mcpack",
16: "16.Drawbar_Organ_击杆风琴.mcpack",
17: "17.Percussive_Organ_打击型风琴.mcpack",
18: "18.Rock_Organ_摇滚风琴.mcpack",
19: "19.Church_Organ_管风琴.mcpack",
2: "2.Electric_Grand_Piano_电子大钢琴.mcpack",
20: "20.Reed_Organ_簧风琴.mcpack",
21: "21.Accordion_手风琴.mcpack",
22: "22.Harmonica_口琴.mcpack",
23: "23.Tango_Accordian_探戈手风琴.mcpack",
24: "24.Acoustic_Guitar_(nylon)_尼龙弦吉他.mcpack",
25: "25.Acoustic_Guitar(steel)_钢弦吉他.mcpack",
26: "26.Electric_Guitar_(jazz)_爵士乐电吉他.mcpack",
27: "27.Electric_Guitar_(clean)_清音电吉他.mcpack",
28: "28.Electric_Guitar_(muted)_弱音电吉他.mcpack",
29: "29.Overdriven_Guitar_驱动音效吉他.mcpack",
3: "3.Honky-Tonk_Piano_酒吧钢琴.mcpack",
30: "30.Distortion_Guitar_失真音效吉他.mcpack",
31: "31.Guitar_Harmonics_吉他泛音.mcpack",
32: "32.Acoustic_Bass_原声贝司.mcpack",
33: "33.Electric_Bass(finger)_指拨电贝司.mcpack",
34: "34.Electric_Bass(pick)_拨片拨电贝司.mcpack",
35: "35.Fretless_Bass_无品贝司.mcpack",
36: "36.Slap_Bass_A_击弦贝司A.mcpack",
37: "37.Slap_Bass_B_击弦贝司B.mcpack",
38: "38.Synth_Bass_A_合成贝司A.mcpack",
39: "39.Synth_Bass_B_合成贝司B.mcpack",
4: "4.Electric_Piano_1_电钢琴A.mcpack",
40: "40.Violin_小提琴.mcpack",
41: "41.Viola_中提琴.mcpack",
42: "42.Cello_大提琴.mcpack",
43: "43.Contrabass_低音提琴.mcpack",
44: "44.Tremolo_Strings_弦乐震音.mcpack",
45: "45.Pizzicato_Strings_弦乐拨奏.mcpack",
46: "46.Orchestral_Harp_竖琴.mcpack",
47: "47.Timpani_定音鼓.mcpack",
48: "48.String_Ensemble_A_弦乐合奏A.mcpack",
49: "49.String_Ensemble_B_弦乐合奏B.mcpack",
5: "5.Electric_Piano_2_电钢琴B.mcpack",
50: "50.SynthStrings_A_合成弦乐A.mcpack",
51: "51.SynthStrings_B_合成弦乐B.mcpack",
52: "52.Choir_Aahs_合唱“啊”音.mcpack",
53: "53.Voice_Oohs_人声“哦”音.mcpack",
54: "54.Synth_Voice_合成人声.mcpack",
55: "55.Orchestra_Hit_乐队打击乐.mcpack",
56: "56.Trumpet_小号.mcpack",
57: "57.Trombone_长号.mcpack",
58: "58.Tuba_大号.mcpack",
59: "59.Muted_Trumpet_弱音小号.mcpack",
6: "6.Harpsichord_拨弦古钢琴.mcpack",
60: "60.French_Horn_圆号.mcpack",
61: "61.Brass_Section_铜管组.mcpack",
62: "62.Synth_Brass_A_合成铜管A.mcpack",
63: "63.Synth_Brass_A_合成铜管B.mcpack",
64: "64.Soprano_Sax_高音萨克斯.mcpack",
65: "65.Alto_Sax_中音萨克斯.mcpack",
66: "66.Tenor_Sax_次中音萨克斯.mcpack",
67: "67.Baritone_Sax_上低音萨克斯.mcpack",
68: "68.Oboe_双簧管.mcpack",
69: "69.English_Horn_英国管.mcpack",
7: "7.Clavinet_击弦古钢琴.mcpack",
70: "70.Bassoon_大管.mcpack",
71: "71.Clarinet_单簧管.mcpack",
72: "72.Piccolo_短笛.mcpack",
73: "73.Flute_长笛.mcpack",
74: "74.Recorder_竖笛.mcpack",
75: "75.Pan_Flute_排笛.mcpack",
76: "76.Bottle_Blow_吹瓶口.mcpack",
77: "77.Skakuhachi_尺八.mcpack",
78: "78.Whistle_哨.mcpack",
79: "79.Ocarina_洋埙.mcpack",
8: "8.Celesta_钢片琴.mcpack",
80: "80.Lead_square_合成主音-方波.mcpack",
81: "81.Lead_sawtooth_合成主音-锯齿波.mcpack",
82: "82.Lead_calliope_lead_合成主音-汽笛风琴.mcpack",
83: "83.Lead_chiff_lead_合成主音-吹管.mcpack",
84: "84.Lead_charang_合成主音5-吉他.mcpack",
85: "85.Lead_voice_合成主音-人声.mcpack",
86: "86.Lead_fifths_合成主音-五度.mcpack",
87: "87.Lead_bass+lead_合成主音-低音加主音.mcpack",
88: "88.Pad_new_age_合成柔音-新时代.mcpack",
89: "89.Pad_warm_合成柔音-暖音.mcpack",
9: "9.Glockenspiel_钟琴.mcpack",
90: "90.Pad_polysynth_合成柔音-复合成.mcpack",
91: "91.Pad_choir_合成柔音-合唱.mcpack",
92: "92.Pad_bowed_合成柔音-弓弦.mcpack",
93: "93.Pad_metallic_合成柔音-金属.mcpack",
94: "94.Pad_halo_合成柔音-光环.mcpack",
95: "95.Pad_sweep_合成柔音-扫弦.mcpack",
96: "96.FX_rain_合成特效-雨.mcpack",
97: "97.FX_soundtrack_合成特效-音轨.mcpack",
98: "98.FX_crystal_合成特效-水晶.mcpack",
99: "99.FX_atmosphere_合成特效-大气.mcpack",
}
if __name__ == "__main__":
print(zip_name[0])

View File

@@ -0,0 +1,134 @@
pitch = {
"0": "0.0220970869120796",
"1": "0.0234110480761981",
"2": "0.0248031414370031",
"3": "0.0262780129766786",
"4": "0.0278405849418856",
"5": "0.0294960722713029",
"6": "0.03125",
"7": "0.033108221698728",
"8": "0.0350769390096679",
"9": "0.037162722343835",
"10": "0.0393725328092148",
"11": "0.0417137454428136",
"12": "0.0441941738241592",
"13": "0.0468220961523963",
"14": "0.0496062828740062",
"15": "0.0525560259533572",
"16": "0.0556811698837712",
"17": "0.0589921445426059",
"18": "0.0625",
"19": "0.066216443397456",
"20": "0.0701538780193358",
"21": "0.0743254446876701",
"22": "0.0787450656184296",
"23": "0.0834274908856271",
"24": "0.0883883476483184",
"25": "0.0936441923047926",
"26": "0.0992125657480125",
"27": "0.105112051906714",
"28": "0.111362339767542",
"29": "0.117984289085212",
"30": "0.125",
"31": "0.132432886794912",
"32": "0.140307756038672",
"33": "0.14865088937534",
"34": "0.157490131236859",
"35": "0.166854981771254",
"36": "0.176776695296637",
"37": "0.187288384609585",
"38": "0.198425131496025",
"39": "0.210224103813429",
"40": "0.222724679535085",
"41": "0.235968578170423",
"42": "0.25",
"43": "0.264865773589824",
"44": "0.280615512077343",
"45": "0.29730177875068",
"46": "0.314980262473718",
"47": "0.333709963542509",
"48": "0.353553390593274",
"49": "0.37457676921917",
"50": "0.39685026299205",
"51": "0.420448207626857",
"52": "0.44544935907017",
"53": "0.471937156340847",
"54": "0.5",
"55": "0.529731547179648",
"56": "0.561231024154687",
"57": "0.594603557501361",
"58": "0.629960524947437",
"59": "0.667419927085017",
"60": "0.707106781186548",
"61": "0.749153538438341",
"62": "0.7937005259841",
"63": "0.840896415253715",
"64": "0.890898718140339",
"65": "0.943874312681694",
"66": "1",
"67": "1.0594630943593",
"68": "1.12246204830937",
"69": "1.18920711500272",
"70": "1.25992104989487",
"71": "1.33483985417003",
"72": "1.4142135623731",
"73": "1.49830707687668",
"74": "1.5874010519682",
"75": "1.68179283050743",
"76": "1.78179743628068",
"77": "1.88774862536339",
"78": "2",
"79": "2.11892618871859",
"80": "2.24492409661875",
"81": "2.37841423000544",
"82": "2.51984209978975",
"83": "2.66967970834007",
"84": "2.82842712474619",
"85": "2.99661415375336",
"86": "3.1748021039364",
"87": "3.36358566101486",
"88": "3.56359487256136",
"89": "3.77549725072677",
"90": "4",
"91": "4.23785237743718",
"92": "4.48984819323749",
"93": "4.75682846001088",
"94": "5.03968419957949",
"95": "5.33935941668014",
"96": "5.65685424949238",
"97": "5.99322830750673",
"98": "6.3496042078728",
"99": "6.72717132202972",
"100": "7.12718974512272",
"101": "7.55099450145355",
"102": "8",
"103": "8.47570475487436",
"104": "8.97969638647498",
"105": "9.51365692002177",
"106": "10.079368399159",
"107": "10.6787188333603",
"108": "11.3137084989848",
"109": "11.9864566150135",
"110": "12.6992084157456",
"111": "13.4543426440594",
"112": "14.2543794902454",
"113": "15.1019890029071",
"114": "16",
"115": "16.9514095097487",
"116": "17.95939277295",
"117": "19.0273138400435",
"118": "20.158736798318",
"119": "21.3574376667206",
"120": "22.6274169979695",
"121": "23.9729132300269",
"122": "25.3984168314912",
"123": "26.9086852881189",
"124": "28.5087589804909",
"125": "30.2039780058142",
"126": "32",
"127": "33.9028190194974",
"128": "35.9187855458999",
"129": "38.0546276800871",
"130": "40.3174735966359",
"131": "42.7148753334411",
}

View File

@@ -0,0 +1,208 @@
# -*- coding: utf-8 -*-
# from nmcsup.log import log
import pickle
class Note:
def __init__(self, channel, pitch, velocity, time, time_position, instrument):
self.channel = channel
self.pitch = pitch
self.velocity = velocity
self.delay = time
self.time_position = time_position
self.instrument = instrument
self.CD = "d"
def get_CD(self, start, end):
if end - start > 1.00:
self.CD = "c"
else:
self.CD = "d"
def midiNewReader(midfile: str):
import mido
# from msctspt.threadOpera import NewThread
from bgArrayLib.bpm import get
def Time(mt, tpb_a, bpm_a):
return round(mt / tpb_a / bpm_a * 60 * 20)
Notes = []
tracks = []
note_list = []
close = []
on = []
off = []
instruments = []
isPercussion = False
try:
mid = mido.MidiFile(midfile)
except Exception:
print("找不到文件或无法读取文件" + midfile)
return False
tpb = mid.ticks_per_beat
bpm = get(mid)
# 解析
# def loadMidi(track1):
for track in mid.tracks:
overallTime = 0.0
instrument = 0
for i in track:
overallTime += i.time
try:
if i.channel != 9:
# try:
# log("event_type(事件): " + str(i.type) + " channel(音轨): " + str(i.channel) +
# " note/pitch(音高): " +
# str(i[2]) +
# " velocity(力度): " + str(i.velocity) + " time(间隔时间): " + str(i.time) +
# " overallTime/globalTime/timePosition: " + str(overallTime) + " \n")
# except AttributeError:
# log("event_type(事件): " + str(i.type) + " thing(内容)" + str(i) + " \n")
if "program_change" in str(i):
instrument = i.program
if instrument > 119: # 音色不够
pass
else:
instruments.append(i.program)
if "note_on" in str(i) and i.velocity > 0:
print(i)
# print(i.note)
# print([Note(i.channel, i.note, i.velocity, i.time, Time(overallTime, tpb, bpm), instrument)])
tracks.append(
[
Note(
i.channel,
i.note,
i.velocity,
i.time,
Time(overallTime, tpb, bpm),
instrument,
)
]
)
note_list.append(
[
i.channel,
i.note,
i.velocity,
i.time,
Time(overallTime, tpb, bpm),
instrument,
]
)
on.append([i.note, Time(overallTime, tpb, bpm)])
# return [Note(i.channel, i, i.velocity, i.time, Time(overallTime, tpb, bpm))]
if "note_off" in str(i) or "note_on" in str(i) and i.velocity == 0:
# print(i)
# print([Note(i.channel, i.note, i.velocity, i.time, Time(overallTime, tpb, bpm))])
close.append(
[
Note(
i.channel,
i.note,
i.velocity,
i.time,
Time(overallTime, tpb, bpm),
instrument,
)
]
)
off.append([i.note, Time(overallTime, tpb, bpm)])
# return [Note(i.channel, i, i.velocity, i.time, Time(overallTime, tpb, bpm))]
except AttributeError:
pass
if "note_on" in str(i) and i.channel == 9:
if "note_on" in str(i) and i.velocity > 0:
print(i)
# print(i.note)
# print([Note(i.channel, i.note, i.velocity, i.time, Time(overallTime, tpb, bpm), -1)])
tracks.append(
[
Note(
i.channel,
i.note,
i.velocity,
i.time,
Time(overallTime, tpb, bpm),
-1,
)
]
)
note_list.append(
[
i.channel,
i.note,
i.velocity,
i.time,
Time(overallTime, tpb, bpm),
-1,
]
)
on.append([i.note, Time(overallTime, tpb, bpm)])
isPercussion = True
# return [Note(i.channel, i, i.velocity, i.time, Time(overallTime, tpb, bpm))]
Notes.append(tracks)
if instruments is []:
instruments.append(0)
instruments = list(set(instruments))
with open("1.pkl", "wb") as b:
pickle.dump([instruments, isPercussion], b)
# for j, track in enumerate(mid.tracks):
# th = NewThread(loadMidi, (track,))
# th.start()
# Notes.append(th.getResult())
# print(Notes)
print(Notes.__len__())
# print(note_list)
print(instruments)
return Notes
# return [Notes, note_list]
def midiClassReader(midfile: str):
import mido
from bgArrayLib.bpm import get
def Time(mt, tpb_a, bpm_a):
return round(mt / tpb_a / bpm_a * 60 * 20)
Notes = []
tracks = []
try:
mid = mido.MidiFile(filename=midfile, clip=True)
except Exception:
print("找不到文件或无法读取文件" + midfile)
return False
print("midi已经载入了。")
tpb = mid.ticks_per_beat
bpm = get(mid)
for track in mid.tracks:
overallTime = 0.0
instrument = 0
for i in track:
overallTime += i.time
if "note_on" in str(i) and i.velocity > 0:
print(i)
tracks.append(
[
Note(
i.channel,
i.note,
i.velocity,
i.time,
Time(overallTime, tpb, bpm),
instrument,
)
]
)
Notes.append(tracks)
print(Notes.__len__())
return Notes

View File

@@ -0,0 +1,147 @@
import os
import pickle
import shutil
# import tkinter.filedialog
# from namesConstant import zip_name
# from namesConstant import mcpack_name
import bgArrayLib.namesConstant
zipN = bgArrayLib.namesConstant.zip_name
mpN = bgArrayLib.namesConstant.mcpack_name
manifest = {
"format_version": 1,
"header": {
"name": "羽音缭绕-midiout_25.5--音创使用",
"description": "羽音缭绕-midiout_25.0--音创使用",
"uuid": "c1adbda4-3b3e-4e5b-a57e-cde8ac80ee19",
"version": [25, 5, 0],
},
"modules": [
{
"description": "羽音缭绕-midiout_25.0--音创使用",
"type": "resources",
"uuid": "c13455d5-b9f3-47f2-9706-c05ad86b3180 ",
"version": [25, 5, 0],
}
],
}
def resources_pathSetting(newPath: str = ""):
if not os.path.isfile("./bgArrayLib/resourcesPath.rpposi") and newPath == "":
return [False, 1] # 1:没有路径文件
elif newPath != "": # not os.path.isfile("./bgArrayLib/resourcesPath.rpposi") and
path = newPath
print(path)
with open("./bgArrayLib/resourcesPath.rpposi", "w") as w:
w.write(path)
if "mcpack(国际版推荐)格式_25.0" in os.listdir(
path
) and "zip格式_25.0" in os.listdir(path):
return [True, path, 1] # 1:都有
elif "mcpack(国际版推荐)格式_25.0" in os.listdir(
path
) and "zip格式_25.0" not in os.listdir(path):
return [True, path, 2] # 2:有pack
elif "mcpack(国际版推荐)格式_25.0" not in os.listdir(
path
) and "zip格式_25.0" in os.listdir(path):
return [True, path, 3] # 3:有zip
else:
return [False, 2] # 2:路径文件指示错误
if os.path.isfile("./bgArrayLib/resourcesPath.rpposi") and newPath == "":
with open("./bgArrayLib/resourcesPath.rpposi", "r") as f:
path = f.read()
if "mcpack(国际版推荐)格式_25.0" in os.listdir(
path
) and "zip格式_25.0" in os.listdir(path):
return [True, path, 1] # 1:都有
elif "mcpack(国际版推荐)格式_25.0" in os.listdir(
path
) and "zip格式_25.0" not in os.listdir(path):
return [True, path, 2] # 2:有pack
elif "mcpack(国际版推荐)格式_25.0" not in os.listdir(
path
) and "zip格式_25.0" in os.listdir(path):
return [True, path, 3] # 3:有zip
else:
return [False, 2] # 2:路径文件指示错误
raise
def choose_resources():
global zipN
global mpN
back_list = []
try:
with open(r"1.pkl", "rb") as rb:
instrument = list(pickle.load(rb))
print(instrument)
except FileNotFoundError:
with open(r"./nmcsup/1.pkl", "rb") as rb:
instrument = list(pickle.load(rb))
print(instrument)
path = resources_pathSetting()
if path.__len__() == 2:
return path
else:
dataT = path[2]
pathT = path[1]
if dataT == 1:
if instrument[1] is True: # 是否存在打击乐器
index = zipN.get(-1, "")
percussion_instrument = str(pathT) + "\\zip格式_25.0\\" + index
# print(percussion_instrument)
back_list.append(percussion_instrument)
for i in instrument[0]:
ins_p = str(pathT) + "\\zip格式_25.0\\" + str(zipN.get(i))
# print(ins_p)
back_list.append(ins_p)
print(back_list)
return back_list
elif dataT == 2:
if instrument[1] is True:
index = mpN.get(-1, "")
percussion_instrument = (
str(pathT) + "\\mcpack(国际版推荐)格式_25.0\\" + index
)
# print(percussion_instrument)
back_list.append(percussion_instrument)
for i in instrument[0]:
ins_p = str(pathT) + "\\mcpack(国际版推荐)格式_25.0\\" + str(mpN.get(i))
# print(ins_p)
back_list.append(ins_p)
print(back_list)
return back_list
elif dataT == 3:
if instrument[1] is True:
index = zipN.get(-1, "")
percussion_instrument = str(pathT) + "\\zip格式_25.0\\" + index
# print(percussion_instrument)
back_list.append(percussion_instrument)
for i in instrument[0]:
ins_p = str(pathT) + "\\zip格式_25.0\\" + str(zipN.get(i))
# print(ins_p)
back_list.append(ins_p)
print(back_list)
return back_list
raise
def scatteredPack(path):
pack_list = choose_resources()
print(pack_list)
print(path)
# os.close("L:/0WorldMusicCreater-MFMS new edition")
# shutil.copy("L:\\shenyu\\音源的资源包\\羽音缭绕-midiout_25.0\\mcpack(国际版推荐)格式_25.0\\0.Acoustic_Grand_Piano_大钢琴.mcpack",
# "L:/0WorldMusicCreater-MFMS new edition")
for i in pack_list:
shutil.copy(i, path)
if __name__ == "__main__":
# print(resources_pathSetting(r"L:\shenyu\音源的资源包\羽音缭绕-midiout_25.0"))
choose_resources()