def testDrawingDoesntCrash(self): """A woefully inadequate test to just see if slurs can be drawn at all. TODO LOW: Replace this with real tests """ slur = Slur((Mm(1), Mm(2)), self.left_parent, (Mm(3), Mm(4)), self.right_parent)
def test_modifying_accidental_type_changes_music_char(self): # This will fail until the causing bug is fixed acc = Accidental((Mm(0), Mm(0)), AccidentalType.SHARP, self.staff) acc.accidental_type = AccidentalType.FLAT assert acc.music_chars == [ MusicChar(self.staff.music_font, "accidentalFlat") ]
def test_ledgers_needed_from_position_with_odd_line_count(self): staff = Staff((Mm(0), Mm(0)), Mm(100), self.flowable, line_count=5) # Inside the staff, no ledgers assert staff.ledgers_needed_for_y(staff.unit(0)) == [] assert staff.ledgers_needed_for_y(staff.unit(4)) == [] # Just outside the staff, no ledgers assert staff.ledgers_needed_for_y(staff.unit(-0.5)) == [] assert staff.ledgers_needed_for_y(staff.unit(4.5)) == [] # Right on the first ledger assert staff.ledgers_needed_for_y(staff.unit(-1)) == [staff.unit(-1)] assert staff.ledgers_needed_for_y(staff.unit(5)) == [staff.unit(5)] # Further outside with multiple ledgers, directly on lines assert staff.ledgers_needed_for_y(staff.unit(6)) == [ staff.unit(6), staff.unit(5), ] assert staff.ledgers_needed_for_y(staff.unit(-2)) == [ staff.unit(-2), staff.unit(-1), ] # Further outside with multiple ledgers, between lines assert staff.ledgers_needed_for_y(staff.unit(6.5)) == [ staff.unit(6), staff.unit(5), ] assert staff.ledgers_needed_for_y(staff.unit(-2.5)) == [ staff.unit(-2), staff.unit(-1), ]
def test_position_on_ledger_with_odd_line_count(self): staff = Staff((Mm(0), Mm(0)), Mm(100), self.flowable, line_count=5) assert staff.y_on_ledger(staff.unit(-1)) is True assert staff.y_on_ledger(staff.unit(-0.5)) is False assert staff.y_on_ledger(staff.unit(0)) is False assert staff.y_on_ledger(staff.unit(4)) is False assert staff.y_on_ledger(staff.unit(4.5)) is False assert staff.y_on_ledger(staff.unit(5)) is True
def test_generate_layout_controllers_with_two_pages(self): live_width = neoscore.document.paper.live_width test_flowable = Flowable((Mm(0), Mm(0)), live_width * 1.5, Mm(256), Mm(5)) # Should result in two lines separated by one page break test_flowable._generate_layout_controllers() assert len(test_flowable.layout_controllers) == 2 assert test_flowable.layout_controllers[1].flowable_x == live_width
def setUp(self): neoscore.setup() self.staff = Staff((Mm(0), Mm(0)), Mm(100), flowable=None, staff_unit=Mm(1)) self.font = MusicFont(constants.DEFAULT_MUSIC_FONT_NAME, self.staff.unit)
def test_generate_layout_controllers_with_many_pages(self): live_width = neoscore.document.paper.live_width test_flowable = Flowable((Mm(0), Mm(0)), live_width * 3.5, Mm(256), Mm(5)) test_flowable._generate_layout_controllers() assert len(test_flowable.layout_controllers) == 4 assert test_flowable.layout_controllers[1].flowable_x == live_width assert test_flowable.layout_controllers[2].flowable_x == live_width * 2 assert test_flowable.layout_controllers[3].flowable_x == live_width * 3
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), ]
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_generate_layout_controllers_with_many_lines(self): live_width = neoscore.document.paper.live_width test_flowable = Flowable((Mm(0), Mm(0)), live_width * 3.5, Mm(50), Mm(5)) # Should result in four lines separated by 3 line breaks test_flowable._generate_layout_controllers() assert len(test_flowable.layout_controllers) == 4 assert test_flowable.layout_controllers[1].flowable_x == live_width assert test_flowable.layout_controllers[2].flowable_x == live_width * 2 assert test_flowable.layout_controllers[3].flowable_x == live_width * 3
def test_repetition_count(self): line = RepeatingMusicTextLine( (Mm(1), Mm(2)), self.left_parent, Mm(3), self.char, self.right_parent, scale=2, ) expected = int(Mm(12) / self.single_repetition_width) assert line._repetitions_needed == expected
def test_active_transposition_at_with_octave_line_with_staff_parent(self): staff = Staff((Mm(0), Mm(0)), Mm(100), self.flowable) octave_line = OctaveLine((Mm(20), Mm(0)), staff, Mm(80), indication="8va") assert staff.active_transposition_at(Mm(0)) is None assert staff.active_transposition_at( Mm(20)) == octave_line.transposition assert staff.active_transposition_at( Mm(100)) == octave_line.transposition assert staff.active_transposition_at(Mm(101)) is None
def test_generate_layout_controllers_on_new_pages_have_no_padding(self): live_width = neoscore.document.paper.live_width test_flowable = Flowable((Mm(0), Mm(0)), live_width * 3.5, Mm(1000), Mm(5)) test_flowable._generate_layout_controllers() # Test that every NewLine which is also a page break # has no y_padding (is aligned with the top of the live page area) current_page = None for line in test_flowable.layout_controllers: if current_page == line.page: continue current_page = line.page assert line.margin_bottom == Mm(0)
def test_generate_layout_controllers_new_lines_have_padding(self): live_width = neoscore.document.paper.live_width test_flowable = Flowable((Mm(0), Mm(0)), live_width * 3.5, Mm(1000), Mm(5)) test_flowable._generate_layout_controllers() # Test that every NewLine which is not also a page break has the expected # y_padding from the flowable current_page = None for line in test_flowable.layout_controllers: if current_page != line.page: current_page = line.page continue assert line.margin_bottom == test_flowable.y_padding
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), )
def test_generate_layout_controllers_with_only_one_line(self): test_flowable = Flowable((Mm(9), Mm(11)), Mm(100), Mm(50), Mm(5)) test_flowable._generate_layout_controllers() assert len(test_flowable.layout_controllers) == 1 assert test_flowable.layout_controllers[0].flowable_x == Mm(0) assert test_flowable.layout_controllers[0].pos == Point(Mm(9), Mm(11)) assert test_flowable.layout_controllers[ 0].page == neoscore.document.pages[0]
def test_qt_object_creation(self): pen = PenInterface( Color(0, 100, 200, 250), Mm(1), PenPattern.SOLID, PenJoinStyle.BEVEL, PenCapStyle.SQUARE, ) assert pen.qt_object.color().red() == 0 assert pen.qt_object.color().green() == 100 assert pen.qt_object.color().blue() == 200 assert pen.qt_object.color().alpha() == 250 self.assertAlmostEqual(pen.qt_object.widthF(), Mm(1).base_value) assert pen.qt_object.style() == PenPattern.SOLID.value assert pen.qt_object.joinStyle() == PenJoinStyle.BEVEL.value assert pen.qt_object.capStyle() == PenCapStyle.SQUARE.value
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
def test_init(self): test_paper = Paper(*[Mm(val) for val in [1, 2, 3, 4, 5, 6, 7]]) assert test_paper.width == Mm(1) assert test_paper.height == Mm(2) assert test_paper.margin_top == Mm(3) assert test_paper.margin_right == Mm(4) assert test_paper.margin_bottom == Mm(5) assert test_paper.margin_left == Mm(6) assert test_paper.gutter == Mm(7)
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), )
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), )
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), ]
def test_middle_c_at_with_explicit_clefs(self): staff = Staff((Mm(0), Mm(0)), Mm(100), self.flowable) Clef(staff, Mm(0), "treble") Clef(staff, Mm(10), "bass") # Test between two clefs should be in treble mode assert staff.middle_c_at(Mm(1)) == staff.unit(5) # Test after bass clef goes into effect assert staff.middle_c_at(Mm(11)) == staff.unit(-1)
def test_active_clef_at_with_explicit_clefs(self): staff = Staff((Mm(0), Mm(0)), Mm(100), self.flowable) Clef(staff, Mm(0), "treble") Clef(staff, Mm(10), "bass") # Test between two clefs should have treble in effect assert staff.active_clef_at(Mm(1)).clef_type == ClefType.TREBLE # Test after bass clef goes into effect assert staff.active_clef_at(Mm(11)).clef_type == ClefType.BASS
def test_page_origin_at_first_page(self): left_margin = Mm(13) top_margin = Mm(21) test_paper = Paper(Mm(200), Mm(250), top_margin, Mm(10), Mm(20), left_margin, Mm(0)) test_doc = Document(test_paper) found = test_doc.page_origin(0) assert_almost_equal(found, Point(left_margin, top_margin))
def test_make_rotation(self): original = Paper(*[Mm(val) for val in [100, 101, 1, 2, 3, 4, 5]]) rotated = original.make_rotation() assert rotated.width == original.height assert rotated.height == original.width assert rotated.margin_top == original.margin_left assert rotated.margin_right == original.margin_top assert rotated.margin_bottom == original.margin_right assert rotated.margin_left == original.margin_bottom assert rotated.gutter == original.gutter
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)) )
def test_page_origin_at_second_page(self): width = Mm(200) left_margin = Mm(13) top_margin = Mm(21) test_paper = Paper(width, Mm(250), top_margin, Mm(10), Mm(20), left_margin, Mm(0)) test_doc = Document(test_paper) found = test_doc.page_origin(1) page_width = width expected_x = left_margin + page_width + test_doc._page_display_gap expected_y = top_margin assert_almost_equal(found, Point(expected_x, expected_y))
def __init__( self, pos: PointDef, width: Unit, height: Unit, y_padding: Unit = Mm(5), break_threshold: Unit = Mm(5), ): """ Args: pos: Starting position in relative to the top left corner of the live document area of the first page width: length of the flowable height: height of the flowable y_padding: The vertical gap between flowable sections break_threshold: The maximum distance the flowable will shorten a line to allow a break to occur on a `BreakOpportunity` """ super().__init__(pos) self._length = width self._height = height self._y_padding = y_padding self._break_threshold = break_threshold self._layout_controllers = self._generate_layout_controllers()
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)) )