def write_song(piano_roll, filename):
""" Save the song on disk
Args:
piano_roll (np.array): a song object containing the tracks and melody
filename (str): the path were to save the song (don't add the file extension)
"""
note_played = piano_roll > 0.5
piano_roll_int = np.uint8(piano_roll*255)
b = piano_roll_int * (~note_played).astype(np.uint8) # Note silenced
g = np.zeros(piano_roll_int.shape, dtype=np.uint8) # Empty channel
r = piano_roll_int * note_played.astype(np.uint8) # Notes played
img = cv.merge((b, g, r))
# TODO: We could insert a first column indicating the piano keys (black/white key)
cv.imwrite(filename + '.png', img)
评论列表
文章目录