]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 3186: fix clef transposition alignment
authorJanek Warchoł <lemniskata.bernoullego@gmail.com>
Wed, 3 Apr 2013 19:46:56 +0000 (21:46 +0200)
committerJanek Warchoł <lemniskata.bernoullego@gmail.com>
Sat, 16 Aug 2014 21:39:07 +0000 (23:39 +0200)
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.

input/regression/clef-transposition-placement.ly
lily/clef-modifier.cc [new file with mode: 0644]
scm/define-grob-interfaces.scm
scm/define-grob-properties.scm
scm/define-grobs.scm

index 119e00a903a28ef7b5be816d84748e1a58df51e7..2255e9be208242be14ad075d1a252d5a12ff63c2 100644 (file)
@@ -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 (file)
index 0000000..6d802ad
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+  This file is part of LilyPond, the GNU music typesetter.
+
+  Copyright (C) 2014--2014 Janek Warchoł <lemniskata.bernoullego@gmail.com>
+
+  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 <http://www.gnu.org/licenses/>.
+*/
+
+#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 "
+              );
+
index 2c3290a4c88573a25a90b2c6cd688105b1430e0f..e07006e35048c3aca50207c2516492ceb708f955 100644 (file)
@@ -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
index 35f0074a88de07538712e29d39c651af28445cb2..ff714fc04d32c0c5246d7138a26be8ac79e65ba8 100644 (file)
@@ -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
index 53401d3a42daf2362d464c7bd42ad11c260382e6..813c93b13168f4b85362bff1bff5e691a78def38 100644 (file)
      . (
         (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)