def demo_random_new(argv): mid = Song() track = mid.add_track() # header = MidiFile('AutumnL.mid') for i in range(1000): note = np.random.randint(60, 100) # key down track.append( Message( 'note_on', note=note, velocity=np.random.randint(30, 70), time=0 if np.random.rand() > 0.8 else np.random.randint( 100, 300), )) # key up track.append( Message( 'note_on', note=note, velocity=0, time=np.random.randint(100, 300), )) mid.save('new_song.mid')
def demo_copy(argv): mid = Song() track = mid.add_track() source = MidiFile('playground/AutumnL.mid') # only copy notes Song._copy(source, track, filter_f=lambda x: x.type == 'note_on') mid.save('playground/AutumnL_copy.mid')
from midiwrapper import Song from keras.models import load_model import numpy as np if __name__ == '__main__': m = load_model('./temp/gan2.h5') m.summary() bs, seq_len, note_dim, _ = m.output_shape code_dim = m.input_shape[-1] def code_generator(bs): Z = np.random.uniform(-1., 1., size=(bs, code_dim)) return Z mid = Song() track = mid.add_track() notes = m.predict(code_generator(1))[0, :, :, 0] mid._compose(track, notes, deltat=100, threshold=1.) mid.save_as('gan2.mid')
# testing if __name__ == '__main__': from mido import MidiFile midi = MidiFile('./datasets/e-comp/2002chan01.mid') encoder = AllInOneEncoder() code = encoder.encode(midi) msg = encoder.decode(code) print code.dtype print code.shape # print msg[-10:] from midiwrapper import Song s = Song() track = s.add_track() for msgi in msg: track.append(msgi) s.save_as("decode.mid") # import os # from tqdm import tqdm # dirpath = './datasets/e-comp/' # tmppath = './datasets/e-comp-allinone/' # encoder = AllInOneEncoder() # filelist = [] # for root, _, files in os.walk(dirpath): # for name in files: # filelist.append(os.path.join(root, name)) # for filename in tqdm(filelist): # midi = Song(filename)