コード例 #1
0
 def test_invalid_direction_raises_value_error(self):
     with pytest.raises(ValueError):
         Flag(Beat(1, 8), 0, self.staff)
     with pytest.raises(ValueError):
         Flag(Beat(1, 8), 2, self.staff)
     with pytest.raises(ValueError):
         Flag(Beat(1, 8), -2, self.staff)
コード例 #2
0
 def test__hash__(self):
     assert {Beat(Beat(1, 2), 4),
             Beat(Beat(1, 2), 4),
             Beat(Beat(1, 2), 8)} == {
                 Beat(Beat(1, 2), 4),
                 Beat(Beat(1, 2), 8),
             }
コード例 #3
0
ファイル: test_chordrest.py プロジェクト: ajyoon/brown
 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,,,,")
コード例 #4
0
    def test_raises_no_flag_needed_error(self):
        # Test valid durations
        Flag(Beat(1, 16), 1, self.staff)
        Flag(Beat(1, 8), 1, self.staff)

        # Test invalid durations
        with pytest.raises(NoFlagNeededError):
            Flag(Beat(1, 4), 1, self.staff)
        with pytest.raises(NoFlagNeededError):
            Flag(Beat(1, 2), 1, self.staff)
        with pytest.raises(NoFlagNeededError):
            Flag(Beat(1, 1), 1, self.staff)
コード例 #5
0
    def test_vertical_offset_needed(self):
        self.assertEqual(
            Flag.vertical_offset_needed(Beat(1, 4), self.staff.unit),
            self.staff.unit(0))

        self.assertEqual(
            Flag.vertical_offset_needed(Beat(1, 8), self.staff.unit),
            self.staff.unit(1))

        self.assertEqual(
            Flag.vertical_offset_needed(Beat(1, 16), self.staff.unit),
            self.staff.unit(1),
        )
コード例 #6
0
ファイル: test_notehead.py プロジェクト: ajyoon/brown
 def test_staff_position_with_accidentals(self):
     self.assertEqual(
         Notehead(Mm(10), "cf'", Beat(1, 4), self.staff).staff_pos,
         self.staff.unit(5),
     )
     self.assertEqual(
         Notehead(Mm(10), "cn'", Beat(1, 4), self.staff).staff_pos,
         self.staff.unit(5),
     )
     self.assertEqual(
         Notehead(Mm(10), "cs'", Beat(1, 4), self.staff).staff_pos,
         self.staff.unit(5),
     )
コード例 #7
0
ファイル: test_chordrest.py プロジェクト: ajyoon/brown
 def test_stem_direction_override(self):
     pitches = ["b'"]
     chord = Chordrest(Mm(1), self.staff, pitches, Beat(1, 4), -1)
     assert chord.stem_direction == -1
     # Setting stem_direction = None should revert to default 1
     chord.stem_direction = None
     assert chord.stem_direction == 1
コード例 #8
0
ファイル: notehead.py プロジェクト: ajyoon/brown
 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
     )
コード例 #9
0
ファイル: test_notehead.py プロジェクト: ajyoon/brown
 def test_staff_position_low_octaves(self):
     self.assertEqual(
         Notehead(Mm(10), "c", Beat(1, 4), self.staff).staff_pos,
         self.staff.unit(8.5),
     )
     self.assertEqual(
         Notehead(Mm(10), "c,", Beat(1, 4), self.staff).staff_pos,
         self.staff.unit(12),
     )
     self.assertEqual(
         Notehead(Mm(10), "c,,", Beat(1, 4), self.staff).staff_pos,
         self.staff.unit(15.5),
     )
     self.assertEqual(
         Notehead(Mm(10), "c,,,", Beat(1, 4), self.staff).staff_pos,
         self.staff.unit(19),
     )
コード例 #10
0
ファイル: test_notehead.py プロジェクト: ajyoon/brown
 def test_staff_position_high_octaves(self):
     self.assertEqual(
         Notehead(Mm(10), "c''", Beat(1, 4), self.staff).staff_pos,
         self.staff.unit(1.5),
     )
     self.assertEqual(
         Notehead(Mm(10), "c'''", Beat(1, 4), self.staff).staff_pos,
         self.staff.unit(-2),
     )
     self.assertEqual(
         Notehead(Mm(10), "c''''", Beat(1, 4), self.staff).staff_pos,
         self.staff.unit(-5.5),
     )
     self.assertEqual(
         Notehead(Mm(10), "c'''''", Beat(1, 4), self.staff).staff_pos,
         self.staff.unit(-9),
     )
コード例 #11
0
ファイル: test_chordrest.py プロジェクト: ajyoon/brown
 def test_ledger_line_positions_with_different_clef(self):
     Clef(self.staff, Mm(10), "bass")
     pitches = ["e,", "d", "e'"]
     chord = Chordrest(Mm(15), self.staff, pitches, Beat(1, 4))
     assert chord.ledger_line_positions == [
         self.staff.unit(5),
         self.staff.unit(-2),
         self.staff.unit(-1),
     ]
コード例 #12
0
ファイル: test_chordrest.py プロジェクト: ajyoon/brown
 def test_ledger_line_positions(self):
     pitches = ["c'", "b'", "f'''"]
     chord = Chordrest(Mm(1), self.staff, pitches, Beat(1, 4))
     assert chord.ledger_line_positions == [
         self.staff.unit(5),
         self.staff.unit(-3),
         self.staff.unit(-2),
         self.staff.unit(-1),
     ]
