(quantized_sequence, start_step=0)
return events
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.
Populate self with events from the given quantized NoteSequence object.
Populate self with events from the given quantized NoteSequence object .
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
def _from_quantized_sequence ( quantized_sequence , start_step = 0 ) : 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