(self, midi_instr, requested_shape)
return roll
Returns midi_instr as 2D (time, model pitch_range) pianoroll.
Returns midi_instr as 2D (time, model pitch_range) pianoroll.
Returns midi_instr as 2D ( time model pitch_range ) pianoroll .
def get_instr_pianoroll(self, midi_instr, requested_shape):
    """Returns midi_instr as 2D (time, model pitch_range) pianoroll."""
    pianoroll = np.zeros(requested_shape[1:-1])
    if not midi_instr.notes:
      return pianoroll
    midi = pretty_midi.PrettyMIDI()
    midi.instruments.append(midi_instr)
    # TODO(annahuang): Sampling frequency is dataset dependent.
    fs = 4
    # Returns matrix of shape (128, time) with summed velocities.
    roll = midi.get_piano_roll(fs=fs)
    roll = np.where(roll > 0, 1, 0)
    roll = roll.T
    out_of_range_pitch_count = (
        np.sum(roll[:, self.max_pitch + 1:]) + np.sum(roll[:, :self.min_pitch]))
    if out_of_range_pitch_count > 0:
      raise ValueError(
          '%d pitches out of the range (%d, %d) the model was trained on.' %
          (out_of_range_pitch_count.item(), self.min_pitch, self.max_pitch))
    roll = roll[:, self.min_pitch:self.max_pitch + 1]
    return roll
def get_instr_pianoroll ( self , midi_instr , requested_shape ) : pianoroll = np . zeros ( requested_shape [ 1 : - 1 ] ) if not midi_instr . notes : return pianoroll midi = pretty_midi . PrettyMIDI ( ) midi . instruments . append ( midi_instr ) # TODO(annahuang): Sampling frequency is dataset dependent. fs = 4 # Returns matrix of shape (128, time) with summed velocities. roll = midi . get_piano_roll ( fs = fs ) roll = np . where ( roll > 0 , 1 , 0 ) roll = roll . T out_of_range_pitch_count = ( np . sum ( roll [ : , self . max_pitch + 1 : ] ) + np . sum ( roll [ : , : self . min_pitch ] ) ) if out_of_range_pitch_count > 0 : raise ValueError ( '%d pitches out of the range (%d, %d) the model was trained on.' % ( out_of_range_pitch_count . item ( ) , self . min_pitch , self . max_pitch ) ) roll = roll [ : , self . min_pitch : self . max_pitch + 1 ] return roll