コード例 #13
0
ファイル: test_chordrest.py プロジェクト: ajyoon/brown
 def test_rhythm_dot_positions_with_rest(self):
     chord = Chordrest(Mm(1), self.staff, None, Beat(7, 16))
     dots = list(chord.rhythm_dot_positions)
     dots.sort(key=lambda d: d.x)
     assert_almost_equal(
         dots[0], Point(self.staff.unit(1.326), self.staff.unit(1.5))
     )
     assert_almost_equal(
         dots[1], Point(self.staff.unit(1.826), self.staff.unit(1.5))
     )
コード例 #14
0
ファイル: rest.py プロジェクト: ajyoon/brown
 def __init__(
     self,
     pos: PointDef,
     parent: Union[StaffObject, Staff],
     duration: BeatDef,
 ):
     pos = Point.from_def(pos)
     self._duration = Beat.from_def(duration)
     MusicText.__init__(self, pos,
                        [self._glyphnames[self.duration.base_division]],
                        parent)
     StaffObject.__init__(self, parent)
コード例 #15
0
ファイル: test_chordrest.py プロジェクト: ajyoon/brown
 def test_rhythm_dot_positions_with_noteheads(self):
     pitches = ["e,", "d", "e'''"]
     chord = Chordrest(Mm(1), self.staff, pitches, Beat(7, 16))
     dots = list(chord.rhythm_dot_positions)
     dots.sort(key=lambda d: d.x)
     dots.sort(key=lambda d: d.y)
     assert_almost_equal(
         dots[0], Point(self.staff.unit(1.43), self.staff.unit(-3.5))
     )
     assert_almost_equal(
         dots[1], Point(self.staff.unit(1.93), self.staff.unit(-3.5))
     )
     assert_almost_equal(dots[2], Point(self.staff.unit(1.43), self.staff.unit(7.5)))
     assert_almost_equal(dots[3], Point(self.staff.unit(1.93), self.staff.unit(7.5)))
     assert_almost_equal(
         dots[4], Point(self.staff.unit(1.43), self.staff.unit(10.5))
     )
     assert_almost_equal(
         dots[5], Point(self.staff.unit(1.93), self.staff.unit(10.5))
     )
コード例 #16
0
ファイル: test_notehead.py プロジェクト: ajyoon/brown
 def test_staff_position_with_all_letter_names(self):
     self.assertEqual(
         Notehead(Mm(10), "d'", Beat(1, 4), self.staff).staff_pos,
         self.staff.unit(4.5),
     )
     self.assertEqual(
         Notehead(Mm(10), "e'", Beat(1, 4), self.staff).staff_pos, self.staff.unit(4)
     )
     self.assertEqual(
         Notehead(Mm(10), "f'", Beat(1, 4), self.staff).staff_pos,
         self.staff.unit(3.5),
     )
     self.assertEqual(
         Notehead(Mm(10), "g'", Beat(1, 4), self.staff).staff_pos, self.staff.unit(3)
     )
     self.assertEqual(
         Notehead(Mm(10), "a'", Beat(1, 4), self.staff).staff_pos,
         self.staff.unit(2.5),
     )
     self.assertEqual(
         Notehead(Mm(10), "b'", Beat(1, 4), self.staff).staff_pos, self.staff.unit(2)
     )
コード例 #17
0
 def tests__lte__with_non_nested(self):
     assert Beat(1, 4) <= Beat(1, 2)
     assert Beat(1, 4) <= Beat(1, 4)
コード例 #18
0
 def test__gt__with_non_nested(self):
     assert Beat(1, 4) > Beat(1, 8)
コード例 #19
0
ファイル: test_notehead.py プロジェクト: ajyoon/brown
 def test_staff_position_middle_c_treble(self):
     self.assertEqual(
         Notehead(Mm(10), "c'", Beat(1, 4), self.staff).staff_pos, self.staff.unit(5)
     )
コード例 #20
0
 def test__sub__with_nested(self):
     assert Beat(Beat(1, 2), 4) - Beat(1, 16) == Beat(1, 16)
コード例 #21
0
 def test__sub__with_non_nested(self):
     assert Beat(3, 4) - Beat(1, 4) == Beat(1, 2)
コード例 #22
0
 def test__add__with_nested(self):
     assert Beat(Beat(1, 2), 4) + Beat(1, 4) == Beat(3, 8)
コード例 #23
0
 def test_init_from_numerator_denominator(self):
     dur = Beat(1, 4)
     assert dur.numerator == 1
     assert dur.denominator == 4
コード例 #24
0
 def test__lt__with_non_nested(self):
     assert Beat(1, 4) < Beat(1, 2)
コード例 #25
0
 def tests__lte__with_nested(self):
     assert Beat(1, 4) <= Beat(Beat(1, 1), 1)
     assert Beat(1, 4) <= Beat(Beat(1, 2), 2)
コード例 #26
0
 def tests__gte__with_nested(self):
     assert Beat(1, 4) >= Beat(Beat(1, 3), 8)
     assert Beat(1, 4) >= Beat(Beat(1, 1), 4)
コード例 #27
0
 def test__lt__with__nested(self):
     assert Beat(Beat(1, 2), 4) < Beat(Beat(1, 1), 4)
コード例 #28
0
 def tests__gte__with_non_nested(self):
     assert Beat(1, 4) >= Beat(1, 8)
     assert Beat(1, 4) >= Beat(1, 4)
コード例 #29
0
ファイル: test_notehead.py プロジェクト: ajyoon/brown
 def test_staff_position_on_later_flowable_line(self):
     self.assertEqual(
         Notehead(Mm(1000), "c", Beat(1, 4), self.staff).staff_pos,
         self.staff.unit(8.5),
     )
コード例 #30
0
 def test__gt__with_nested(self):
     assert Beat(Beat(1, 1), 4) > Beat(Beat(1, 2), 4)