]> git.donarmstrong.com Git - lilypond.git/commitdiff
(internal_brew_molecule): make left protusion
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 28 Sep 2003 23:27:17 +0000 (23:27 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 28 Sep 2003 23:27:17 +0000 (23:27 +0000)
smaller, to accomodate for natural sign.
(internal_brew_molecule): only do this when the accidental is
close enough.
(extent): new function

ChangeLog
input/regression/accidental-ledger.ly
lily/include/note-head.hh
lily/note-head.cc
ly/engraver-init.ly
scm/define-grobs.scm
scm/output-lib.scm

index a9fdd433e3300791dc760ded3e63986cc2eef2d8..8e2d3d7310ea437232a0a75880d472f4e04120ae 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2003-09-29  Han-Wen Nienhuys  <hanwen@cs.uu.nl>
 
+       * lily/note-head.cc (internal_brew_molecule): make left protusion
+       smaller, to accomodate for natural sign.
+       (internal_brew_molecule): only do this when the accidental is
+       close enough.
+       (extent): new function
+
        * lily/skyline.cc (merge_skyline): new function
        (heighten_skyline): new function
 
index 6aada6eb8977dbdb9da39a64db4decba74d78f58..7a7da7c85e59888047994470e0b75e715f216989 100644 (file)
@@ -6,7 +6,7 @@
 
 \score { \notes
 {
- cis'4 cis'! cis' cis'
+ c'!4 cis'! cis' <cis'! gis'>
 }
         \paper { raggedright = ##t}
 }
index 752fff6c0351ff7908b7f67e2e045da937080b63..118022c7008b3d98aca5d30e01f8302d2eca00c6 100644 (file)
@@ -23,8 +23,9 @@ public:
   DECLARE_SCHEME_CALLBACK (brew_molecule, (SCM ));
   static Interval head_extent (Grob*, Axis);
   static Molecule brew_ledger_lines (Grob *me, int pos, int interspaces,
-                                    Interval x_extent, bool take_space);
-  DECLARE_SCHEME_CALLBACK (brew_ez_molecule, (SCM ));
+                                    Interval x_extent, bool);
+  DECLARE_SCHEME_CALLBACK (brew_ez_molecule, (SCM));
+  DECLARE_SCHEME_CALLBACK (extent, (SCM,SCM));
   static bool has_interface (Grob*);
   static Real stem_attachment_coordinate (Grob *, Axis a);
   static int get_balltype (Grob*) ;  
index 1bf1ed66c5aa9cf77643e4454dd68c8601103f96..ede0bdb483e85b6529cb4af4d277aef0bab83add 100644 (file)
@@ -66,7 +66,7 @@ Note_head::brew_ledger_lines (Grob *me,
                               int pos,
                               int interspaces,
                               Interval x_extent,
-                              bool take_space)
+                             bool take_space)
 {
   Real inter_f = Staff_symbol_referencer::staff_space (me)/2;
   int line_count = (abs (pos) < interspaces)
@@ -74,6 +74,7 @@ Note_head::brew_ledger_lines (Grob *me,
     : (abs (pos) - interspaces) / 2;
   Molecule molecule = Molecule();
 
+
   if (line_count)
     {
       Real ledgerlinethickness =
@@ -87,10 +88,11 @@ Note_head::brew_ledger_lines (Grob *me,
 
       Molecule proto_ledger_line =
        Lookup::round_filled_box (ledger_line, blotdiameter);
-      
+
       if (!take_space)
         proto_ledger_line.set_empty (true);
 
+      
       Direction dir = (Direction)sign (pos);
       Real offs = (Staff_symbol_referencer::on_staffline (me, pos))
         ? 0.0
@@ -107,7 +109,7 @@ Note_head::brew_ledger_lines (Grob *me,
 }
 
 Molecule
-internal_brew_molecule (Grob *me, bool ledger_take_space)
+internal_brew_molecule (Grob *me, bool with_ledgers)
 {
   SCM style  = me->get_grob_property ("style");
   if (!gh_symbol_p (style))
@@ -129,14 +131,14 @@ internal_brew_molecule (Grob *me, bool ledger_take_space)
 
   int interspaces = Staff_symbol_referencer::line_count (me)-1;
   int pos = (int)rint (Staff_symbol_referencer::get_position (me));
-  if (interspaces >= 0
+  if (with_ledgers && interspaces >= 0
       && abs (pos) - interspaces > 1)
     {
       Interval hd = out.extent (X_AXIS);
       Real left_ledger_protusion = hd.length ()/4;
       Real right_ledger_protusion = left_ledger_protusion;
 
-      if (unsmob_grob(me->get_grob_property ("accidental-grob")))
+      if (Grob * g = unsmob_grob(me->get_grob_property ("accidental-grob")))
        {
          /*
            make a little room for accidentals.
@@ -144,16 +146,19 @@ internal_brew_molecule (Grob *me, bool ledger_take_space)
            TODO: this will look silly if a chord has ledger lines,
            and only the bottom note has an accidental.
          */
-         
-         left_ledger_protusion *= 0.66;
-         right_ledger_protusion *= 0.9; 
+
+         Grob *common = g->common_refpoint (me, X_AXIS);
+         Real d =
+           me->extent (common, X_AXIS)[LEFT]
+           -g->extent (common, X_AXIS)[RIGHT];
+         
+         left_ledger_protusion = left_ledger_protusion <? (d/2);
        }
 
       Interval l_extents = Interval (hd[LEFT] - left_ledger_protusion,
                                     hd[RIGHT] + right_ledger_protusion);
       out.add_molecule (Note_head::brew_ledger_lines (me, pos, interspaces,
-                                                     l_extents,
-                                                     ledger_take_space));
+                                                     l_extents, false));
     }
   return out;
 }
@@ -168,7 +173,7 @@ Note_head::brew_molecule (SCM smob)
   /*
     ledgers don't take space. See top of file.
    */
-  return internal_brew_molecule (me, false).smobbed_copy ();
+  return internal_brew_molecule (me, true).smobbed_copy ();
 }
 
 /*
@@ -180,14 +185,40 @@ Note_head::brew_molecule (SCM smob)
 Interval
 Note_head::head_extent (Grob *me, Axis a)
 {
-  Molecule * mol = me->get_molecule();
-  return mol ? mol ->extent (a) : Interval(0,0);
+  SCM brewer = me->get_grob_property ("molecule-callback");
+  if (brewer == Note_head::brew_molecule_proc)
+    {
+      Molecule mol = internal_brew_molecule (me, false);
+  
+      if (!mol.empty_b())
+       return mol.extent (a);
+    }
+  else
+    {
+      Molecule * mol = me->get_molecule ();
+      if (mol)
+       return  mol->extent (a) ;
+    }
+  
+  return Interval (0,0);
 }
 
+/*
+  This is necessary to prevent a cyclic dependency: the appearance of
+  the ledgers depends on positioning, so the Grob::get_molecule() can
+  not be used for determining the note head extent.
+  
+ */ 
+MAKE_SCHEME_CALLBACK (Note_head,extent,2);
+SCM
+Note_head::extent (SCM smob, SCM axis)  
+{
+  Grob *me = unsmob_grob (smob);
 
+  return ly_interval2scm (head_extent (me, (Axis) gh_scm2int (axis)));
+}
 
 MAKE_SCHEME_CALLBACK (Note_head,brew_ez_molecule,1);
-
 SCM
 Note_head::brew_ez_molecule (SCM smob)
 {
index 0f70dc52a8a020d16c80ca8c5b447b0a5e559074..5684d564d427c004f1606ffb50497f2fa480d0bf 100644 (file)
@@ -568,6 +568,8 @@ OrchestralScoreContext= \translator {
 EasyNotation =  \translator {
        \ScoreContext
        NoteHead \override #'molecule-callback = #Note_head::brew_ez_molecule
+       NoteHead \override #'Y-extent-callback = #'()
+       NoteHead \override #'X-extent-callback = #'()
 }
 
 
index b71c5787fca49cbb08f12ddb4a513d4a49ae0849..be9b6422df83c90bed0f861b200928e3ca3c16df 100644 (file)
        (molecule-callback . ,Note_head::brew_molecule)
        (ligature-primitive-callback . ,Note_head::brew_molecule)
        (glyph-name-procedure . ,find-notehead-symbol)
+       (X-extent-callback . ,Note_head::extent)
+       (Y-extent-callback . ,Note_head::extent)
        (Y-offset-callbacks  . (,Staff_symbol_referencer::callback))
        (stem-attachment-function . ,note-head-style->attachment-coordinates)
        (meta . ((interfaces . (rhythmic-grob-interface rhythmic-head-interface font-interface note-head-interface staff-symbol-referencer-interface item-interface ))))
      . (
        (font-family . roman)
        (style . default)
-       (molecule-callback . ,tablature-molecule-callback)
+       (molecule-callback . ,Text_item::brew_molecule)
        (Y-offset-callbacks  . (,Staff_symbol_referencer::callback))
        (extra-offset . (0 . -0.65)) ;; UGH! TODO: Clean this up!
        (stem-attachment-function . ,tablature-stem-attachment-function)
index 84e45228e4facaafaa6e1669cc1846a7078254c2..fc9b682897b3e3db8818de344b3486be48675285 100644 (file)
@@ -20,8 +20,7 @@
                    (ly:get-grob-property grob 'text)
                    )))
     molecule ; return the molecule.
-    )
-  )
+    ))
 
 ; The TabNoteHead tablatureFormat callback.
 ; Compute the text grob-property