Fix MEI importer silently dropping <bTrem> and shifting subsequent onsets (AI) - #2000
Open
youdie006 wants to merge 1 commit into
Open
Fix MEI importer silently dropping <bTrem> and shifting subsequent onsets (AI)#2000youdie006 wants to merge 1 commit into
youdie006 wants to merge 1 commit into
Conversation
…sets music21.mei.base._processEmbeddedElements dispatches each child element through a per-container tag->function mapping. A child whose tag is not in the mapping is silently dropped and never recursed into (only a debug message is emitted). <bTrem> (measured/bowed tremolo, which wraps the <note>/<chord> carrying the notated duration) was registered in none of the dispatch dicts, so the tremolo note/chord and its duration disappeared and every later onset in the layer shifted earlier - data corruption, not a cosmetic loss. Add bTremFromElement, mirroring beamFromElement/tupletFromElement: it imports the wrapped <note>/<chord> with its notated duration and returns it, so timing is preserved. When @unitdur is present it attaches an expressions.Tremolo with numberOfMarks derived from the unit duration. Register <bTrem> in the layer, beam, and tuplet dispatch tables. Scope limited to <bTrem>; the two-note <fTrem> is intentionally out of scope. Docstring implemented/not-implemented lists updated to match. Fixes cuthbertLab#1994.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1994
Problem
music21.mei.base._processEmbeddedElementsdispatches each child element through a per-container tag->function mapping. A child whose tag is not in the mapping is silently dropped and never recursed into (only a debug message is emitted).<bTrem>(measured / bowed tremolo, which wraps the<note>/<chord>carrying the notated duration) was registered in none of the dispatch dicts, so the tremolo note/chord and its duration disappeared and every later onset in the layer shifted earlier -- data corruption, not a cosmetic loss. As @weselyj reported, one dropped tremolo chord shifted the remainder of a real piece by a quarter note.Fix
bTremFromElement, mirroringbeamFromElement/tupletFromElement: it imports the wrapped<note>/<chord>with its notated duration and returns it, so timing is preserved. When@unitduris present it attaches anexpressions.TremolowithnumberOfMarksderived from the unit duration (eighth->1 mark, sixteenth->2, ...).<bTrem>in the layer, beam, and tuplet dispatch tables.<bTrem>; the two-note<fTrem>is intentionally out of scope.Tests
Added focused tests in
music21/mei/test_base.pyusing the reporter's snippet: the<bTrem>chord now imports on beat 2 with its correct duration, subsequent onsets no longer shift (3 notes at offsets 0.0/1.0/2.0, ql 1/1/2), and the Tremolo expression is attached with the right number of marks. Red-green verified (without the fix the layer imports only 2 notes); the fullmusic21/mei/test_base.pymodule and the module doctests pass with no regressions; ruff, pylint, and mypy are clean.Thanks to @weselyj for the precise repro and to @mscuthbert for inviting the PR.
AI disclosure
This contribution was prepared with AI assistance; I take responsibility for its correctness and have verified it against the project's test suite and style checks.