3

In my (MuseScore) sheets have a lot of custom bar number indicators, like this:

bar number

which help me quickly glance over the length of the sections. The bar count can also be above a bar containing notes:

bar with notes

Unfortunately, I'm having a hard time figuring out how to do this in Lilypond. I'm pretty sure this is possible but figuring out how-exactly is a bit of a pain.

When an empty-chord mark is used in a bar with notes, then the markup is displayed above the next note and not in the middle. So, as a workaround I could just use that but this is more of a challenge to understand how to use Lilypond to get what is needed.

Currently I'm trying to achieve this with Text Spanners, as I would like the number in parentheses to be centered above a bar. All the examples override the text at the left and right edges of a spanner. I've also seen the span-type and span-text in some functions but am not sure how to use them.

I've also seen \textSpannerUp commands but have no idea how they are to be used.

Edit: The automatic bar numbers are positioned correctly when \set Score.centerBarNumbers = ##t is used. Meaning it is certainly doable.

auto bar numbers

The code is here but I don't know Scheme that well. :(

3 Answers 3

2

Quick and dirty way to do it:

markAtCenterAboveMeasure =
#(define-music-function (m music)
   (markup? ly:music?)
   #{
     \once\override
     Staff.MeasureCounter.text = #m
     <>\startMeasureCount
     #music
     <>\stopMeasureCount
   #})

\new DrumStaff \with {
  \consists Measure_counter_engraver
}{
  s1*7
  \markAtCenterAboveMeasure \markup\dynamic"(8)" s1
}
3
  • Quick and dirty does it! Edit: Any specific reason to use \dynamic? It seems to work just the same without both \markup and \dynamic. Jan 27, 2022 at 15:38
  • Works well for blank bars but not when there are notes: imgur.com/a/9mcvKNE. It's fixed by having the notes afterwards in {}. Jan 27, 2022 at 15:46
  • @AlenSiljak The choice for \dynamic was simply to mimic what your MuseScore example used. There is no real additional reason. About your second point: Yes, as with any music function you need to wrap multiple music events in a simultaneous music event. I thought this was obvious.
    – Lazy
    Jan 27, 2022 at 23:41
1

Since you are indicating bar numbers, perhaps it makes sense to try something like a modification of Measure-centered bar numbers, however this won't work for LilyPond versions earlier than v2.23.

0

Empty-Chord Marks

A simple solution for the blank bars can be the empty chord mark:

s1 <>^\markup {(2)} or simply s1 <>^"(4)".

This is not centered above the bar, unfortunately.

The good thing with a markup is that it can be customized in detail and extracted into a function which can be included in multiple score sheets.

Text Spanners

Using spanners, I've managed to do

    \override TextSpanner.text = "blah"
    \override TextSpanner.stencil = #ly:text-interface::print
    \override TextSpanner.font-shape = #'upright
    \override TextSpanner.side-axis = 0
    \override TextSpanner.direction = #'CENTER

    bd4 \startTextSpan sn bd sn \stopTextSpan

which produces

spanner

but is not centered, although it does span the whole bar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.