class_docstr: Encodes list/array format piece into pianorolls and decodes into midi.
docstr: Encode 2d array or list of lists of midi note numbers into pianoroll.
docstr_tok: ["Encode","2d","array","or","list","of","lists","of","midi","note","numbers","into","pianoroll","."]
code: def encode_list_of_lists(self, sequence):
      """Encode 2d array or list of lists of midi note numbers into pianoroll."""
      # step_size larger than 1 means some notes will be skipped over.
      step_size = self.quantization_level / self.shortest_duration
      if not step_size.is_integer():
          raise ValueError(
              "quantization %r should be multiple of shortest_duration %r."
              % (self.quantization_level, self.shortest_duration)
          )
      step_size = int(step_size)
  
      if not (len(sequence) / step_size).is_integer():
          raise ValueError(
              "step_size %r should fully divide length of seq %r."
              % (step_size, len(sequence))
          )
      tt = int(len(sequence) / step_size)
      pp = self.max_pitch - self.min_pitch + 1
      if self.separate_instruments:
          roll = np.zeros((tt, pp, self.num_instruments))
      else:
          roll = np.zeros((tt, pp, 1))
      for raw_t, chord in enumerate(sequence):
          # Only takes time steps that are on the quantization grid.
          if raw_t % step_size != 0:
              continue
          t = int(raw_t / step_size)
          for i in range(self.num_instruments):
              if i > len(chord):
                  # Some instruments are silence in this time step.
                  if self.separate_instruments:
                      raise ValueError(
                          "If instruments are separated must have all encoded."
                      )
                  continue
              pitch = chord[i]
              # Silences are sometimes encoded as NaN when instruments are separated.
              if np.isnan(pitch):
                  continue
              if pitch > self.max_pitch or pitch < self.min_pitch:
                  raise PitchOutOfEncodeRangeError(
                      "%r is out of specified range [%r, %r]."
                      % (pitch, self.min_pitch, self.max_pitch)
                  )
              p = pitch - self.min_pitch
              if not float(p).is_integer():
                  raise ValueError(
                      "Non integer pitches not yet supported."
                  )
              p = int(p)
              if self.separate_instruments:
                  roll[t, p, i] = 1
              else:
                  roll[t, p, 0] = 0
      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 3 for calling the PianorollEncoderDecoder obj's underlying member method code with example usage: obj.encode_list_of_lists(sequence) and returns: roll