+(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 ly: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)))
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Tuplets
+
+(define-public (tuplet-number::calc-denominator-text grob)
+ (let*
+ ((ev (ly:grob-property grob 'cause)))
+
+ (number->string (ly:event-property ev 'denominator))))
+
+
+(define-public (tuplet-number::calc-fraction-text grob)
+ (let*
+ ((ev (ly:grob-property grob 'cause)))
+ (format "~a:~a"
+ (ly:event-property ev 'denominator)
+ (ly:event-property ev 'numerator))))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 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 '(0.0 1.0 1.0))
+(define-public magenta '(1.0 0.0 1.0))
+(define-public yellow '(1.0 1.0 0.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.0 0.5 0.5))
+(define-public darkmagenta '(0.5 0.0 0.5))
+(define-public darkyellow '(0.5 0.5 0.0))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; * Pitch Trill Heads
+;; * Parentheses
+
+(define (parenthesize-elements grob . rest)
+ (let*
+ (
+ (refp (if (null? rest)
+ grob
+ (car rest)))
+ (elts (ly:grob-object grob 'elements))
+ (x-ext (ly:relative-group-extent elts refp X))