2009/5/20 Francisco Vila <paconet....@gmail.com>: > 2009/5/20 Francisco Vila <paconet....@gmail.com>: >> The key code is this. Given a (big) amount of time I could figure out >> how it works and try to improve it. >> >> http://git.savannah.gnu.org/gitweb/?p=lilypond.git;a=blobdiff;f=lily/system-start-text.cc;h=c99f150fed;hp=494ab1;hb=b12cf254;hpb=4d0abb92 > > Maybe it's not that easy. If the right padding is intended to put the > stencil to the rightmost side, the problem is that the extent of the > brace (if any) is unknown at this moment.
The InstrumentName has to be attached to the left edge of the VerticalAxisGroup (i.e., the Staff), so the only way to position it is to apply padding on its right hand side; this moves it away from the system. In order to prevent collisions between instrument names and PianoStaff braces, the system start delimiters are added as side-support-elements of each InstrumentName, thus leading to a variation in support extents depending on where each InstrumentName is attached to the system. I think the simplest way to deal with this is to split it into two parts: 1. Remove the side-support-elements so every InstrumentName has the same alignment anchor in the X-axis (i.e., the left edge of each stave). This is a simple matter of removing the acknowledger for system-start-text in the System_start_delimiter_engraver. 2. Calculate the combined extents of all the system start delimiters in a system, then apply an X-offset correction to each InstrumentName. This ensures that there wil be no collisions between any InstrumentName and SystemStartBrace/Bracket/Bar/Square. Since we can access the System grob from the InstrumentName (via ly:grob-system), it's possible to retrieve the grob-array 'elements which will include all the system start delimiter grobs. From the array we can cherry pick the delimiters by checking the interfaces list for system-start-delimiter-interface. By uniting their horizontal extents it's possible to get an offset which represents the width of the set of delimiters attached to the most deeply nested stave. I've attached a proof of concept patch together with an image demonstrating left-, centre- and right-aligned instrument names. Regards, Neil
<<attachment: instrument-name-test.png>>
From 6bfeefe1e0f84b39039bf893195eebeca08681c1 Mon Sep 17 00:00:00 2001 From: Neil Puttock <n.putt...@gmail.com> Date: Fri, 22 May 2009 23:40:25 +0100 Subject: [PATCH] Correctly aligned instrument names. --- lily/system-start-delimiter-engraver.cc | 10 ---------- scm/define-grobs.scm | 7 ++++++- scm/output-lib.scm | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/lily/system-start-delimiter-engraver.cc b/lily/system-start-delimiter-engraver.cc index ea4fcf3..fa8ea2d 100644 --- a/lily/system-start-delimiter-engraver.cc +++ b/lily/system-start-delimiter-engraver.cc @@ -176,7 +176,6 @@ protected: Bracket_nesting_group *nesting_; DECLARE_ACKNOWLEDGER (system_start_delimiter); - DECLARE_ACKNOWLEDGER (system_start_text); DECLARE_ACKNOWLEDGER (staff_symbol); void process_music (); @@ -229,14 +228,6 @@ System_start_delimiter_engraver::acknowledge_staff_symbol (Grob_info inf) } } - - -void -System_start_delimiter_engraver::acknowledge_system_start_text (Grob_info inf) -{ - nesting_->add_support (inf.grob ()); -} - void System_start_delimiter_engraver::acknowledge_system_start_delimiter (Grob_info inf) { @@ -247,7 +238,6 @@ System_start_delimiter_engraver::acknowledge_system_start_delimiter (Grob_info i ADD_ACKNOWLEDGER (System_start_delimiter_engraver, staff_symbol); ADD_ACKNOWLEDGER (System_start_delimiter_engraver, system_start_delimiter); -ADD_ACKNOWLEDGER (System_start_delimiter_engraver, system_start_text); ADD_TRANSLATOR (System_start_delimiter_engraver, /* doc */ diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index 58a6440..fd022f1 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -844,7 +844,12 @@ . ( (padding . 0.3) (stencil . ,ly:system-start-text::print) - (X-offset . ,ly:side-position-interface::x-aligned-side) + (X-offset . ,(ly:make-simple-closure + `(,- + ,(ly:make-simple-closure + (list ly:side-position-interface::x-aligned-side)) + ,(ly:make-simple-closure + (list instrument-name::calc-combined-delimiters-offset))))) (direction . ,LEFT) (self-alignment-Y . ,CENTER) (self-alignment-X . ,CENTER) diff --git a/scm/output-lib.scm b/scm/output-lib.scm index fdd5253..17cae6b 100644 --- a/scm/output-lib.scm +++ b/scm/output-lib.scm @@ -737,3 +737,25 @@ centered, X==1 is at the right, X == -1 is at the left." note-head-location))) 0.0)) 0.0)))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; system start texts + +(define (instrument-name::calc-combined-delimiters-offset grob) + (let* ((system (ly:grob-system grob)) + (elements (ly:grob-object system 'elements)) + (common (ly:grob-common-refpoint-of-array system elements X)) + (total-ext '(+inf.0 . -inf.0))) + + (let loop ((l (ly:grob-array-length elements))) + (if (> l 0) + (let* ((elt (ly:grob-array-ref elements (1- l))) + (ifs (ly:grob-interfaces elt))) + + (if (memq 'system-start-delimiter-interface ifs) + (let ((dims (ly:grob-extent elt common X))) + (if (interval-sane? dims) + (set! total-ext (interval-union total-ext dims))))) + (loop (1- l))))) + + (interval-length total-ext))) \ No newline at end of file -- 1.6.0.4
_______________________________________________ lilypond-devel mailing list lilypond-devel@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-devel