# Path: moonlight/score/elements/key_signature.py
# class _BaseAccidentals(object):
# class Accidentals(_BaseAccidentals):
# class KeySignature(_BaseAccidentals):
#   def __init__(self, clef, accidentals=None):
#   def _normalize_position(self, position):
#   def get_accidental_for_position(self, position):
#   def __init__(self, clef):
#   def put(self, position, accidental):
#   def _normalize_position(self, position):
#   def try_put(self, position, accidental):
#   def _can_put(self, position, accidental):
#   def get_next_accidental(self):
#   def get_type(self):
#   def __len__(self):
# def _key_sig_pitch_classes(note_name, ascending_fifths):
# _KEY_SIGNATURE_PITCH_CLASS_LIST = {
#     # The sharp key signature starts with F#, and each subsequent note ascends
#     # by a fifth.
#     Glyph.SHARP:
#         _key_sig_pitch_classes('F', ascending_fifths=True),
#     # The flat key signature starts with Bb, and each subsequent note descends
#     # by a fifth.
#     Glyph.FLAT:
#         _key_sig_pitch_classes('B', ascending_fifths=False),
# }
# _KEY_SIGNATURE_Y_POSITION_RANGES = {
#     (Glyph.CLEF_TREBLE, Glyph.SHARP): range(-1, 6),  # A#4 to G#5
#     (Glyph.CLEF_TREBLE, Glyph.FLAT): range(-3, 4),  # Fb4 to Eb5
#     (Glyph.CLEF_BASS, Glyph.SHARP): range(-3, 4),  # A#2 to G#3
#     (Glyph.CLEF_BASS, Glyph.FLAT): range(-5, 2),  # Fb2 to Eb3
# }


import copy
import enum
from protobuf import music_pb2
from moonlight.protobuf import musicscore_pb2
from moonlight.score.elements import key_signature as key_signature_module
        ACCIDENTAL_PITCH_SHIFT_[accidental])
    first_note_in_chord = None
    if glyph.HasField('stem'):
      # Try to get the timing from another note in the same chord.
      stem = ((glyph.stem.start.x, glyph.stem.start.y), (glyph.stem.end.x,
                                                         glyph.stem.end.y))
      if stem in self.chords:
        first_note_in_chord = self.chords[stem]
    else:
      stem = None

    if first_note_in_chord:
      start_time, end_time = (first_note_in_chord.start_time,
                              first_note_in_chord.end_time)
    else:
      # TODO(ringw): Check all note durations, not just the first seen in a
      # chord, and use the median detected duration.
      duration = _get_note_duration(glyph)
      start_time, end_time = self.time, self.time + duration
      self.time += duration
    note = music_pb2.NoteSequence.Note(
        pitch=pitch, start_time=start_time, end_time=end_time)
    if stem:
      self.chords[stem] = note
    return note

  def set_clef(self, clef):
    """Sets the clef, and resets the key signature if necessary."""
    if clef != self.clef:
      self._key_signature_state = _KeySignatureState.KEY_SIGNATURE

# Path: moonlight/score/elements/key_signature.py
# class _BaseAccidentals(object):
# class Accidentals(_BaseAccidentals):
# class KeySignature(_BaseAccidentals):
#   def __init__(self, clef, accidentals=None):
#   def _normalize_position(self, position):
#   def get_accidental_for_position(self, position):
#   def __init__(self, clef):
#   def put(self, position, accidental):
#   def _normalize_position(self, position):
#   def try_put(self, position, accidental):
#   def _can_put(self, position, accidental):
#   def get_next_accidental(self):
#   def get_type(self):
#   def __len__(self):
# def _key_sig_pitch_classes(note_name, ascending_fifths):
# _KEY_SIGNATURE_PITCH_CLASS_LIST = {
#     # The sharp key signature starts with F#, and each subsequent note ascends
#     # by a fifth.
#     Glyph.SHARP:
#         _key_sig_pitch_classes('F', ascending_fifths=True),
#     # The flat key signature starts with Bb, and each subsequent note descends
#     # by a fifth.
#     Glyph.FLAT:
#         _key_sig_pitch_classes('B', ascending_fifths=False),
# }
# _KEY_SIGNATURE_Y_POSITION_RANGES = {
#     (Glyph.CLEF_TREBLE, Glyph.SHARP): range(-1, 6),  # A#4 to G#5
#     (Glyph.CLEF_TREBLE, Glyph.FLAT): range(-3, 4),  # Fb4 to Eb5
#     (Glyph.CLEF_BASS, Glyph.SHARP): range(-3, 4),  # A#2 to G#3
#     (Glyph.CLEF_BASS, Glyph.FLAT): range(-5, 2),  # Fb2 to Eb3
# }


# Path: moonlight/score/state/measure.py
import copy
import enum
from protobuf import music_pb2
from moonlight.protobuf import musicscore_pb2
from moonlight.score.elements import key_signature as key_signature_module

        ACCIDENTAL_PITCH_SHIFT_[accidental])
    first_note_in_chord = None
    if glyph.HasField('stem'):
      # Try to get the timing from another note in the same chord.
      stem = ((glyph.stem.start.x, glyph.stem.start.y), (glyph.stem.end.x,
                                                         glyph.stem.end.y))
      if stem in self.chords:
        first_note_in_chord = self.chords[stem]
    else:
      stem = None

    if first_note_in_chord:
      start_time, end_time = (first_note_in_chord.start_time,
                              first_note_in_chord.end_time)
    else:
      # TODO(ringw): Check all note durations, not just the first seen in a
      # chord, and use the median detected duration.
      duration = _get_note_duration(glyph)
      start_time, end_time = self.time, self.time + duration
      self.time += duration
    note = music_pb2.NoteSequence.Note(
        pitch=pitch, start_time=start_time, end_time=end_time)
    if stem:
      self.chords[stem] = note
    return note

  def set_clef(self, clef):
    """Sets the clef, and resets the key signature if necessary."""
    if clef != self.clef:
      self._key_signature_state = _KeySignatureState.KEY_SIGNATURE

      self.key_signature = key_signature_module.KeySignature(clef)