'Populate self with events from the given quantized NoteSequence object.
Within a step, new pitches are started with NOTE_ON and existing pitches are
ended with NOTE_OFF. TIME_SHIFT shifts the current step forward in time.
VELOCITY changes the current velocity value that will be applied to all
NOTE_ON events.
Args:
quantized_sequence: A quantized NoteSequence instance.
start_step: Start converting the sequence at this time step.
num_velocity_bins: Number of velocity bins to use. If 0, velocity events
will not be included at all.
Returns:
A list of events.'

@staticmethod
def _from_quantized_sequence(quantized_sequence, start_step=0, num_velocity_bins=0):

    notes = [note for note in quantized_sequence.notes if ((not note.is_drum) and (note.quantized_start_step >= start_step))]
    sorted_notes = sorted(notes, key=(lambda note: note.start_time))
    onsets = [(note.quantized_start_step, idx, False) for (idx, note) in enumerate(sorted_notes)]
    offsets = [(note.quantized_end_step, idx, True) for (idx, note) in enumerate(sorted_notes)]
    note_events = sorted((onsets + offsets))
    if num_velocity_bins:
        velocity_bin_size = int(math.ceil((((MAX_MIDI_VELOCITY - MIN_MIDI_VELOCITY) + 1) / num_velocity_bins)))
        velocity_to_bin = (lambda v: (((v - MIN_MIDI_VELOCITY) // velocity_bin_size) + 1))
    current_step = start_step
    current_velocity_bin = 0
    performance_events = []
    for (step, idx, is_offset) in note_events:
        if (step > current_step):
            while (step > (current_step + MAX_SHIFT_STEPS)):
                performance_events.append(PerformanceEvent(event_type=PerformanceEvent.TIME_SHIFT, event_value=MAX_SHIFT_STEPS))
                current_step += MAX_SHIFT_STEPS
            performance_events.append(PerformanceEvent(event_type=PerformanceEvent.TIME_SHIFT, event_value=int((step - current_step))))
            current_step = step
        if num_velocity_bins:
            velocity_bin = velocity_to_bin(sorted_notes[idx].velocity)
            if ((not is_offset) and (velocity_bin != current_velocity_bin)):
                current_velocity_bin = velocity_bin
                performance_events.append(PerformanceEvent(event_type=PerformanceEvent.VELOCITY, event_value=current_velocity_bin))
        event_type = (PerformanceEvent.NOTE_OFF if is_offset else PerformanceEvent.NOTE_ON)
        performance_events.append(PerformanceEvent(event_type=event_type, event_value=sorted_notes[idx].pitch))
    return performance_events
