class_docstr: Convert between performance event indices and (filenames of) MIDI files.
class_docstr_tok: ["Convert","between","performance","event","indices","and","(","filenames","of",")","MIDI","files","."]
docstr: Transform a NoteSequence into a list of performance event indices.
  
  Args:
    ns: NoteSequence proto containing the performance to encode.
  
  Returns:
    ids: List of performance event indices.
code: def encode_note_sequence(self, ns):
      """Transform a NoteSequence into a list of performance event indices.
  
      Args:
        ns: NoteSequence proto containing the performance to encode.
  
      Returns:
        ids: List of performance event indices.
      """
      performance = note_seq.Performance(
          note_seq.quantize_note_sequence_absolute(
              ns, self._steps_per_second
          ),
          num_velocity_bins=self._num_velocity_bins,
      )
  
      event_ids = [
          self._encoding.encode_event(event) + self.num_reserved_ids
          for event in performance
      ]
  
      # Greedily encode performance event n-grams as new indices.
      ids = []
      j = 0
      while j < len(event_ids):
          ngram = ()
          for i in range(j, len(event_ids)):
              ngram += (event_ids[i],)
              if self._ngrams_trie.has_key(ngram):
                  best_ngram = ngram
              if not self._ngrams_trie.has_subtrie(ngram):
                  break
          ids.append(self._ngrams_trie[best_ngram])
          j += len(best_ngram)
  
      if self._add_eos:
          ids.append(text_encoder.EOS_ID)
  
      return ids
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import tempfile
  import note_seq
  from note_seq import performance_lib
  import pygtrie
  from tensor2tensor.data_generators import text_encoder
label_desc: Use image node_id 3 for calling the MidiPerformanceEncoder obj's underlying member method code with example usage: obj.encode_note_sequence(ns) and returns: ids