#4TCsCGtjU|h7`771_Oo~wk)<<_8O)dplB@zkjL)A5L;Bs
znZiE#45y?hM+s*QPcvf~Ls3NyPZn1SV>U}s#pGX{#_|<4EDLyQSQi4#D$FS12J!?J
zf=#Yr31-mbob1EZ$5x~S^qbpcKJJs^Mj&r8axn5RaWJzmvM@3+@-gx-@=X4~t-$Cy
NS&&B?NZRrk0RY0~MacjF
diff --git a/bgArrayLib/instrumentConstant.py b/bgArrayLib/instrumentConstant.py
new file mode 100644
index 0000000..924b4e2
--- /dev/null
+++ b/bgArrayLib/instrumentConstant.py
@@ -0,0 +1,24 @@
+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'}
diff --git a/bgArrayLib/reader.py b/bgArrayLib/reader.py
index 514fbf6..094db70 100644
--- a/bgArrayLib/reader.py
+++ b/bgArrayLib/reader.py
@@ -1,148 +1,148 @@
-# -*- 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:
- log("找不到文件或无法读取文件" + 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:
- log("找不到文件或无法读取文件" + midfile)
- return False
- log("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
+# -*- 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:
+ log("找不到文件或无法读取文件" + 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:
+ log("找不到文件或无法读取文件" + midfile)
+ return False
+ log("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
diff --git a/languages/__pycache__/__init__.cpython-39.pyc b/languages/__pycache__/__init__.cpython-39.pyc
index 8dd1ba5d1f3cc9c817faaa140630d2ceb33662b6..8b056f036672c87b185c88c355bb77d4d24022a3 100644
GIT binary patch
delta 29
jcmdnOxPp;8k(ZZ?0SJOTzfR<~Vf32lVa8}Wv0D=WV=4zM
delta 41
vcmZ3%xP_5Bk(ZZ?0SM~1{FumX!x%Qv!;IG`#<#RMGr1@=u_U! ltfwywvX87e#!`v(JsKo){gC}KN?qJTuj
zD?>F*t&S_o)p}^WY&Nqfvj|qSb3oQ
zVX3!}KDW1&Sy`o_WDEP?@(