in gan/utils/midi_utils.py [0:0]
def save_pianoroll_as_midi(pianoroll,
programs=[0, 0, 0, 0],
is_drums=[False, False, False, False],
tempo=100, # in bpm
beat_resolution=4, # number of time steps
destination_path=None
):
pianoroll = pianoroll > 0
# Reshape batched pianoroll array to a single pianoroll array
pianoroll_ = pianoroll.reshape((-1, pianoroll.shape[2], pianoroll.shape[3]))
# Create the tracks
tracks = []
for idx in range(pianoroll_.shape[2]):
tracks.append(pypianoroll.Track(
pianoroll_[..., idx], programs[idx], is_drums[idx]))
multitrack = pypianoroll.Multitrack(
tracks=tracks, tempo=tempo, beat_resolution=beat_resolution)
multitrack.write(destination_path)
print('Midi saved to ', destination_path)
return destination_path