Skip to content

Create an implicit part for a Voice outside a Staff - #197

Open
wattdave wants to merge 2 commits into
frescobaldi:masterfrom
wattdave:fix-voice-addlyrics-crash
Open

wattdave wants to merge 2 commits into
frescobaldi:masterfrom
wattdave:fix-voice-addlyrics-crash

Conversation

@wattdave

Copy link
Copy Markdown

Builds on the \addlyrics fix (#196). This PR is based on that branch, so it also contains that commit; please review #196 first.

Problem

A \new Voice placed directly in a group has an implicit Staff in LilyPond:

\score {
  \new StaffGroup <<
    \new Voice = "S" { \set Staff.instrumentName = #"Cantus" c''2 d'' }
    \addlyrics { Du tout }
    \new Voice = "B" { c2 g, }
  >>
}

ly musicxml exports no parts at all for this. In a real four-voice CPDL score,
where the Voices use note variables and \set Staff.instrumentName, it also
prints 'NoneType' object has no attribute 'name'.

Root cause

In ParseSource.check_context() (ly/musicxml/lymus2musxml.py), the Voice
branch only opens a new section. No part is created unless a Staff context
does it. Because nothing ever adds the section to a part, the music is dropped,
and Mediator.set_partname() writes to self.part, which is None.

Fix

When a Voice context starts with no part open, create one with
mediator.new_part(). When that Voice ends, add its music to the part with
mediator.check_part(), the same way a Staff is handled. A new implicit_staff
stack tracks this for nested Voices.

Tests

  • Added tests/test_xml_files/voice_in_group.{ly,xml} and test_voice_in_group.
  • Before the fix, the test fails because the output has no parts. After the fix,
    the full suite gives 20 passed and 2 xfailed. The 2 xfails were already there.
  • On the full Brumel "Du tout plongiet" CPDL score (convert-ly'd to 2.26), the
    output went from an empty document to 4 parts with notes and lyrics.

Not addressed

  • LayoutContext and Keyword warnings: the handlers for \layout/\midi
    blocks are not implemented. These warnings are harmless.
  • Measure boundaries are still wrong for this score, also with Fix bar counting and markup placement in MusicXML export #193 merged on top (tested: it merges cleanly, but the output is unchanged). Long notes that cross a barline in 2/2 are not split, so measures come out with the wrong length. That looks like a separate issue.
  • Incipits written with \cadenzaOn, and bar checks used where there are no
    barlines, still produce measures of the wrong length.

🤖 Generated with Claude Code

wattdave and others added 2 commits September 26, 2026 21:41
Lyrics following music via \addlyrics were appended as plain lists
directly into the barlist of the current part, so iterating the part
crashed with "AttributeError: 'list' object has no attribute 'pickup'".

Collect \addlyrics into a LyricsSection and merge it into the preceding
music when it ends, as is already done for \lyricsto. This also makes
the lyrics appear in the exported MusicXML.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A \new Voice placed directly in a StaffGroup (or other group) has an
implicit Staff in LilyPond, but the MusicXML export never created a
part for it. Its music was dropped, and a \set Staff.instrumentName
inside it failed with "'NoneType' object has no attribute 'name'".

When a Voice context starts with no part open, create a new part and
add the voice to it when the Voice ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant