From baa2feedb3dfe7f2d734e7cd3616b0a16dcb8e50 Mon Sep 17 00:00:00 2001 From: melkisedeath Date: Wed, 20 Sep 2023 10:54:47 +0200 Subject: [PATCH 1/2] A unit test example for cross staff beaming. The possibility of testing other formats is left open. --- .../test_cross_staff_beaming.musicxml | 390 ++++++++++++++++++ tests/test_cross_staff_beaming.py | 20 + 2 files changed, 410 insertions(+) create mode 100644 tests/data/musicxml/test_cross_staff_beaming.musicxml create mode 100644 tests/test_cross_staff_beaming.py diff --git a/tests/data/musicxml/test_cross_staff_beaming.musicxml b/tests/data/musicxml/test_cross_staff_beaming.musicxml new file mode 100644 index 00000000..f30dcddc --- /dev/null +++ b/tests/data/musicxml/test_cross_staff_beaming.musicxml @@ -0,0 +1,390 @@ + + + + + Untitled score + + + Composer / arranger + + MuseScore 4.0.0 + 2023-09-20 + + + + + + + + + + Piano + Pno. + + Piano + + + + 1 + 1 + 78.7402 + 0 + + + + + + + 2 + + 0 + + + 2 + + G + 2 + + + F + 4 + + + + + G + 4 + + 1 + 1 + eighth + down + 1 + begin + + + + F + 4 + + 1 + 1 + eighth + down + 1 + continue + + + + E + 4 + + 1 + 1 + eighth + down + 1 + continue + + + + D + 4 + + 1 + 1 + eighth + down + 1 + end + + + + C + 4 + + 1 + 1 + eighth + down + 1 + begin + + + + B + 3 + + 1 + 1 + eighth + up + 2 + continue + + + + A + 3 + + 1 + 1 + eighth + up + 2 + continue + + + + G + 3 + + 1 + 1 + eighth + up + 2 + end + + + 8 + + + + C + 5 + + 4 + 2 + half + up + 1 + + + + D + 5 + + 4 + 2 + half + up + 1 + + + 8 + + + + C + 3 + + 4 + 5 + half + down + 2 + + + + + E + 3 + + 4 + 5 + half + down + 2 + + + + B + 2 + + 4 + 5 + half + down + 2 + + + + + D + 3 + + 4 + 5 + half + down + 2 + + + + + + G + 4 + + 1 + 1 + eighth + down + 1 + begin + + + + F + 3 + + 1 + 1 + eighth + up + 2 + continue + + + + F + 4 + + 1 + 1 + eighth + down + 1 + continue + + + + G + 3 + + 1 + 1 + eighth + up + 2 + end + + + + A + 3 + + 1 + 1 + eighth + up + 2 + begin + + + + B + 3 + + 1 + 1 + eighth + down + 1 + end + + + + C + 4 + + 2 + 1 + quarter + up + 1 + + + 8 + + + + E + 5 + + 4 + 2 + half + up + 1 + + + + D + 5 + + 4 + 2 + half + up + 1 + + + 8 + + + + B + 2 + + 4 + 5 + half + down + 2 + + + + + D + 3 + + 4 + 5 + half + down + 2 + + + + C + 3 + + 4 + 5 + half + down + 2 + + + + + E + 3 + + 4 + 5 + half + down + 2 + + + light-heavy + + + + diff --git a/tests/test_cross_staff_beaming.py b/tests/test_cross_staff_beaming.py new file mode 100644 index 00000000..5eaecfaf --- /dev/null +++ b/tests/test_cross_staff_beaming.py @@ -0,0 +1,20 @@ +import unittest +import os +from tests import MUSICXML_PATH +from partitura import load_musicxml +import numpy as np + +EXAMPLE_FILE = os.path.join(MUSICXML_PATH, "test_cross_staff_beaming.musicxml") + +class CrossStaffBeaming(unittest.TestCase): + def test_cross_staff_single_part_musicxml(self): + score = load_musicxml(EXAMPLE_FILE) + note_array = score.note_array(include_staff=True) + expected_staff = np.array([1, 1, 1, 1, 1, 2, 2, 2, 1, 2, 1, 2, 2, 1, 1]) + cross_staff_mask = (note_array["pitch"] > 52) & (note_array["pitch"] < 72) + note_array_staff = note_array[cross_staff_mask]["staff"] + expected_voice = np.ones(len(note_array_staff), dtype=int) + note_array_voice = note_array[[cross_staff_mask]]["voice"] + self.assertTrue(np.all(note_array_staff == expected_staff)) + self.assertTrue(np.all(note_array_voice == expected_voice)) + From a2e52b8b0776c431df8bdb791c2412aa9c963299 Mon Sep 17 00:00:00 2001 From: melkisedeath Date: Wed, 20 Sep 2023 11:28:27 +0200 Subject: [PATCH 2/2] minor typo correction. --- tests/test_cross_staff_beaming.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cross_staff_beaming.py b/tests/test_cross_staff_beaming.py index 5eaecfaf..1b8ecd8f 100644 --- a/tests/test_cross_staff_beaming.py +++ b/tests/test_cross_staff_beaming.py @@ -14,7 +14,7 @@ def test_cross_staff_single_part_musicxml(self): cross_staff_mask = (note_array["pitch"] > 52) & (note_array["pitch"] < 72) note_array_staff = note_array[cross_staff_mask]["staff"] expected_voice = np.ones(len(note_array_staff), dtype=int) - note_array_voice = note_array[[cross_staff_mask]]["voice"] + note_array_voice = note_array[cross_staff_mask]["voice"] self.assertTrue(np.all(note_array_staff == expected_staff)) self.assertTrue(np.all(note_array_voice == expected_voice))