From 21a1e3b8267fd76ff261ed9f01e833d5d04703e7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Janek=20Warcho=C5=82?= Date: Wed, 3 Apr 2013 21:46:56 +0200 Subject: [PATCH] Issue 3186: fix clef transposition alignment Until now, numbers indicating clef transposition (for example in \clef "G_8") were simply centered against the clef glyph. This was not optimal, because clef glyphs aren't symmetrical - for example the hook of the treble clef isn't exactly at its horizontal center, and thus the octavation number shouldn't be exactly centered. This commit allows to specify alignment separately for each clef, taking into account their individual characteristics. Alignments are stored in clef-alignments property. --- .../clef-transposition-placement.ly | 46 ++++++++++-- lily/clef-modifier.cc | 70 +++++++++++++++++++ scm/define-grob-interfaces.scm | 2 +- scm/define-grob-properties.scm | 2 + scm/define-grobs.scm | 5 +- 5 files changed, 116 insertions(+), 9 deletions(-) create mode 100644 lily/clef-modifier.cc diff --git a/input/regression/clef-transposition-placement.ly b/input/regression/clef-transposition-placement.ly index 119e00a903..2255e9be20 100644 --- a/input/regression/clef-transposition-placement.ly +++ b/input/regression/clef-transposition-placement.ly @@ -3,16 +3,48 @@ \header { texidoc="Transposition symbols should be correctly positioned -close to the parent clef." +close to the parent clef. Horizontal alignment is fine-tuned +for standard C, G and F clefs: for example, downwards transposition +of a G clef should be centered exactly under the middle of clef hook. +For clefs that don't have fine-tuned alignment the transposition +number should be centered." } + +% use huge staff-size to see the tiny differencies better. +#(set-global-staff-size 35) + +clefVariations = +#(define-music-function (parser location type)(string?) + #{ + \once \omit Staff.Clef s4 + \override Staff.Clef.full-size-change = ##t + \clef #(string-append type "8") s4 + \clef #(string-append type "15") s4 + \clef #(string-append type "(8)") s4 + \clef #(string-append type "(141)") s4 + % change clefs are omitted - too similar to regular ones + \cueClef #(string-append type "8") s4 + \cueClef #(string-append type "15") s4 + \cueClef #(string-append type "(8)") s4 + \cueClef #(string-append type "(141)") s4 + #}) + +\markup "Even the smallest positioning changes may indicate a problem!" \score { << - \new Staff { \clef "G^8" g''1 } - \new Staff { \clef "F^8" c'1 } - \new Staff { \clef "C^8" c''1 } - \new Staff { \clef "G_8" g1 } - \new Staff { \clef "F_8" c,1 } - \new Staff { \clef "C_8" c1 } + \new Staff { \clefVariations "C_" } + \new Staff { \clefVariations "C^" } + \new Staff { \clefVariations "G_" } + \new Staff { \clefVariations "G^" } + \new Staff { \clefVariations "F_" } + \new Staff { \clefVariations "F^" } >> } + +\layout { + \context { + \Staff + \remove Time_signature_engraver + } +} \ No newline at end of file diff --git a/lily/clef-modifier.cc b/lily/clef-modifier.cc new file mode 100644 index 0000000000..6d802ad271 --- /dev/null +++ b/lily/clef-modifier.cc @@ -0,0 +1,70 @@ +/* + This file is part of LilyPond, the GNU music typesetter. + + Copyright (C) 2014--2014 Janek Warchoł + + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . +*/ + +#include "item.hh" + +struct Clef_modifier +{ + DECLARE_SCHEME_CALLBACK (calc_parent_alignment, (SCM)); + DECLARE_GROB_INTERFACE (); +}; + +MAKE_SCHEME_CALLBACK (Clef_modifier, calc_parent_alignment, 1) +SCM +Clef_modifier::calc_parent_alignment (SCM smob) +{ + Grob *me = Grob::unsmob (smob); + Grob *clef = me->get_parent (X_AXIS); + string full_clef_name = ly_scm2string (clef->get_property ("glyph")); + + int separator_position = full_clef_name.find ('.'); + string clef_type = full_clef_name.substr (separator_position + 1, + separator_position + 2); + + // find entry with keyname clef_type in clef-alignments + SCM alist_entry = scm_assq (ly_symbol2scm (clef_type.c_str ()), + me->get_property ("clef-alignments")); + + if (scm_is_pair (alist_entry)) + { + SCM entry_value = scm_cdr (alist_entry); + // the value should be a pair of numbers - first is the alignment + // for modifiers below the clef, second for those above. + if (scm_is_pair (entry_value)) + if (robust_scm2dir (me->get_property ("direction"), DOWN) == DOWN) + return scm_car (entry_value); + else + return scm_cdr (entry_value); + + else // default alignment = centered + return scm_from_double (0); + } + else // default alignment = centered + return scm_from_double (0); +} + +ADD_INTERFACE (Clef_modifier, + "The number describing transposition of the clef, placed below\n" + "or above clef sign. Usually this is 8 (octave transposition)\n" + "or 15 (two octaves), but LilyPond allows any integer here.", + + /* properties */ + "clef-alignments " + ); + diff --git a/scm/define-grob-interfaces.scm b/scm/define-grob-interfaces.scm index 2c3290a4c8..e07006e350 100644 --- a/scm/define-grob-interfaces.scm +++ b/scm/define-grob-interfaces.scm @@ -83,7 +83,7 @@ found in @file{scm/bar-line.scm}. "The number describing transposition of the clef, placed below or above clef sign. Usually this is 8 (octave transposition) or 15 (two octaves), but LilyPond allows any integer here." - '()) + '(clef-alignments)) (ly:add-interface 'dynamic-interface diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index 35f0074a88..ff714fc04d 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -179,6 +179,8 @@ on each chord to the height of the chord plus @code{chord-dots-limit} staff-positions.") (circled-tip ,boolean? "Put a circle at start/@/end of hairpins (al/@/del niente).") + (clef-alignments ,list? "An alist of parent-alignments +that should be used for clef modifiers with various clefs") (clip-edges ,boolean? "Allow outward pointing beamlets at the edges of beams?") (collapse-height ,ly:dimension? "Minimum height of system start diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index 53401d3a42..813c93b131 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -573,11 +573,14 @@ . ( (break-visibility . ,(grob::inherit-parent-property X 'break-visibility)) + (clef-alignments . ((G . (-0.2 . 0.1)) + (F . (-0.3 . -0.2)) + (C . (0 . 0)))) (color . ,(grob::inherit-parent-property X 'color)) (font-shape . italic) (font-size . -4) - (parent-alignment-X . ,CENTER) + (parent-alignment-X . ,ly:clef-modifier::calc-parent-alignment) (self-alignment-X . ,CENTER) (staff-padding . 0.7) (stencil . ,ly:text-interface::print) -- 2.39.2