def test_furthest_notehead_with_one_note(self): pitches = ["b'"] chord = Chordrest(Mm(1), self.staff, pitches, Beat(1, 4)) assert chord.furthest_notehead.pitch == Pitch("b'") pitches = ["f'''"] chord = Chordrest(Mm(1), self.staff, pitches, Beat(1, 4)) assert chord.furthest_notehead.pitch == Pitch("f'''") pitches = ["c,,,,"] chord = Chordrest(Mm(1), self.staff, pitches, Beat(1, 4)) assert chord.furthest_notehead.pitch == Pitch("c,,,,")
def test_pitch_init_common_case(self): pitch_string = "af,," test_pitch = Pitch(pitch_string) assert test_pitch.pitch == pitch_string assert test_pitch.letter == "a" assert test_pitch.accidental_type.value == -1 assert test_pitch.octave == 1
def __init__( self, pos_x: Unit, pitch: PitchDef, duration: BeatDef, parent: GraphicObject ): """ Args: pos_x (Unit): The x-axis position relative to `parent`. The y-axis position is calculated automatically based on `pitch` and contextual information in `self.staff`. pitch (Pitch or str): May be a `str` pitch representation. See `Pitch` for valid signatures. duration (Beat or init tuple): The logical duration of the notehead. This is used to determine the glyph style. parent (GraphicObject): Must either be a `Staff` or an object with an ancestor `Staff`. """ self._pitch = Pitch.from_def(pitch) self._duration = Beat.from_def(duration) # Use a temporary y-axis position before calculating it for real MusicText.__init__( self, (pos_x, ZERO), [self._glyphnames[self.duration.base_division]], parent, ) StaffObject.__init__(self, parent) self.y = self.staff.unit( self.staff_pos - map_between(self.staff, self.parent).y )
def test__hash__(self): self.assertEqual({Pitch("c"), Pitch("c"), Pitch("d")}, {Pitch("c"), Pitch("d")})
def test__ne__(self): assert Pitch("c") != "nonsense" assert Pitch("c") != Pitch("d") assert Pitch("c") != Pitch("c,") assert Pitch("c") != Pitch("cs")
def test__eq__(self): assert Pitch("c") == Pitch("c") assert Pitch("c,") == Pitch("c,") assert Pitch("cs,") == Pitch("cs,")
def test_staff_position_relative_to_middle_c_doesnt_give_negative_0(self): # Cosmetic regression where Pitch("cs'") might actually be -0.0 assert str(Pitch("cs'").staff_pos_from_middle_c) == "0"
def test_staff_position_relative_to_middle_c(self): assert Pitch("c'").staff_pos_from_middle_c == 0 assert Pitch("cs'").staff_pos_from_middle_c == 0 assert Pitch("d'").staff_pos_from_middle_c == -0.5 assert Pitch("d''").staff_pos_from_middle_c == -4 assert Pitch("cn,").staff_pos_from_middle_c == 7
def test_diatonic_degree_in_c(self): # Simple identity test - mostly to raise a flag if the API changes degrees = {"c": 1, "d": 2, "e": 3, "f": 4, "g": 5, "a": 6, "b": 7} for letter, number in degrees.items(): assert Pitch(letter).diatonic_degree_in_c == number
def test_pitch_class(self): assert Pitch("af").pitch_class == 8
def test_apostrophe_octave_marks(self): assert Pitch("af'").octave == 4
def test_comma_octave_marks(self): assert Pitch("af,").octave == 2
def test_no_octave_marks(self): assert Pitch("af").octave == 3
def test_pitch_init_no_letter_fails(self): with pytest.raises(InvalidPitchDescriptionError): Pitch("s,")
def test_lowest_notehead(self): pitches = ["c'", "b'", "c'''"] chord = Chordrest(Mm(1), self.staff, pitches, Beat(1, 4)) assert chord.lowest_notehead.pitch == Pitch("c'")