diff --git a/lily/include/note-column.hh b/lily/include/note-column.hh index 02342472555e0bef6205b9512f74d17a2afe05a1..91d2efb1ef5f4bb12588ed2113826b7ce52288e2 100644 --- a/lily/include/note-column.hh +++ b/lily/include/note-column.hh @@ -36,7 +36,6 @@ public: static Grob *accidentals (Grob *me); static Slice head_positions_interval (Grob *me); static Grob *first_head (Grob *me); - static Interval calc_main_extent (Grob *me); static Grob *get_rest (Grob *me); static void set_stem (Grob *me, Grob *); static void add_head (Grob *me, Grob *); @@ -46,6 +45,8 @@ public: static Item *get_stem (Grob *); static Item *get_flag (Grob *); + + DECLARE_SCHEME_CALLBACK (calc_main_extent, (SCM)); }; #endif // NOTE_COLUMN_HH diff --git a/lily/note-column.cc b/lily/note-column.cc index 6557ebd7ef243932e06b736031881ef015467eb8..8eebe0067b99e359095bc4a0acaa439abd5940e0 100644 --- a/lily/note-column.cc +++ b/lily/note-column.cc @@ -37,6 +37,10 @@ /* TODO: figure out if we can prune this class. This is just an annoying layer between (rest)collision & (note-head + stem) + + TODO: If it's not pruned altogether, replace most of these + functions with storage in objects, either in the engraver or + via object-callbacks. --JeanAS */ bool @@ -163,9 +167,11 @@ Note_column::first_head (Grob *me) (i.e. excluding any suspended noteheads), or extent of the rest (if there are no heads). */ -Interval -Note_column::calc_main_extent (Grob *me) +MAKE_SCHEME_CALLBACK (Note_column, calc_main_extent, 1); +SCM +Note_column::calc_main_extent (SCM smob) { + auto *me = unsmob (smob); Grob *main_head = 0; if (get_stem (me)) main_head = first_head (me); @@ -180,9 +186,9 @@ Note_column::calc_main_extent (Grob *me) ? main_head : unsmob (get_object (me, "rest")); - return main_item - ? main_item->extent (me, X_AXIS) - : Interval (0, 0); + return to_scm (main_item + ? main_item->extent (me, X_AXIS) + : Interval (0, 0)); } /* @@ -247,6 +253,7 @@ ADD_INTERFACE (Note_column, "horizontal-shift " "ignore-collision " "note-heads " + "main-extent " "rest " "rest-collision " "stem " diff --git a/lily/self-alignment-interface.cc b/lily/self-alignment-interface.cc index 48c608b7e40a78300ef4d14fbf57c40b55325cd5..5d959c239033c4ebe07fe2661f375065b2c3202c 100644 --- a/lily/self-alignment-interface.cc +++ b/lily/self-alignment-interface.cc @@ -129,7 +129,7 @@ Self_alignment_interface::aligned_on_parent (Grob *me, Axis a) { if (from_scm (get_property (me, "X-align-on-main-noteheads")) && has_interface (him)) - he = Note_column::calc_main_extent (him); + he = from_scm (get_property (him, "main-extent")); else he = him->extent (him, a); } diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index 82df3786bd4344a9cf42ac81e4f898d007ce1880..8e26c7cd02cb20eb81de5d86d5b05e82005d4ff6 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -633,6 +633,10 @@ visual output is influenced by changes to ;;; ;;; m ;;; + (main-extent ,number-pair? "The horizontal extent of a +@code{NoteColumn} grob without taking suspended @code{NoteHead} +grobs into account (i.e., @code{NoteHead}s forced into the unnatural +direction of the @code{Stem} because of a chromatic clash).") (max-beam-connect ,integer? "Maximum number of beams to connect to beams from this stem. Further beams are typeset as beamlets.") (maximum-gap ,number? "Maximum value allowed for @code{gap} diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index 86243b27ce4e124105390c69c0f95d0038b4f20c..718d64ecc2433c18a0b0f0fb674d357c913d254b 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -1914,6 +1914,7 @@ (axes . (,X ,Y)) (bound-alignment-interfaces . (rhythmic-head-interface stem-interface)) (horizontal-skylines . ,ly:separation-item::calc-skylines) + (main-extent . ,ly:note-column::calc-main-extent) (skyline-vertical-padding . 0.15) (X-extent . ,ly:axis-group-interface::width) (Y-extent . ,axis-group-interface::height) diff --git a/scm/output-lib.scm b/scm/output-lib.scm index a20f75e30272b470fe87338a8ce908d236397c91..70cd63cdd81a9d75ec98dd8ea4f27b67cd49cc5a 100644 --- a/scm/output-lib.scm +++ b/scm/output-lib.scm @@ -2433,32 +2433,6 @@ representing the amount a string is bent." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; DurationLine -;; helper -(define-public (note-column::main-extent grob) - "Return extent of the noteheads in the @q{main column} (i.e., excluding any -suspended noteheads), or extent of the rest (if there are no heads)." - ;; Partial rewrite of a C++-procedure - (let* ((note-heads (ly:grob-object grob 'note-heads #f)) - ;; stem is currently not needed, for now we let it in, commented - ;(stem (ly:grob-object grob 'stem)) - (rest (ly:grob-object grob 'rest #f))) - (cond (note-heads - (let (;; get the cdr from all note-heads-extents, where the car - ;; is zero - (n-h-right-coords - (filter-map - (lambda (n-h) - (let ((ext (ly:grob-extent n-h grob X))) - (and (= (car ext) 0) (cdr ext)))) - (ly:grob-array->list note-heads)))) - ;; better be paranoid, find the max of n-h-right-coords and return - ;; a pair with (cons 0 ) - (cons 0.0 (reduce max 0 n-h-right-coords)))) - (rest - (ly:grob-extent rest grob X)) - ;; better be paranoid again - (else '(0 . 0))))) - ;;;; We separate coding the stencil of DurationLine into ;;;; - coding arrow-stencil ;;;; - coding hook-stencil @@ -2564,6 +2538,8 @@ The final stencil is adjusted vertically using @var{staff-space}, which is ;;;; DurationLine start ;;;;;;;;;;;;;;;;;;;;;;;; (left-bound (ly:spanner-bound grob LEFT)) + ;; FIXME: misnamed because it's sometimes a PaperColumn. + ;; Investigate. --JeanAS (left-note-column (if (note-head-or-rest? left-bound) (ly:grob-parent left-bound X) @@ -2585,9 +2561,8 @@ The final stencil is adjusted vertically using @var{staff-space}, which is ;; of the whole NoteColumn-width and main NoteColumn-width. ;; Depending on the stem-direction this happens to the left or right. - (left-note-column-main-X-ext - (note-column::main-extent left-note-column)) + (ly:grob-property left-note-column 'main-extent '(0 . 0))) ;;;; ;;;; adjust for DotColumn of left NoteColumn ;;;; @@ -2669,6 +2644,8 @@ The final stencil is adjusted vertically using @var{staff-space}, which is ;;;;;;;;;;;;;;;;;;;;;;;; ;; NB `right-bound' may not always be a NoteColumn (right-bound (ly:spanner-bound grob RIGHT)) + ;; FIXME: misnamed because it's sometimes a PaperColumn + ;; or BarLine. Investigate. --JeanAS (right-note-column (if (note-head-or-rest? right-bound) (ly:grob-parent right-bound X) @@ -2678,7 +2655,7 @@ The final stencil is adjusted vertically using @var{staff-space}, which is ;; value to adjust the end of DurationLine. ;; Applied later while calculating `right-end' (right-bound-X-ext (ly:grob-extent right-note-column right-bound X)) - (right-bound-main-X-ext (note-column::main-extent right-note-column)) + (right-bound-main-X-ext (ly:grob-property right-note-column 'main-extent '(0 . 0))) (adjust-right-for-suspended-heads-and-broken-items ;; Could be simple (if ...) (cond ;; compensate suspended heads if present