(self, midi)
return roll
Encodes midi into pianorolls.
Encodes midi into pianorolls.
Encodes midi into pianorolls .
def encode_midi_melody_to_pianoroll(self, midi):
    """Encodes midi into pianorolls."""
    if len(midi.instruments) != 1:
      raise ValueError('Only one melody/instrument allowed, %r given.' %
                       (len(midi.instruments)))
    unused_tempo_change_times, tempo_changes = midi.get_tempo_changes()
    assert len(tempo_changes) == 1
    fs = 4
    # Returns matrix of shape (128, time) with summed velocities.
    roll = midi.get_piano_roll(fs=fs)  # 16th notes
    roll = np.where(roll > 0, 1, 0)
    tf.logging.debug('Roll shape: %s', roll.shape)
    roll = roll.T
    tf.logging.debug('Roll argmax: %s', np.argmax(roll, 1))
    return roll
def encode_midi_melody_to_pianoroll ( self , midi ) : if len ( midi . instruments ) != 1 : raise ValueError ( 'Only one melody/instrument allowed, %r given.' % ( len ( midi . instruments ) ) ) unused_tempo_change_times , tempo_changes = midi . get_tempo_changes ( ) assert len ( tempo_changes ) == 1 fs = 4 # Returns matrix of shape (128, time) with summed velocities. roll = midi . get_piano_roll ( fs = fs ) # 16th notes roll = np . where ( roll > 0 , 1 , 0 ) tf . logging . debug ( 'Roll shape: %s' , roll . shape ) roll = roll . T tf . logging . debug ( 'Roll argmax: %s' , np . argmax ( roll , 1 ) ) return roll