class_docstr: Stores a polyphonic sequence as a stream of single-note events.
  
  Events are PolyphonicEvent tuples that encode event type and pitch.
class_docstr_tok: ["Stores","a","polyphonic","sequence","as","a","stream","of","single-note","events",".","Events","are","PolyphonicEvent","tuples","that","encode","event","type","and","pitch","."]
docstr: Populate self with events from the given quantized NoteSequence object.
  
  Sequences start with START.
  
  Within a step, new pitches are started with NEW_NOTE and existing
  pitches are continued with CONTINUED_NOTE. A step is ended with
  STEP_END. If an active pitch is not continued, it is considered to
  have ended.
  
  Sequences end with END.
  
  Args:
    quantized_sequence: A quantized NoteSequence instance.
    start_step: Start converting the sequence at this time step.
        Assumed to be the beginning of a bar.
  
  Returns:
    A list of events.
docstr_tok: ["Populate","self","with","events","from","the","given","quantized","NoteSequence","object",".","Sequences","start","with","START",".","Within","a","step",",","new","pitches","are","started","with","NEW_NOTE","and","existing","pitches","are","continued","with","CONTINUED_NOTE",".","A","step","is","ended","with","STEP_END",".","If","an","active","pitch","is","not","continued",",","it","is","considered","to","have","ended",".","Sequences","end","with","END",".","Args",":","quantized_sequence",":","A","quantized","NoteSequence","instance",".","start_step",":","Start","converting","the","sequence","at","this","time","step",".","Assumed","to","be","the","beginning","of","a","bar",".","Returns",":","A","list","of","events","."]
code: def _from_quantized_sequence(quantized_sequence, start_step=0):
      """Populate self with events from the given quantized NoteSequence object.
  
      Sequences start with START.
  
      Within a step, new pitches are started with NEW_NOTE and existing
      pitches are continued with CONTINUED_NOTE. A step is ended with
      STEP_END. If an active pitch is not continued, it is considered to
      have ended.
  
      Sequences end with END.
  
      Args:
        quantized_sequence: A quantized NoteSequence instance.
        start_step: Start converting the sequence at this time step.
            Assumed to be the beginning of a bar.
  
      Returns:
        A list of events.
      """
      pitch_start_steps = collections.defaultdict(list)
      pitch_end_steps = collections.defaultdict(list)
  
      for note in quantized_sequence.notes:
          if note.quantized_start_step < start_step:
              continue
          pitch_start_steps[note.quantized_start_step].append(
              note.pitch
          )
          pitch_end_steps[note.quantized_end_step].append(note.pitch)
  
      events = [
          PolyphonicEvent(event_type=PolyphonicEvent.START, pitch=None)
      ]
  
      # Use a list rather than a set because one pitch may be active multiple
      # times.
      active_pitches = []
      for step in range(
          start_step, quantized_sequence.total_quantized_steps
      ):
          step_events = []
  
          for pitch in pitch_end_steps[step]:
              active_pitches.remove(pitch)
  
          for pitch in active_pitches:
              step_events.append(
                  PolyphonicEvent(
                      event_type=PolyphonicEvent.CONTINUED_NOTE,
                      pitch=pitch,
                  )
              )
  
          for pitch in pitch_start_steps[step]:
              active_pitches.append(pitch)
              step_events.append(
                  PolyphonicEvent(
                      event_type=PolyphonicEvent.NEW_NOTE, pitch=pitch
                  )
              )
  
          events.extend(
              sorted(step_events, key=lambda e: e.pitch, reverse=True)
          )
          events.append(
              PolyphonicEvent(
                  event_type=PolyphonicEvent.STEP_END, pitch=None
              )
          )
      events.append(
          PolyphonicEvent(event_type=PolyphonicEvent.END, pitch=None)
      )
  
      return events
  
imports: from __future__ import division
  import collections
  import copy
  from magenta.pipelines import statistics
  from note_seq import constants
  from note_seq import events_lib
  from note_seq import sequences_lib
  from note_seq.protobuf import music_pb2
  from six.moves import range
  import tensorflow.compat.v1
label_desc: Use image node_id 16 for calling the PolyphonicSequence obj's underlying member method code with example usage: obj._from_quantized_sequence(quantized_sequence, start_step) and returns: events