# Path: note_seq/constants.py
# DEFAULT_QUARTERS_PER_MINUTE = 120.0
# DEFAULT_STEPS_PER_BAR = 16  # 4/4 music sampled at 4 steps per quarter note.
# DEFAULT_STEPS_PER_QUARTER = 4
# DEFAULT_STEPS_PER_SECOND = 100
# STANDARD_PPQ = 220
# NUM_SPECIAL_MELODY_EVENTS = 2
# MELODY_NOTE_OFF = -1
# MELODY_NO_EVENT = -2
# MIN_MELODY_EVENT = -2
# MAX_MELODY_EVENT = 127
# MIN_MIDI_PITCH = 0  # Inclusive.
# MAX_MIDI_PITCH = 127  # Inclusive.
# NUM_MIDI_PITCHES = MAX_MIDI_PITCH - MIN_MIDI_PITCH + 1
# NOTES_PER_OCTAVE = 12
# MIN_MIDI_VELOCITY = 1  # Inclusive.
# MAX_MIDI_VELOCITY = 127  # Inclusive.
# MIN_MIDI_PROGRAM = 0
# MAX_MIDI_PROGRAM = 127
# UNPITCHED_PROGRAMS = (
#     list(range(96, 104)) + list(range(112, 120)) + list(range(120, 128)))
# NO_CHORD = 'N.C.'
# MAJOR_SCALE = [0, 2, 4, 5, 7, 9, 11]
# NOTE_KEYS = [
#     [0, 1, 3, 5, 7, 8, 10],
#     [1, 2, 4, 6, 8, 9, 11],
#     [0, 2, 3, 5, 7, 9, 10],
#     [1, 3, 4, 6, 8, 10, 11],
#     [0, 2, 4, 5, 7, 9, 11],
#     [0, 1, 3, 5, 6, 8, 10],
#     [1, 2, 4, 6, 7, 9, 11],
#     [0, 2, 3, 5, 7, 8, 10],
#     [1, 3, 4, 6, 8, 9, 11],
#     [0, 2, 4, 5, 7, 9, 10],
#     [1, 3, 5, 6, 8, 10, 11],
#     [0, 2, 4, 6, 7, 9, 11]
# ]


import collections
import io
import sys
import pretty_midi
from note_seq import constants
from note_seq.protobuf import music_pb2
  relative values (MIDI ticks). When the NoteSequence is translated back to
  PrettyMIDI the absolute time is retained. The tempo map is also recreated.

  Args:
    sequence: A NoteSequence.
    drop_events_n_seconds_after_last_note: Events (e.g., time signature changes)
        that occur this many seconds after the last note will be dropped. If
        None, then no events will be dropped.

  Returns:
    A pretty_midi.PrettyMIDI object or None if sequence could not be decoded.
  """
  ticks_per_quarter = sequence.ticks_per_quarter or constants.STANDARD_PPQ

  max_event_time = None
  if drop_events_n_seconds_after_last_note is not None:
    max_event_time = (max([n.end_time for n in sequence.notes] or [0]) +
                      drop_events_n_seconds_after_last_note)

  # Try to find a tempo at time zero. The list is not guaranteed to be in order.
  initial_seq_tempo = None
  for seq_tempo in sequence.tempos:
    if seq_tempo.time == 0:
      initial_seq_tempo = seq_tempo
      break

  kwargs = {}
  if initial_seq_tempo:
    kwargs['initial_tempo'] = initial_seq_tempo.qpm
  else:

# Path: note_seq/constants.py
# DEFAULT_QUARTERS_PER_MINUTE = 120.0
# DEFAULT_STEPS_PER_BAR = 16  # 4/4 music sampled at 4 steps per quarter note.
# DEFAULT_STEPS_PER_QUARTER = 4
# DEFAULT_STEPS_PER_SECOND = 100
# STANDARD_PPQ = 220
# NUM_SPECIAL_MELODY_EVENTS = 2
# MELODY_NOTE_OFF = -1
# MELODY_NO_EVENT = -2
# MIN_MELODY_EVENT = -2
# MAX_MELODY_EVENT = 127
# MIN_MIDI_PITCH = 0  # Inclusive.
# MAX_MIDI_PITCH = 127  # Inclusive.
# NUM_MIDI_PITCHES = MAX_MIDI_PITCH - MIN_MIDI_PITCH + 1
# NOTES_PER_OCTAVE = 12
# MIN_MIDI_VELOCITY = 1  # Inclusive.
# MAX_MIDI_VELOCITY = 127  # Inclusive.
# MIN_MIDI_PROGRAM = 0
# MAX_MIDI_PROGRAM = 127
# UNPITCHED_PROGRAMS = (
#     list(range(96, 104)) + list(range(112, 120)) + list(range(120, 128)))
# NO_CHORD = 'N.C.'
# MAJOR_SCALE = [0, 2, 4, 5, 7, 9, 11]
# NOTE_KEYS = [
#     [0, 1, 3, 5, 7, 8, 10],
#     [1, 2, 4, 6, 8, 9, 11],
#     [0, 2, 3, 5, 7, 9, 10],
#     [1, 3, 4, 6, 8, 10, 11],
#     [0, 2, 4, 5, 7, 9, 11],
#     [0, 1, 3, 5, 6, 8, 10],
#     [1, 2, 4, 6, 7, 9, 11],
#     [0, 2, 3, 5, 7, 8, 10],
#     [1, 3, 4, 6, 8, 9, 11],
#     [0, 2, 4, 5, 7, 9, 10],
#     [1, 3, 5, 6, 8, 10, 11],
#     [0, 2, 4, 6, 7, 9, 11]
# ]


# Path: note_seq/midi_io.py
import collections
import io
import sys
import pretty_midi
from note_seq import constants
from note_seq.protobuf import music_pb2

  relative values (MIDI ticks). When the NoteSequence is translated back to
  PrettyMIDI the absolute time is retained. The tempo map is also recreated.

  Args:
    sequence: A NoteSequence.
    drop_events_n_seconds_after_last_note: Events (e.g., time signature changes)
        that occur this many seconds after the last note will be dropped. If
        None, then no events will be dropped.

  Returns:
    A pretty_midi.PrettyMIDI object or None if sequence could not be decoded.
  """
  ticks_per_quarter = sequence.ticks_per_quarter or constants.STANDARD_PPQ

  max_event_time = None
  if drop_events_n_seconds_after_last_note is not None:
    max_event_time = (max([n.end_time for n in sequence.notes] or [0]) +
                      drop_events_n_seconds_after_last_note)

  # Try to find a tempo at time zero. The list is not guaranteed to be in order.
  initial_seq_tempo = None
  for seq_tempo in sequence.tempos:
    if seq_tempo.time == 0:
      initial_seq_tempo = seq_tempo
      break

  kwargs = {}
  if initial_seq_tempo:
    kwargs['initial_tempo'] = initial_seq_tempo.qpm
  else:

    kwargs['initial_tempo'] = constants.DEFAULT_QUARTERS_PER_MINUTE