Example #1
0
 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)
         self._accidentals = key_signature_module.Accidentals(clef)
     self.clef = clef
Example #2
0
    def __init__(self, start_time, clef, key_signature=None):
        """Initializes a new measure.

    Args:
      start_time: The start time (in quarter notes) of the measure.
      clef: A `Clef`.
      key_signature: The previously detected key signature (optional). If
          present, do not detect a key signature in this measure. This should be
          taken from the previously measure on this staff if this is not the
          first measure. It should not be propagated from one staff to the next,
          because we expect the key signature to be repeated on each staff and
          we will re-detect it.
    """
        self.time = start_time
        self.clef = clef
        self.key_signature = (key_signature
                              or key_signature_module.KeySignature(clef))
        self._accidentals = key_signature_module.Accidentals(clef)
        self._key_signature_state = (_KeySignatureState.ACCIDENTALS
                                     if key_signature else
                                     _KeySignatureState.KEY_SIGNATURE)
        self.chords = {}