+(define-public ((every-nth-bar-number-visible n) barnum) (= 0 (modulo barnum n)))
+
+(define-public ((modulo-bar-number-visible n m) barnum) (and (> barnum 1) (= m (modulo barnum n))))
+
+(define-public ((set-bar-number-visibility n) tr)
+ (let* ((bn (ly:context-property tr 'currentBarNumber)))
+ (ly:context-set-property! tr 'barNumberVisibility (modulo-bar-number-visible n (modulo bn n)))))
+
+(define-public (first-bar-number-invisible barnum) (> barnum 1))
+
+;; See documentation of Item::visibility_lambda_
+(define-public begin-of-line-visible
+ #(#f #f #t))
+(define-public end-of-line-visible
+ #(#t #f #f))
+(define-public end-of-line-invisible
+ #(#f #t #t))
+(define-public spanbar-begin-of-line-invisible
+ #(#t #f #f))
+(define-public all-visible #(#t #t #t))
+(define-public all-invisible #(#f #f #f))
+(define-public begin-of-line-invisible
+ #(#t #t #f))
+(define-public center-invisible #(#t #f #t))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Bar lines.
+
+;;
+;; How should a bar line behave at a break?
+;;
+;; Why prepend `default-' to every scm identifier?
+(define-public (bar-line::calc-glyph-name grob)
+ (let* (
+ (glyph (ly:grob-property grob 'glyph))
+ (dir (ly:item-break-dir grob))
+ (result (assoc glyph
+ '((":|:" . (":|" . "|:"))
+ ("||:" . ("||" . "|:"))
+ ("|" . ("|" . ()))
+ ("||:" . ("||" . "|:"))
+ ("|s" . (() . "|"))
+ ("|:" . ("|" . "|:"))
+ ("|." . ("|." . ()))
+
+ ;; hmm... should we end with a bar line here?
+ (".|" . ("|" . ".|"))
+ (":|" . (":|" . ()))
+ ("||" . ("||" . ()))
+ (".|." . (".|." . ()))
+ ("" . ("" . ""))
+ (":" . (":" . ""))
+ ("." . ("." . ()))
+ ("empty" . (() . ()))
+ ("brace" . (() . "brace"))
+ ("bracket" . (() . "bracket")) )))
+ (glyph-name (if (= dir CENTER)
+ glyph
+ (if (and result (string? (index-cell (cdr result) dir)))
+ (index-cell (cdr result) dir)
+ #f)))
+ )
+
+ (if (not glyph-name)
+ (ly:grob-suicide! grob))
+
+ glyph-name))
+
+
+(define-public (shift-right-at-line-begin g)
+ "Shift an item to the right, but only at the start of the line."
+ (if (and (ly:item? g)
+ (equal? (ly:item-break-dir g) RIGHT))
+ (ly:grob-translate-axis! g 3.5 X)))
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Color
+
+(define-public color? list?)
+
+; predefined colors
+(define-public black '(0.0 0.0 0.0))
+(define-public white '(1.0 1.0 1.0))
+(define-public red '(1.0 0.0 0.0))
+(define-public green '(0.0 1.0 0.0))
+(define-public blue '(0.0 0.0 1.0))
+(define-public cyan '(1.0 1.0 0.0))
+(define-public magenta '(1.0 0.0 1.0))
+(define-public yellow '(0.0 1.0 1.0))
+
+(define-public grey '(0.5 0.5 0.5))
+(define-public darkred '(0.5 0.0 0.0))
+(define-public darkgreen '(0.0 0.5 0.0))
+(define-public darkblue '(0.0 0.0 0.5))
+(define-public darkcyan '(0.5 0.5 0.0))
+(define-public darkmagenta '(0.5 0.0 0.5))
+(define-public darkyellow '(0.0 0.5 0.5))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Pitch Trill Heads
+
+(define (parenthesize-elements grob)
+ (let*
+ ((elts (ly:grob-object grob 'elements))
+ (x-ext (ly:relative-group-extent elts grob X))
+ (font (ly:grob-default-font grob))
+ (lp (ly:font-get-glyph font "accidentals.leftparen"))
+ (rp (ly:font-get-glyph font "accidentals.rightparen"))
+ (padding 0.1))
+
+ (ly:stencil-add
+ (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
+ (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))
+ ))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;