\version "2.19.57" \paper { indent = 0 } #(define draw-nc-position #f) #(define draw-starter-border #t) #(define draw-x-offset-ref #t) #(define draw-accs-box #t) #(define draw-intended-space #f) #(define draw-clef-acc-dist #f) #(define assumed-padding 2) #(define intended-space 4) #(set-object-property! 'seen 'backend-type? boolean?) #(define (distance-info tie) (let* (;; our helper grobs (sys (ly:grob-system tie)) (left-nh (ly:grob-parent tie X)) (nc (ly:grob-parent left-nh Y)) ; NOTE: For simplicity we don't handle missing accidentals (accs (ly:note-column-accidentals nc))) (if (not (ly:grob-property nc 'seen)) (let* ;;;; some lengths and props ((acc-x-extent (ly:grob-property accs 'X-extent)) (acc-width (- (cdr acc-x-extent) (car acc-x-extent))) (left-acc-x-extent (car acc-x-extent)) ;; first NonMusicalPaperColumn, includes clef, key and timesignature (staff-starter (first (ly:grob-array->list (ly:grob-object sys 'elements)))) (staff-starter-width (let ((ext (ly:grob-property staff-starter 'X-extent))) (- (cdr ext) (car ext)))) (staff-starter-x-pos (ly:grob-relative-coordinate staff-starter sys X)) ;; position of note column, relative to system (blue vertical line) (nc-x-pos (ly:grob-relative-coordinate nc sys X)) (nc-x-offset (let ((off (ly:grob-property nc 'X-offset))) (if (null? off) 0 off))) (nc-acc-dist (- nc-x-offset left-acc-x-extent)) ;(staff-starter-nc-dist (- nc-x-pos staff-starter-width)) (clef-acc-dist (- nc-x-pos staff-starter-width nc-acc-dist)) (missing-length (let ((mw (- intended-space clef-acc-dist))) (if (> mw 0) mw #f))) (to-offset (+ nc-acc-dist intended-space (* -1 assumed-padding))) ) ; (ly:message "\nNote column X position: ~a" nc-x-pos) ; (ly:message "Accidentals X position: ~a" acc-x-pos) ; (ly:message "Width of staff starters: ~a" staff-starter-width) ; (ly:message "Space between clef and notes: ~a" staff-starter-nc-dist) ; (ly:message "Accidentals Width: ~a" acc-x-extent) ; (ly:message "nc-acc-dist: ~a" nc-acc-dist) (ly:message "\n") (ly:message "Staff start padding: ~a" (ly:grob-property staff-starter 'padding)) (if missing-length (ly:message "missing space: ~a" missing-length)) (ly:message "Set X-offset to ~a\n\n" to-offset) (ly:grob-set-property! nc 'seen #t) (ly:stencil-add ;; the space we want to have (if draw-intended-space (ly:stencil-translate (stencil-with-color (ly:make-stencil `(path 0.1 `(moveto 0 -3 rlineto 0 6 rlineto ,,intended-space 0 rlineto 0 -6 rlineto -4 0))) red) (cons (- staff-starter-width nc-x-pos) 0)) empty-stencil) ;; where is the "origin" of the note column? (if draw-nc-position (stencil-with-color (ly:make-stencil `(path 0.1 `(moveto 0 -3 rlineto 0 6))) blue) empty-stencil) (if draw-starter-border (ly:stencil-translate (stencil-with-color (ly:make-stencil `(path 0.1 `(moveto 0 -3.5 rlineto 0 7))) blue) (cons (+ staff-starter-x-pos (- staff-starter-width nc-x-pos)) 0)) empty-stencil) (if draw-x-offset-ref (ly:stencil-translate (stencil-with-color (ly:make-stencil `(path 0.1 `(moveto 0 -4.5 rlineto 0 9))) magenta) (cons (* -1 nc-x-offset) 0)) empty-stencil) ;; origin and extent of accidentals (if draw-accs-box (ly:stencil-translate (stencil-with-color (ly:make-stencil `(path 0.1 `(moveto ,,(car acc-x-extent) -2.5 rlineto 0 5 rlineto ,,acc-width 0 rlineto 0 -5 rlineto ,,(* -1 acc-width) 0 ))) magenta) (cons (* -1 nc-x-offset) 0)) empty-stencil) ;; Available distance between clef and accidentals (if draw-clef-acc-dist (ly:stencil-translate (stencil-with-color (ly:make-stencil `(path 0.2 `(moveto 0 1 rlineto 0 -2 moveto 0 0 rlineto ,,clef-acc-dist 0 rmoveto 0 1 rlineto 0 -2))) green) (cons (- staff-starter-width nc-x-pos) 0)) empty-stencil) (ly:tie::print tie) )) (ly:tie::print tie) ))) music = { 1 ~ q } \markup "Default result (no X-offset):" { \music } \markup "X-offset: 2" { \once \override NoteColumn.X-offset = 2 \music } \markup "X-offset: 3" { \once \override NoteColumn.X-offset = 3 \music } \markup "X-offset: 4" { \once \override NoteColumn.X-offset = 4 \music } \markup "X-offset: 4.875" { \once \override NoteColumn.X-offset = 4.875 \music } \markup "X-offset: 5.875" { \once \override NoteColumn.X-offset = 5.875 \music } \markup "Intended result:" \markup #(format "X-offset: ~a" 6.875) { \once \override NoteColumn.X-offset = 6.875 \music } \markup "Default spacing without accidentals" { 1 } \layout { \context { \Score \override Tie.stencil = #distance-info \override NoteColumn.seen = ##f } \context { \Score } }