# get file name tmp = [] for _,_,f in os.walk(JSON_DIR): tmp = f files = [] for t in tmp: if'hard'in t: files.append(t)
#print(files)
# run werrors = [] jerrors = [] for name in files: print('starting -> '+name) # get notes in file try: withopen(JSON_DIR+name,'r') as f: datas = json.loads(f.read()) except: jerrors.append(name) print('get json error -> '+name) print('------------------') continue speed = datas['speed'] #print(speed) #print(list(datas))
notes = datas['notes'] #print(list(notes[0]))
sounds = [] for n in notes: try: try: t = n['_time'] except: t = 0 if n['sounds'] != None: for s in n['sounds']: sounds.append({'d':s['d'],'p':s['p'],'v':s['v'],'t':t}) except KeyError: #print('!') None #print(len(sounds)) #print(list(notes[0]['sounds'][0])) try: start = sounds[0]['t'] for s in sounds: s['t'] -= start except: None
# get bpm times = [] for s in sounds: #if s['p']<50: times.append(s['t']) #times = [s['t'] for s in sounds] if(len(times)<2): bpm = 60 else: dt = [] for i inrange(len(times))[1:]: r = times[i]-times[i-1] if r != 0: dt.append(r) gm = pd.Series(data=dt) bpm = 60/gm.mode()[0] while(bpm>200): bpm /= 2 while(bpm<60): bpm *= 2 bpm = round(bpm) #bpm = int(bpm) print('bpm -> '+str(bpm))
# write midi MyMIDI = MIDIFile(1) track = 0 time = 0 bias = float(bpm/60) # Add track name and tempo. MyMIDI.addTrackName(track,time,name+'_deemo') MyMIDI.addTempo(track,time,bpm)
for s in sounds: MyMIDI.addNote(0,0,s['p'],s['t']*bias,s['d']*bias,s['v']) # And write it to disk. try: binfile = open(RESULT_DIR + name.split('.')[0]+'.mid', 'wb') MyMIDI.writeFile(binfile) binfile.close() except: werrors.append(name) print('write file error -> '+name) #continue
# get file name tmp = [] for _,_,f in os.walk(MONO_DIR): tmp = f files = [] for t in tmp: if'.json'in t: files.append(t[:-5]) #print(files)
songs = [] for fi in files: withopen(MONO_DIR+fi+'.json', 'r', encoding='utf-8') as f: data = json.loads(f.read()) try: content = data['content'] content[0] + 1 except: continue
serror = [] for s in songs: # API os.system(RMD_DIR + 'bnk2wem\\bnkextr.exe ' + RESULT_DIR + s +'.bnk') # change dir for _,_,f in os.walk(RESULT_DIR + s): sname = f
for i inrange(len(sname)): try: name = s + '_%d'%i if i == 0: name = s shutil.move(RESULT_DIR + s + '\\' + sname[i], RESULT_DIR + name + '.wem') print(name + ' - done wem')
# delete old dir try: os.rmdir(RESULT_DIR + s) os.remove(RESULT_DIR + s + '.bnk') for i inrange(len(sname)): name = s + '_%d'%i if i == 0: name = s os.remove(RESULT_DIR + name + '.wem') except: serror.append(s + ' - dir') pass