示例#1
0
 def testEFlatMajor(self):
     sig = key_signature.KeySignature(clef.TrebleClef())
     self.assertTrue(sig.try_put(0, musicscore_pb2.Glyph.FLAT))  # Bb
     self.assertTrue(sig.try_put(+3, musicscore_pb2.Glyph.FLAT))  # Eb
     self.assertTrue(sig.try_put(-1, musicscore_pb2.Glyph.FLAT))  # Ab
     self.assertEqual(sig.get_next_accidental(),
                      (+2, musicscore_pb2.Glyph.FLAT))  # Db
示例#2
0
 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#
示例#3
0
 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))
示例#4
0
 def testTrebleClef(self):
   self.assertEqual(clef.TrebleClef().y_position_to_midi(-8),
                    librosa.note_to_midi('A3'))
   self.assertEqual(clef.TrebleClef().y_position_to_midi(-6),
                    librosa.note_to_midi('C4'))
   self.assertEqual(clef.TrebleClef().y_position_to_midi(0),
                    librosa.note_to_midi('B4'))
   self.assertEqual(clef.TrebleClef().y_position_to_midi(1),
                    librosa.note_to_midi('C5'))
   self.assertEqual(clef.TrebleClef().y_position_to_midi(3),
                    librosa.note_to_midi('E5'))
   self.assertEqual(clef.TrebleClef().y_position_to_midi(4),
                    librosa.note_to_midi('F5'))
   self.assertEqual(clef.TrebleClef().y_position_to_midi(14),
                    librosa.note_to_midi('B6'))
示例#5
0
    def _read_clef(self, staff_state, glyph):
        """Reads a clef glyph.

    If the clef is at the expected y position, set the current clef.

    Args:
      staff_state: The state of the staff that the glyph is on.
      glyph: A glyph of type CLEF_TREBLE or CLEF_BASS.

    Raises:
      ValueError: If glyph is an unexpected type.
    """
        if glyph.type == musicscore_pb2.Glyph.CLEF_TREBLE:
            if glyph.y_position == TREBLE_CLEF_EXPECTED_Y:
                staff_state.set_clef(clef.TrebleClef())
        elif glyph.type == musicscore_pb2.Glyph.CLEF_BASS:
            if glyph.y_position == BASS_CLEF_EXPECTED_Y:
                staff_state.set_clef(clef.BassClef())
        else:
            raise ValueError('Unknown clef of type: ' +
                             musicscore_pb2.Glyph.Type.Name(glyph.type))
示例#6
0
 def __init__(self, start_time, clef=None):
     clef = clef or clef_module.TrebleClef()
     self.measure_state = measure.MeasureState(start_time, clef=clef)
示例#7
0
 def testEmpty_noNextAccidental(self):
     self.assertEqual(
         key_signature.KeySignature(
             clef.TrebleClef()).get_next_accidental(), (None, None))