]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/tuplet-bracket.cc
2003 -> 2004
[lilypond.git] / lily / tuplet-bracket.cc
index 2c9705d0b4e83c55c2206752e948bb0ba3e9740c..221d323a6cc2cb97b740a7a1f31f627cc134ba85 100644 (file)
@@ -1,9 +1,10 @@
 /*
-  plet-spanner.cc -- implement Tuplet_bracket
+  tuplet-bracket.cc -- implement Tuplet_bracket
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2003 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 1997--2004 Jan Nieuwenhuizen <janneke@gnu.org>
+  Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
 /*
@@ -196,7 +197,9 @@ Tuplet_bracket::brew_molecule (SCM smob)
   
   if (bracket_visibility)      
     {
-      SCM gap = me->get_grob_property ("gap");
+      Real ss =   Staff_symbol_referencer::staff_space (me);
+      Real gap = robust_scm2double (me->get_grob_property ("gap"), 1.0)
+       * ss;
       
       SCM fl = me->get_grob_property ("bracket-flare");
       SCM eh = me->get_grob_property ("edge-height");
@@ -207,20 +210,18 @@ Tuplet_bracket::brew_molecule (SCM smob)
       do {
        flare[d] =  height[d] = shorten[d] = 0.0;
        if (is_number_pair (fl))
-         flare[d] +=  gh_scm2double (index_get_cell (fl, d));
+         flare[d] +=  ss * gh_scm2double (index_get_cell (fl, d));
        if (is_number_pair (eh))
-         height[d] += gh_scm2double (index_get_cell (eh, d)) * - dir;
+         height[d] +=  - dir * ss *gh_scm2double (index_get_cell (eh, d));
        if (is_number_pair (sp))
-         shorten[d] +=  gh_scm2double (index_get_cell (sp, d));
+         shorten[d] +=  ss *gh_scm2double (index_get_cell (sp, d));
       }
       while (flip (&d) != LEFT);
       
       Molecule brack = make_bracket (me, Y_AXIS,
                                     Offset (w, ry - ly), 
-                                    height,
-                                    gh_scm2double (gap),
-                                    flare,
-                                    shorten);
+                                    height, gap,
+                                    flare, shorten);
       mol.add_molecule (brack);
     }
   
@@ -257,7 +258,16 @@ Tuplet_bracket::make_bracket (Grob *me,    // for line properties.
   Direction d = LEFT;
   do {
     straight_corners[d] += - d * shorten[d] /length * dz;
-    gap_corners[d] = (dz * 0.5) + d * gap / length * dz;
+  } while (flip (&d) != LEFT);
+
+  /*
+    UGH: the shortening factor is magic.
+   */
+  gap = gap <?
+    (0.66 * (straight_corners[RIGHT] - straight_corners[LEFT]).length ());
+  
+  do {
+    gap_corners[d] = (dz * 0.5) + d * 0.5 * gap / length * dz;
   } while (flip (&d) != LEFT);
 
   Drul_array<Offset> flare_corners = straight_corners;
@@ -293,6 +303,10 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy)
   SCM cols = me->get_grob_property ("note-columns");
   Grob * commony = common_refpoint_of_list (cols, me, Y_AXIS);
   Grob * commonx = common_refpoint_of_list (cols, me, X_AXIS);  
+
+  Interval staff;
+  if (Grob * st = Staff_symbol_referencer::get_staff_symbol (me))
+    staff = st->extent (commony, Y_AXIS);
   
   Direction dir = get_grob_direction (me);
 
@@ -309,8 +323,24 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy)
   
   if (l < r)
     {
-      *dy = columns[r]->extent (commony, Y_AXIS) [dir]
-       - columns[l]->extent (commony, Y_AXIS) [dir] ;
+      Interval rv =columns[r]->extent (commony, Y_AXIS);
+      Interval lv =columns[l]->extent (commony, Y_AXIS);
+      rv.unite (staff);
+      lv.unite (staff);
+      Real graphical_dy =  rv[dir] - lv[dir];
+
+      Slice ls = Note_column::head_positions_interval (columns[l]);
+      Slice rs = Note_column::head_positions_interval (columns[r]);
+      
+      Interval musical_dy;
+      musical_dy[UP] = rs[UP] - ls[UP];
+      musical_dy[DOWN] = rs[DOWN] - ls[DOWN];
+      if (sign (musical_dy[UP]) != sign (musical_dy[DOWN]))
+       *dy = 0.0;
+      else if (sign (graphical_dy) != sign (musical_dy[DOWN]))
+       *dy = 0.0;
+      else
+       *dy = graphical_dy;
     }
   else
     * dy = 0;
@@ -329,15 +359,16 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy)
   Real x1 = rgr->extent (commonx,X_AXIS)[RIGHT];
 
 
-    /*
-      Slope.
-    */
+  /*
+    Slope.
+  */
   Real factor = columns.size () > 1 ? 1/ (x1 - x0) : 1.0;
   
   for (int i = 0; i < columns.size ();  i++)
     {
-      Real notey = columns[i]->extent (commony, Y_AXIS)[dir] 
-       - me->relative_coordinate (commony, Y_AXIS);
+      Interval note_ext =columns[i]->extent (commony, Y_AXIS);
+      note_ext.unite (staff);
+      Real notey = note_ext[dir] - me->relative_coordinate (commony, Y_AXIS);
       
       Real x = columns[i]->relative_coordinate (commonx, X_AXIS) - x0;
       Real tuplety =  *dy * x * factor;
@@ -369,22 +400,6 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy)
   
 }
 
-/*
-  use first -> last note for slope,
-*/
-void
-Tuplet_bracket::calc_dy (Grob*me,Real * dy)
-{
-  Link_array<Grob> columns=
-    Pointer_group_interface__extract_grobs (me, (Grob*)0, "note-columns");
-
-  /*
-    ugh. refps.
-   */
-  Direction d = get_grob_direction (me);
-  *dy = columns.top ()->extent (columns.top (), Y_AXIS) [d]
-    - columns[0]->extent (columns[0], Y_AXIS) [d];
-}
 
 
 /*
@@ -425,7 +440,7 @@ Tuplet_bracket::after_line_breaking (SCM smob)
     }
   if (dynamic_cast<Spanner*> (me)->broken_b ())
     {
-      me->warning ("Tuplet_bracket was across linebreak. Farewell cruel world.");
+      me->warning (_("Killing tuplet bracket across linebreak."));
       me->suicide();
       return SCM_UNSPECIFIED;
     }
@@ -489,22 +504,21 @@ Tuplet_bracket::after_line_breaking (SCM smob)
 
 
 /*
-  similar to slur.
+  similar to beam ? 
  */
 Direction
 Tuplet_bracket::get_default_dir (Grob*me)
 {
-  Direction d = UP;
+  Drul_array<int> dirs(0,0);  
   for (SCM s = me->get_grob_property ("note-columns"); gh_pair_p (s); s = ly_cdr (s))
     {
       Grob * nc = unsmob_grob (ly_car (s));
-      if (Note_column::dir (nc) < 0) 
-       {
-         d = DOWN;
-         break;
-       }
+      Direction d = Note_column::dir (nc);
+      if (d)
+       dirs[d]++;
     }
-  return d;
+
+  return dirs[UP] >= dirs[DOWN] ? UP : DOWN;
 }
 
 void