Beispiel #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
 def testEFlatMajor_bassClef(self):
     sig = key_signature.KeySignature(clef.BassClef())
     self.assertTrue(sig.try_put(-2, musicscore_pb2.Glyph.FLAT))  # Bb
     self.assertTrue(sig.try_put(+1, musicscore_pb2.Glyph.FLAT))  # Eb
     self.assertTrue(sig.try_put(-3, musicscore_pb2.Glyph.FLAT))  # Ab
     self.assertEqual(sig.get_next_accidental(),
                      (0, musicscore_pb2.Glyph.FLAT))  # Db
 def testBMajor(self):
     sig = key_signature.KeySignature(clef.TrebleClef())
     self.assertTrue(sig.try_put(+4, musicscore_pb2.Glyph.SHARP))  # F#
     self.assertTrue(sig.try_put(+1, musicscore_pb2.Glyph.SHARP))  # C#
     self.assertTrue(sig.try_put(+5, musicscore_pb2.Glyph.SHARP))  # G#
     self.assertEqual(sig.get_next_accidental(),
                      (+2, musicscore_pb2.Glyph.SHARP))  # D#
 def testCFlatMajor_noMoreAccidentals(self):
     sig = key_signature.KeySignature(clef.TrebleClef())
     self.assertTrue(sig.try_put(0, musicscore_pb2.Glyph.FLAT))  # Bb
     self.assertNotEqual(sig.get_next_accidental(), (None, None))
     self.assertTrue(sig.try_put(+3, musicscore_pb2.Glyph.FLAT))  # Eb
     self.assertNotEqual(sig.get_next_accidental(), (None, None))
     self.assertTrue(sig.try_put(-1, musicscore_pb2.Glyph.FLAT))  # Ab
     self.assertNotEqual(sig.get_next_accidental(), (None, None))
     self.assertTrue(sig.try_put(+2, musicscore_pb2.Glyph.FLAT))  # Db
     self.assertNotEqual(sig.get_next_accidental(), (None, None))
     self.assertTrue(sig.try_put(-2, musicscore_pb2.Glyph.FLAT))  # Gb
     self.assertNotEqual(sig.get_next_accidental(), (None, None))
     self.assertTrue(sig.try_put(+1, musicscore_pb2.Glyph.FLAT))  # Cb
     self.assertNotEqual(sig.get_next_accidental(), (None, None))
     self.assertTrue(sig.try_put(-3, musicscore_pb2.Glyph.FLAT))  # Fb
     # Already at Cb major, no more accidentals to add.
     self.assertEqual(sig.get_next_accidental(), (None, None))
Beispiel #5
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 = {}
 def testGMajor_bassClef(self):
     sig = key_signature.KeySignature(clef.BassClef())
     self.assertTrue(sig.try_put(+2, musicscore_pb2.Glyph.SHARP))  # F#
     self.assertEqual(sig.get_next_accidental(),
                      (-1, musicscore_pb2.Glyph.SHARP))  # C#
 def testEmpty_noNextAccidental(self):
     self.assertEqual(
         key_signature.KeySignature(
             clef.TrebleClef()).get_next_accidental(), (None, None))