class_docstr: Converts to/from multiple-instrument metric performances.
  
  Attributes:
    num_velocity_bins: Number of velocity bins.
    max_tensors_per_notesequence: The maximum number of outputs to return
        for each NoteSequence.
    hop_size_bars: How many bars each sequence should be.
    chunk_size_bars: Chunk size used for hierarchically decomposing sequence.
    steps_per_quarter: Number of time steps per quarter note.
    quarters_per_bar: Number of quarter notes per bar.
    min_num_instruments: Minimum number of instruments per sequence.
    max_num_instruments: Maximum number of instruments per sequence.
    min_total_events: Minimum total length of all performance tracks, in events.
    max_events_per_instrument: Maximum length of a single-instrument
        performance, in events.
    first_subsequence_only: If True, only use the very first hop and discard all
        sequences longer than the hop size.
    chord_encoding: An instantiated OneHotEncoding object to use for encoding
        chords on which to condition, or None if not conditioning on chords.
    drop_tracks_and_truncate: Randomly drop extra tracks and truncate the event
        sequence.
class_docstr_tok: ["Converts","to\/from","multiple-instrument","metric","performances",".","Attributes",":","num_velocity_bins",":","Number","of","velocity","bins",".","max_tensors_per_notesequence",":","The","maximum","number","of","outputs","to","return","for","each","NoteSequence",".","hop_size_bars",":","How","many","bars","each","sequence","should","be",".","chunk_size_bars",":","Chunk","size","used","for","hierarchically","decomposing","sequence",".","steps_per_quarter",":","Number","of","time","steps","per","quarter","note",".","quarters_per_bar",":","Number","of","quarter","notes","per","bar",".","min_num_instruments",":","Minimum","number","of","instruments","per","sequence",".","max_num_instruments",":","Maximum","number","of","instruments","per","sequence",".","min_total_events",":","Minimum","total","length","of","all","performance","tracks",",","in","events",".","max_events_per_instrument",":","Maximum","length","of","a","single-instrument","performance",",","in","events",".","first_subsequence_only",":","If","True",",","only","use","the","very","first","hop","and","discard","all","sequences","longer","than","the","hop","size",".","chord_encoding",":","An","instantiated","OneHotEncoding","object","to","use","for","encoding","chords","on","which","to","condition",",","or","None","if","not","conditioning","on","chords",".","drop_tracks_and_truncate",":","Randomly","drop","extra","tracks","and","truncate","the","event","sequence","."]
code: def _to_tensors_fn(self, note_sequence):
      # Performance sequences require sustain to be correctly interpreted.
      note_sequence = note_seq.apply_sustain_control_changes(
          note_sequence
      )
  
      if self._chord_encoding and not any(
          ta.annotation_type == CHORD_SYMBOL
          for ta in note_sequence.text_annotations
      ):
          try:
              # Quantize just for the purpose of chord inference.
              # TODO(iansimon): Allow chord inference in unquantized sequences.
              quantized_sequence = note_seq.quantize_note_sequence(
                  note_sequence, self._steps_per_quarter
              )
              if (
                  note_seq.steps_per_bar_in_quantized_sequence(
                      quantized_sequence
                  )
                  != self._steps_per_bar
              ):
                  return data.ConverterTensors()
  
              # Infer chords in quantized sequence.
              note_seq.infer_chords_for_sequence(quantized_sequence)
  
          except (
              note_seq.BadTimeSignatureError,
              note_seq.NonIntegerStepsPerBarError,
              note_seq.NegativeTimeError,
              note_seq.ChordInferenceError,
          ):
              return data.ConverterTensors()
  
          # Copy inferred chords back to original sequence.
          for qta in quantized_sequence.text_annotations:
              if qta.annotation_type == CHORD_SYMBOL:
                  ta = note_sequence.text_annotations.add()
                  ta.annotation_type = CHORD_SYMBOL
                  ta.time = qta.time
                  ta.text = qta.text
  
      if note_sequence.tempos:
          quarters_per_minute = note_sequence.tempos[0].qpm
      else:
          quarters_per_minute = note_seq.DEFAULT_QUARTERS_PER_MINUTE
      quarters_per_bar = self._steps_per_bar / self._steps_per_quarter
      hop_size_quarters = quarters_per_bar * self._hop_size_bars
      hop_size_seconds = 60.0 * hop_size_quarters / quarters_per_minute
  
      # Split note sequence by bar hop size (in seconds).
      subsequences = note_seq.split_note_sequence(
          note_sequence, hop_size_seconds
      )
  
      if self._first_subsequence_only and len(subsequences) > 1:
          return data.ConverterTensors()
  
      sequence_tensors = []
      sequence_chord_tensors = []
  
      for subsequence in subsequences:
          # Quantize this subsequence.
          try:
              quantized_subsequence = note_seq.quantize_note_sequence(
                  subsequence, self._steps_per_quarter
              )
              if (
                  note_seq.steps_per_bar_in_quantized_sequence(
                      quantized_subsequence
                  )
                  != self._steps_per_bar
              ):
                  return data.ConverterTensors()
          except (
              note_seq.BadTimeSignatureError,
              note_seq.NonIntegerStepsPerBarError,
              note_seq.NegativeTimeError,
          ):
              return data.ConverterTensors()
  
          # Convert the quantized subsequence to tensors.
          (
              tensors,
              chord_tensors,
          ) = self._quantized_subsequence_to_tensors(
              quantized_subsequence
          )
          if tensors:
              sequence_tensors.append(tensors)
              if self._chord_encoding:
                  sequence_chord_tensors.append(chord_tensors)
  
      tensors = data.ConverterTensors(
          inputs=sequence_tensors,
          outputs=sequence_tensors,
          controls=sequence_chord_tensors,
      )
      return hierarchical_pad_tensors(
          tensors,
          self.max_tensors_per_notesequence,
          self.is_training,
          self._max_lengths,
          self.end_token,
          self.input_depth,
          self.output_depth,
          self.control_depth,
          self._control_pad_token,
      )
  
imports: import abc
  import random
  from magenta.models.music_vae import data
  from magenta.pipelines import performance_pipeline
  import note_seq
  from note_seq import chords_lib
  from note_seq import performance_lib
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 3 for calling the MultiInstrumentPerformanceConverter obj's underlying member method code with example usage: obj._to_tensors_fn(note_sequence) and returns: hierarchical_pad_tensors, data, data, data, data, data