class_docstr: Encodes list/array format piece into pianorolls and decodes into midi.
docstr: Returns midi_instr as 2D (time, model pitch_range) pianoroll.
docstr_tok: ["Returns","midi_instr","as","2D","(","time",",","model","pitch_range",")","pianoroll","."]
code: 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
  
file_path: magenta/magenta/models/coconet/lib_pianoroll.py
imports: import numpy
  import pretty_midi
  import tensorflow.compat.v1
label_desc: Use image node_id 7 for calling the PianorollEncoderDecoder obj's underlying member method code with example usage: obj.get_instr_pianoroll(midi_instr, requested_shape) and returns: roll, pianoroll