27 lines
945 B
Python
27 lines
945 B
Python
GENERATED_BEAT_PATH = 'data/output/generated_bar.npz'
|
|
OUTPUT_PATH = 'data/output/generated_midi.mid'
|
|
OUTPUT_PATH_PIANOROLL = 'data/output/pianoroll.png'
|
|
|
|
import pypianoroll as roll
|
|
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
import os
|
|
|
|
instruments = np.load(GENERATED_BEAT_PATH)['arr_0'][0]
|
|
|
|
instruments = instruments.reshape(96,128)
|
|
instruments = instruments>instruments.min()*0.3
|
|
instruments = instruments*255
|
|
|
|
# zeros_up = np.zeros((instruments.shape[0],24))
|
|
# zeros_down = np.zeros((instruments.shape[0], 20))
|
|
# instruments_full = np.concatenate([zeros_up,instruments], axis=1)
|
|
# instruments_full = np.concatenate([instruments_full,zeros_down], axis=1)
|
|
|
|
i = roll.Track(instruments, program=0)
|
|
return_midi = roll.Multitrack(tracks=[i], tempo=120.0, downbeat=[0, 96, 192, 288], beat_resolution=24)
|
|
roll.write(return_midi, OUTPUT_PATH)
|
|
|
|
plt.imshow(instruments.T, cmap='gray')
|
|
plt.savefig(OUTPUT_PATH_PIANOROLL)
|