class_docstr: Encodes list/array format piece into pianorolls and decodes into midi.
docstr: Encodes midi into pianorolls.
docstr_tok: ["Encodes","midi","into","pianorolls","."]
code: 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
  
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 5 for calling the PianorollEncoderDecoder obj's underlying member method code with example usage: obj.encode_midi_melody_to_pianoroll(midi) and returns: roll