From 6ba180c8956f07784b64f1a0d96c2a7b93b8c221 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 5 Feb 2006 18:19:16 +0000 Subject: [PATCH] * lily/system-start-delimiter.cc (print): allow style = text too. * lily/system-start-delimiter-engraver.cc (acknowledge_system_start_text): new function, also add add to support of system-start-text (instrument names). This fixes instrument names on piano staves. * lily/instrument-name-engraver.cc: rewrite. Use system-start-delimiter approach. This save memory and cpu. * scm/define-grobs.scm (all-grob-descriptions): remove instrument-name from break-alignment. * mf/GNUmakefile ($(NCSB_TTFS)): depend on pfx2ttf script too. --- ChangeLog | 19 ++ input/regression/instrument-name-hara-kiri.ly | 21 ++ input/regression/instrument-name.ly | 10 +- lily/include/system-start-delimiter.hh | 2 + lily/instrument-name-engraver.cc | 214 +++++------------- lily/system-start-delimiter-engraver.cc | 22 +- lily/system-start-delimiter.cc | 23 +- ly/engraver-init.ly | 10 +- mf/GNUmakefile | 2 +- scm/define-grob-properties.scm | 1 + scm/define-grobs.scm | 60 ++--- 11 files changed, 165 insertions(+), 219 deletions(-) create mode 100644 input/regression/instrument-name-hara-kiri.ly diff --git a/ChangeLog b/ChangeLog index a627649398..4fd6f43b93 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2006-02-05 Han-Wen Nienhuys + + * lily/system-start-delimiter.cc (print): allow style = text too. + + * lily/system-start-delimiter-engraver.cc + (acknowledge_system_start_text): new function, also add add to + support of system-start-text (instrument names). This fixes + instrument names on piano staves. + + * lily/instrument-name-engraver.cc: rewrite. Use + system-start-delimiter approach. This save memory and cpu. + + * scm/define-grobs.scm (all-grob-descriptions): remove + instrument-name from break-alignment. + + * mf/GNUmakefile ($(NCSB_TTFS)): depend on pfx2ttf script too. + 2006-02-05 Jan Nieuwenhuizen * stepmake/stepmake/generic-vars.make (LOOP): Add PLUS to keep -j @@ -14,6 +31,8 @@ 2006-02-05 Han-Wen Nienhuys + * VERSION (PACKAGE_NAME): 2.7.31 + * scm/framework-ps.scm (dump-stencil-as-EPS): don't hardcode left EPS edge at 0, but take minimum with left-overshoot. This fixes cut off system start delims. diff --git a/input/regression/instrument-name-hara-kiri.ly b/input/regression/instrument-name-hara-kiri.ly new file mode 100644 index 0000000000..1b77506e7d --- /dev/null +++ b/input/regression/instrument-name-hara-kiri.ly @@ -0,0 +1,21 @@ + +\header { + + texidoc = "@code{PianoStaff.instrument} and +@code{PianoStaff.instr} are removed when the staves are killed off. + +In this example, the 2nd staff (marked by the barnumber 2) disappears +as does the instrument name. " + +} + +\version "2.7.31" + + \new PianoStaff << + \new Staff { + \override Staff.VerticalAxisGroup #'remove-empty = ##t + \set PianoStaff.instrument="up" + \set PianoStaff.instr="u" + c'1\break R + } + >> diff --git a/input/regression/instrument-name.ly b/input/regression/instrument-name.ly index 0851304124..3590326fde 100644 --- a/input/regression/instrument-name.ly +++ b/input/regression/instrument-name.ly @@ -20,9 +20,13 @@ PianoStaff. \context PianoStaff << \context Staff = "treble" { - \set PianoStaff.instrument = "Piano " - \set Staff.instrument = "Right " { c''4 }} - \context Staff = "bass" { \set Staff.instrument = "Left " \clef bass c4 }>> + \set PianoStaff.instrument = "Piano" + \set Staff.instrument = "Right" { c''4 }} + \context Staff = "bass" { + \set Staff.instrument = "Left" + \clef bass c4 + } +>> diff --git a/lily/include/system-start-delimiter.hh b/lily/include/system-start-delimiter.hh index 3bcb397201..863ff1c523 100644 --- a/lily/include/system-start-delimiter.hh +++ b/lily/include/system-start-delimiter.hh @@ -27,6 +27,8 @@ public: static Stencil staff_brace (Grob *, Real); static Stencil simple_bar (Grob *, Real); static Stencil line_bracket (Grob *, Real); + static Stencil text (Grob *, Real); + }; #endif /* SYSTEM_START_DELIMITER_HH */ diff --git a/lily/instrument-name-engraver.cc b/lily/instrument-name-engraver.cc index 0620ae8cfb..e6850fba0b 100644 --- a/lily/instrument-name-engraver.cc +++ b/lily/instrument-name-engraver.cc @@ -7,204 +7,98 @@ */ #include "engraver.hh" -#include "bar-line.hh" -#include "system-start-delimiter.hh" +#include "spanner.hh" +#include "pointer-group-interface.hh" #include "side-position-interface.hh" -#include "align-interface.hh" #include "axis-group-interface.hh" -#include "context.hh" -#include "text-interface.hh" -#include "grob-array.hh" +#include "align-interface.hh" #include "translator.icc" -class Instrument_name_engraver : public Engraver +class New_instrument_name_engraver : public Engraver { - bool first_; public: - TRANSLATOR_DECLARATIONS (Instrument_name_engraver); + TRANSLATOR_DECLARATIONS (New_instrument_name_engraver); protected: - Grob *text_; + Spanner *text_spanner_; - virtual void create_text (); - virtual void initialize (); - - DECLARE_ACKNOWLEDGER (bar_line); + virtual void finalize (); DECLARE_ACKNOWLEDGER (axis_group); - - void stop_translation_timestep (); void process_music (); }; -Instrument_name_engraver::Instrument_name_engraver () +New_instrument_name_engraver::New_instrument_name_engraver () { - text_ = 0; - first_ = true; + text_spanner_ = 0; } void -Instrument_name_engraver::initialize () +New_instrument_name_engraver::process_music () { - context ()->set_property ("instrumentSupport", SCM_EOL); -} - -void -Instrument_name_engraver::stop_translation_timestep () -{ - if (text_) + if (!text_spanner_) { - SCM support = get_property ("instrumentSupport"); - text_->set_object ("side-support-elements", - grob_list_to_grob_array (support)); - - /* - Hack to get texts on piano staves to disappear. - */ - if (!text_->get_parent (Y_AXIS) - && scm_is_pair (support)) + SCM long_text = get_property ("instrument"); + SCM short_text = get_property ("instr"); + + if (! (scm_is_string (long_text) + || scm_is_string (short_text))) + { + long_text = get_property ("vocalName"); + short_text = get_property ("vocNam"); + } + + if (scm_is_string (long_text) + || scm_is_string (short_text)) { - Axis_group_interface::add_element (unsmob_grob (scm_car (support)), - text_); + text_spanner_ = make_spanner ("InstrumentName", SCM_EOL); + text_spanner_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn"))); + text_spanner_->set_property ("text", short_text); + text_spanner_->set_property ("long-text", long_text); } - text_ = 0; } - - first_ = false; } void -Instrument_name_engraver::create_text () +New_instrument_name_engraver::acknowledge_axis_group (Grob_info info) { - if (text_) - return; - - SCM txt = get_property ("instrument"); - - if (now_mom () > Moment (0)) - txt = get_property ("instr"); - /* - UGH. - */ - if (txt == SCM_EOL) - return; - - text_ = make_item ("InstrumentName", SCM_EOL); - - if (text_->get_property ("text") != txt) - text_->set_property ("text", txt); -} - -void -Instrument_name_engraver::acknowledge_bar_line (Grob_info info) -{ - (void) info; - create_text (); -} - -void -Instrument_name_engraver::acknowledge_axis_group (Grob_info info) -{ - /* - Ugh - typechecking for pedal and dynamic sucks. - */ - if (dynamic_cast (info.grob ()) - && (info.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface")) - || info.grob ()->internal_has_interface (ly_symbol2scm ("piano-pedal-interface")))) - return; - - /* - Hang the instrument names on the staves, but not on the alignment - groups enclosing that staff. The alignment has no real location, - but is only a vehicle for the placement routine it contains, and - therefore the location of its refpoint won't be very useful. - - We could also just use stavesFound, but lets keep this working - without staffs as well. - */ - if (dynamic_cast (info.grob ()) - && ((Axis_group_interface::has_interface (info.grob ()) - && Axis_group_interface::has_axis (info.grob (), Y_AXIS)))) + if (text_spanner_ + && dynamic_cast (info.grob ()) + && Axis_group_interface::has_axis (info.grob (), Y_AXIS) + && (!Align_interface::has_interface (info.grob ()))) { - if (!Align_interface::has_interface (info.grob ())) - { - SCM nl = scm_cons (info.grob ()->self_scm (), - get_property ("instrumentSupport")); - - context ()->set_property ("instrumentSupport", nl); - } + Grob *staff = info.grob(); + Pointer_group_interface::add_grob (text_spanner_, ly_symbol2scm ("elements"), staff); + Side_position_interface::add_support (text_spanner_, staff); } } void -Instrument_name_engraver::process_music () +New_instrument_name_engraver::finalize () { - /* - Also create text if barlines in other groups. This allows - a name to be attached to lyrics or chords. - */ - if (scm_is_string (get_property ("whichBar")) - || first_) - create_text (); + if (text_spanner_) + { + text_spanner_->set_bound (RIGHT, + unsmob_grob (get_property ("currentCommandColumn"))); + } } #include "translator.icc" -ADD_ACKNOWLEDGER (Instrument_name_engraver, bar_line); -ADD_ACKNOWLEDGER (Instrument_name_engraver, axis_group); - -ADD_TRANSLATOR (Instrument_name_engraver, - /* doc */ " Prints the name of the instrument (specified by " - " @code{Staff.instrument} and @code{Staff.instr}) " - "at the left of the staff. ", - /* create */ "InstrumentName", - /* accept */ "", - /* read */ "instrument instr", - /* write */ ""); - -/****************************************************************/ - -class Vocal_name_engraver : public Instrument_name_engraver -{ -public: - TRANSLATOR_DECLARATIONS (Vocal_name_engraver); - virtual void create_text (); -}; - -Vocal_name_engraver::Vocal_name_engraver () -{ -} - -void -Vocal_name_engraver::create_text () -{ - if (text_) - return; - - SCM txt = get_property ("vocalName"); - - if (now_mom () > Moment (0)) - txt = get_property ("vocNam"); - - /* - UGH. - */ - if (txt == SCM_EOL) - return; +ADD_ACKNOWLEDGER (New_instrument_name_engraver, axis_group); - text_ = make_item ("VocalName", SCM_EOL); +ADD_TRANSLATOR (New_instrument_name_engraver, - if (text_->get_property ("text") != txt) - text_->set_property ("text", txt); -} - -ADD_ACKNOWLEDGER (Vocal_name_engraver, bar_line); -ADD_ACKNOWLEDGER (Vocal_name_engraver, axis_group); -ADD_TRANSLATOR (Vocal_name_engraver, - /* doc */ " Prints the name of the a lyric voice (specified by " - " @code{Staff.vocalName} and @code{Staff.vocNam}) " - "at the left of the staff. ", - /* create */ "VocalName", + /* doc */ + "Creates a system start text for instrument or vocal names.", + + /* create */ + "InstrumentName ", + /* accept */ "", - /* read */ "vocNam vocalName", + + /* read */ + "vocNam vocalName instrument instr " + "currentCommandColumn", + /* write */ ""); diff --git a/lily/system-start-delimiter-engraver.cc b/lily/system-start-delimiter-engraver.cc index 9808148fd9..bbab59328d 100644 --- a/lily/system-start-delimiter-engraver.cc +++ b/lily/system-start-delimiter-engraver.cc @@ -178,6 +178,7 @@ protected: Bracket_nesting_group *nesting_; DECLARE_ACKNOWLEDGER (system_start_delimiter); + DECLARE_ACKNOWLEDGER (system_start_text); DECLARE_ACKNOWLEDGER (staff_symbol); void process_music (); @@ -189,8 +190,6 @@ System_start_delimiter_engraver::System_start_delimiter_engraver () nesting_ = 0; } - - void System_start_delimiter_engraver::process_music () { @@ -231,6 +230,13 @@ 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) { @@ -241,10 +247,18 @@ 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 */ "Creates a system start delimiter (ie. SystemStart@{Bar, Brace, Bracket@} spanner", - /* create */ "SystemStartSquare SystemStartBrace SystemStartBracket SystemStartBar", + /* create */ "SystemStartSquare " + "SystemStartBrace " + "SystemStartBracket " + "SystemStartBar", /* accept */ "", - /* read */ "systemStartDelimiter systemStartDelimiterHierarchy currentCommandColumn", + /* read */ + "systemStartDelimiter " + "systemStartDelimiterHierarchy " + "currentCommandColumn", + /* write */ ""); diff --git a/lily/system-start-delimiter.cc b/lily/system-start-delimiter.cc index e7b1269e92..73b350976e 100644 --- a/lily/system-start-delimiter.cc +++ b/lily/system-start-delimiter.cc @@ -7,7 +7,7 @@ */ #include "system-start-delimiter.hh" - +#include "text-interface.hh" #include "all-font-metrics.hh" #include "axis-group-interface.hh" #include "font-interface.hh" @@ -75,6 +75,23 @@ System_start_delimiter::line_bracket (Grob *me, Real height) return vline; } +Stencil +System_start_delimiter::text (Grob *me_grob, Real h) +{ + Spanner *me = dynamic_cast (me_grob); + SCM t = me->get_property ("text"); + if (me->get_break_index () == 0) + t = me->get_property ("long-text"); + + + SCM chain = Font_interface::text_font_alist_chain (me); + + SCM scm_stencil = Text_interface::interpret_markup (me->layout ()->self_scm (), chain, t); + if (Stencil *p = unsmob_stencil (scm_stencil)) + return *p; + return Stencil(); +} + Stencil System_start_delimiter::simple_bar (Grob *me, Real h) { @@ -130,6 +147,8 @@ System_start_delimiter::print (SCM smob) m = simple_bar (me, len); else if (glyph_sym == ly_symbol2scm ("line-bracket")) m = line_bracket (me, len); + else if (glyph_sym == ly_symbol2scm ("text")) + m = text (me, len); m.translate_axis (ext.center (), Y_AXIS); return m.smobbed_copy (); @@ -181,5 +200,7 @@ ADD_INTERFACE (System_start_delimiter, "system-start-delimiter-interface", /* properties */ "collapse-height " "style " + "text " + "long-text " "thickness " ); diff --git a/ly/engraver-init.ly b/ly/engraver-init.ly index 1f8aca50b5..f60ff00515 100644 --- a/ly/engraver-init.ly +++ b/ly/engraver-init.ly @@ -35,7 +35,7 @@ \consists "Rest_collision_engraver" \consists "Accidental_engraver" \consists "Piano_pedal_engraver" - \consists "Instrument_name_engraver" + \consists "New_instrument_name_engraver" \consists "String_number_engraver" \consists "Axis_group_engraver" @@ -144,7 +144,7 @@ contained staves are not connected vertically." \consists "Staff_symbol_engraver" \consists "Pitch_squash_engraver" \consists "Time_signature_engraver" - \consists "Instrument_name_engraver" + \consists "New_instrument_name_engraver" \consists "Axis_group_engraver" \accepts "Voice" @@ -284,7 +284,7 @@ contained staves are not connected vertically." \override VerticalAlignment #'self-alignment-Y = #0 \consists "Vertical_align_engraver" - \consists "Instrument_name_engraver" + \consists "New_instrument_name_engraver" instrument = #'() instr = #'() @@ -343,14 +343,14 @@ printing of a single line of lyrics. " \consists "Extender_engraver" \consists "Hyphen_engraver" \consists "Stanza_number_engraver" - \consists "Vocal_name_engraver" + \consists "New_instrument_name_engraver" \consists "Skip_event_swallow_translator" \consists "Font_size_engraver" \consists "Hara_kiri_engraver" \override VerticalAxisGroup #'remove-first = ##t \override VerticalAxisGroup #'remove-empty = ##t \override SeparationItem #'padding = #0.2 - + \override InstrumentName #'Y-offset = #0.0 %% make sure that barlines aren't collapsed, when %% Bar_engraver is there. diff --git a/mf/GNUmakefile b/mf/GNUmakefile index 8ff1afa9ba..8bc4bdbb56 100644 --- a/mf/GNUmakefile +++ b/mf/GNUmakefile @@ -247,7 +247,7 @@ $(outdir)/%.enc.in: %.enc cp $< $@ -$(NCSB_TTFS): $(addsuffix .pfb,$(addprefix $(NCSB_DIR)/,$(NCSB_SOURCE_FILES))) +$(NCSB_TTFS): $(addsuffix .pfb,$(addprefix $(NCSB_DIR)/,$(NCSB_SOURCE_FILES))) $(buildscript-dir)/pfx2ttf.fontforge $(foreach i,$(NCSB_SOURCE_FILES), \ $(FONTFORGE) -script $(buildscript-dir)/pfx2ttf.fontforge \ $(NCSB_DIR)/$(i).pfb $(NCSB_DIR)/$(i).afm $(outdir)/ && ) true diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index 5d530ab5d2..1c0396967d 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -274,6 +274,7 @@ column is the start of a system.") (line-count ,integer? "The number of staff lines.") (line-positions ,list? "Vertical positions of staff lines.") + (long-text ,markup? "Text markup. See @usermanref{Text markup}.") (measure-length ,ly:moment? "Length of a measure. Used in some spacing situations.") diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index 4d491af89e..4ba3869e69 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -316,7 +316,7 @@ (positioning-done . ,ly:break-align-interface::calc-positioning-done) (X-extent . ,ly:axis-group-interface::width) (break-align-orders . ;; end of line - #((instrument-name + #(( left-edge ambitus breathing-sign @@ -328,7 +328,7 @@ custos) ;; unbroken - (instrument-name + ( left-edge ambitus breathing-sign @@ -340,7 +340,7 @@ time-signature custos) ;; begin of line - (instrument-name + ( left-edge ambitus breathing-sign @@ -724,31 +724,18 @@ spanner-interface)))))) (InstrumentName . ( - (breakable . #t) - (Y-offset . ,(ly:make-simple-closure - `(,+ ,(ly:make-simple-closure - (list ly:self-alignment-interface::y-aligned-on-self)) - ,(ly:make-simple-closure - (list ly:side-position-interface::y-aligned-on-support-refpoints))))) - - ;; This direction is for aligned_on_support_refpoints - ;; (?) --hwn - (direction . ,CENTER) - (space-alist . ( - (left-edge . (extra-space . 1.0)))) - - (self-alignment-Y . 0) - (stencil . ,ly:text-interface::print) - (break-align-symbol . instrument-name) - (break-visibility . ,begin-of-line-visible) - (baseline-skip . 2) - (side-axis . ,X) - (meta . ((class . Item) - (interfaces . (font-interface - self-alignment-interface + (style . text) + (padding . 0.3) + (stencil . ,ly:system-start-delimiter::print) + (collapse-height . 5.0) + (X-offset . ,ly:side-position-interface::x-aligned-side) + (direction . ,LEFT) + (Y-offset . -0.75) + (Y-extent . #f) + (meta . ((class . Spanner) + (interfaces . (system-start-text-interface side-position-interface - text-interface - break-aligned-interface)))))) + font-interface)))))) (KeyCancellation . ( @@ -1606,6 +1593,7 @@ side-position-interface font-interface)))))) + (SystemStartSquare . ( (Y-extent . #f) @@ -1901,24 +1889,6 @@ hara-kiri-group-interface vertically-spaceable-interface)))))) - (VocalName - . ( - (breakable . #t) - (Y-offset . ,ly:side-position-interface::y-aligned-on-support-refpoints) - (direction . ,CENTER) - (space-alist . ((left-edge . (extra-space . 1.0)))) - (break-align-symbol . instrument-name) - (stencil . ,ly:text-interface::print) - (break-align-symbol . clef) - (break-visibility . ,begin-of-line-visible) - (baseline-skip . 2) - (side-axis . ,Y) - (meta . ((class . Item) - (interfaces . (font-interface - self-alignment-interface - side-position-interface - text-interface - break-aligned-interface)))))) (VoltaBracket . ( -- 2.39.5