Staff in Staff group starts after the start of the piece
I would like to have a piece that starts with one staff and later has two. I've tried something like this
MusicA = #(define-music-function (parser location inTab) (boolean?)
#{ a4 b4 c2 #})
MusicB = #(define-music-function (parser location inTab) (boolean?)
#{ d4 e4 f2 #})
MusicC = #(define-music-function (parser location inTab) (boolean?)
#{ g4 a4 b2 #})
MyStaff = <<
new Staff MusicA
new StaffGroup {
new Staff MusicB
new Staff MusicC
}
>>
score {
myStaff
}
I would like to keep the general structure in the code, but I don't know how to fix the part in MyStaff = <<...>> so that I don't get an error message.
I am aware of this snippet for adding an extra staff, but I would rather not change the general structure of my code.
2 Comments
Sorted by latest first Latest Oldest Best
I'm not sure why you attempted to use define-music-function here, but your definitions are wrong, because their first argument is not a boolean.
Also in your example you define MyStaff and then try to use myStaff. Lilypond names are case sensitive!
I suspect the message about a missing } really means "Lilypond has just got very confused." After a bit of tinkering with the code I got the more understandable message
error: wrong type for argument 1. Expecting boolean, found (make-music ... etc )
You can fix that error by changing the argument types from boolean? to ly:music? but that doesn't fix the staff indentation problem.
But if you simplify the code to
MusicA = { a4 b4 c2 }
MusicB = { d4 e4 f2 }
MusicC = { g4 a4 b2 }
MyStaff = <<
new Staff MusicA
new StaffGroup {
new Staff MusicB
new Staff MusicC
}
>>
score {
MyStaff
}
it does something closer to what you want:
However you can't "overlap" the two staves in the StaffGroup that way. You probably want to define the staves for the full duration of the piece (using spacer rests where there are no notes) and then use RemoveEmptyStaves or RemoveAllEmptyStaves, and maybe a break so the music on the "second staff" starts at the beginning of a system.
If by "later has two" you mean that the additional staff persists for longer portions of your piece, you can use RemoveEmptyStaves, as has been pointed out in user19146's answer and is documented in lilypond.org/. Admittedly the structure of your code has to change moderately, because in a hidden sense, all staves start simultaneously at the beginning of the piece.
MusicA = { a1 a4 a a2 a1 a4 a2 a4 a a a a a1 a2. a4 a4 a4 a2 a1 }
MusicB = { b2 b4 b b1 b4 b b2 b1 b2 b b1 b4 b2 b4 b1 b1 }
MusicC = { clef bass r1 r1 break c4 c4 c2 c1 break r1 r break c c1 c2 c4 c8 c }
MyStaff = <<
new Staff MusicA
new Staff MusicB
new Staff MusicC
>>
score {
layout {
context {
Staff RemoveEmptyStaves
override VerticalAxisGroup.remove-first = ##t
}
}
MyStaff
}
Terms of Use Privacy policy Contact About Cancellation policy © freshhoot.com2025 All Rights reserved.