Skip to content

Instantly share code, notes, and snippets.

@igneus
Last active November 24, 2024 19:35
Show Gist options
  • Save igneus/99fe721936ddd7394b0e55178cb2461b to your computer and use it in GitHub Desktop.
Save igneus/99fe721936ddd7394b0e55178cb2461b to your computer and use it in GitHub Desktop.
LilyPond, square notation: add shade to selected staff lines
\version "2.24.1"
\include "gregorian.ly"
#(set-global-staff-size 32)
\layout {
\override VaticanaStaff.StaffSymbol.color = "black"
\override VaticanaStaff.LedgerLineSpanner.color = "black"
\override VaticanaLyrics.LyricText.font-size = #-2
}
\paper {
#(define fonts
(set-global-fonts
#:roman "Junicode"
#:factor (/ staff-height pt 20)))
}
%% Gray shades of selected staff lines to be combined with the actual staff symbol
%% via ly:stencil-add.
%%
%% (shade-staff-lines 1 2 3 4)
%% (shade-staff-lines 1 3)
%% The numbers specify staff lines to be provided with a shade.
%% Line numbering is as in Gregorio (1 is the bottom line).
%%
%% Based on http://lsr.di.unimi.it/LSR/Item?id=700
#(define ((shade-staff-lines . rest) grob)
(define (index-cell cell dir)
(if (equal? dir RIGHT)
(cdr cell)
(car cell)))
(define (index-set-cell! x dir val)
(case dir
((-1) (set-car! x val))
((1) (set-cdr! x val))))
(let* ((common (ly:grob-system grob))
(span-points '(0 . 0))
(width (ly:grob-property grob 'width))
(line-positions (ly:grob-property grob 'line-positions))
(staff-space (ly:grob-property grob 'staff-space 1))
(thickness (/ staff-space 4))
(line-stencil #f)
(total-lines empty-stencil)
(shaded-lines rest))
(for-each
(lambda (dir)
(if (and (= dir RIGHT)
(number? width))
(set-cdr! span-points width)
(let* ((bound (ly:spanner-bound grob dir))
(bound-ext (ly:grob-extent bound bound X)))
(index-set-cell! span-points dir
(ly:grob-relative-coordinate bound common X))
(if (and (not (ly:item-break-dir bound))
(not (interval-empty? bound-ext)))
(index-set-cell! span-points dir
(+ (index-cell span-points dir)
(index-cell bound-ext dir)))))))
(list LEFT RIGHT))
(set! span-points
(coord-translate span-points
(- (ly:grob-relative-coordinate grob common X))))
(set! line-stencil
(make-filled-box-stencil span-points (cons 0 thickness)))
(let* ((line-count (ly:grob-property grob 'line-count 5))
(height (* (1- line-count) (/ staff-space 2))))
(do ((i 0 (1+ i)))
((= i line-count))
(when (memq (- 4 i) shaded-lines)
(set! total-lines (ly:stencil-add
total-lines
(ly:stencil-translate-axis
(ly:stencil-in-color line-stencil "#e1e1e1")
(- height (* i staff-space) thickness) Y))))))
total-lines))
% with lilygabc
\include "lilygabc.ily"
\score {
\gabc-vaticana
"(c4) Tres(g) pú(g')e(g)ri(gh) jus(hv_GF)su(gh) re(h)gis(g'_) (,)
in(f) for(hj~)ná(j)cem(i) mis(jk)si(h) sunt,(g.) (;)
non(j) ti(i')mén(j)tes(h') flam(j)mam(g') i(h)gnis,(g_f_) (;)
di(d)cén(f_g)tes:(g_f) Be(h)ne(ji)dí(hg)ctus(fg) De(g)us,(gf) al(gh)le(h)lú(g.)ia.(g.) (::)
E(j) u(j) o(i) u(j) a(h) e.(g) (::)"
\layout {
\override VaticanaStaff.StaffSymbol.stencil =
#(lambda (grob)
(ly:stencil-add
((shade-staff-lines 2 4) grob)
(ly:staff-symbol::print grob)))
}
}
% vanilla LilyPond
\score {
<<
\new VaticanaVoice = "v" {
\clef "vaticana-do3"
g g\ictus g
\[ g\melisma \pes a\melismaEnd \]
\[ \virga a\episemInitium\episemFinis\melisma \inclinatum g \inclinatum f\melismaEnd \]
\[ g\melisma \pes a\melismaEnd \]
a g\episemInitium\episemFinis\ictus \divisioMinima
}
\new VaticanaLyrics \lyricsto "v" {
Tres pú -- e -- ri jus -- su re -- gis
}
>>
\layout {
\override VaticanaStaff.StaffSymbol.stencil =
#(lambda (grob)
(ly:stencil-add
((shade-staff-lines 2 4) grob)
(ly:staff-symbol::print grob)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment