]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/tuplet-bracket.cc
trem fix
[lilypond.git] / lily / tuplet-bracket.cc
index bfcc48bfdb3e160938ba1c05b5db9e4babe600a0..2b6b6f7cb14bf7db0bee521e3d6055aae72ad969 100644 (file)
 #include "lookup.hh"
 
 
-static Real
-get_x_offset (Grob *g, Grob *common, Direction my_dir)
+static Grob*
+get_x_bound_grob (Grob *g, Direction my_dir)
 {
   if (Note_column::stem_l (g)
       && Note_column::dir (g) == my_dir)
     {
       g = Note_column::stem_l (g);
     }
-  return g->relative_coordinate (common, X_AXIS);
+  return g;
 }
 
 
 
 Grob*
-Tuplet_bracket::parallel_beam (Grob *me, Link_array<Grob> cols, bool *equally_long)
+Tuplet_bracket::parallel_beam (Grob *me, Link_array<Grob> const &cols, bool *equally_long)
 {
   /*
     ugh: code dup. 
@@ -129,9 +129,12 @@ Tuplet_bracket::brew_molecule (SCM smob)
        
   Grob * commonx = column_arr[0]->common_refpoint (column_arr.top (),X_AXIS);
   Direction dir = Directional_element_interface::get (me);
-      
-  Real x0 = get_x_offset (column_arr[0], commonx, dir);
-  Real x1 = get_x_offset (column_arr.top(), commonx, dir);
+
+  Grob * lgr = get_x_bound_grob (column_arr[0], dir);
+  Grob * rgr = get_x_bound_grob (column_arr.top(), dir);  
+  Real x0 = lgr->extent (commonx,X_AXIS)[LEFT];
+  Real x1 = rgr->extent (commonx,X_AXIS)[RIGHT];
+
   Real w = x1 -x0;
 
   Real ly = gh_scm2double (me->get_grob_property ("left-position"));
@@ -160,15 +163,31 @@ Tuplet_bracket::brew_molecule (SCM smob)
        lt *= gh_scm2double (thick);
       
       SCM gap = me->get_grob_property ("gap");
-
-      Real prot_size = 0.7;    // magic.
-
+      SCM ew = me->get_grob_property ("edge-width");
+      SCM eh = me->get_grob_property ("edge-height");
+      SCM sp = me->get_grob_property ("shorten-pair");
+      
+      Direction d = LEFT;
+      Drul_array<Real> height, width, shorten;
+      do {
+       width[d] =  height[d] = shorten[d] = 0.0;
+       if ( gh_pair_p (ew) )
+         width[d] +=  gh_scm2double (index_cell (ew, d)) * d;
+       if ( gh_pair_p (eh) )
+         height[d] += gh_scm2double (index_cell (eh, d));
+       if ( gh_pair_p (sp) )
+         shorten[d] +=  gh_scm2double (index_cell (sp, d));
+      }
+      while (flip (&d) != LEFT);
+      
       Molecule brack = make_bracket (Y_AXIS,
-                                    w, ry-ly, lt,
-                                    -prot_size*dir, -prot_size*dir,
+                                    w, ry - ly, lt,
+                                    -height[LEFT]*dir, -height[RIGHT]*dir,
                                     gh_scm2double (gap),
-                                    0.0, 0.0);
+                                    width[LEFT], width[RIGHT],
+                                    shorten[LEFT], shorten[RIGHT]);
       mol.add_molecule (brack);
+      mol.translate_axis (dir * max(height[LEFT], height[RIGHT]), Y_AXIS);
     }
 
   mol.translate_axis (ly, Y_AXIS);
@@ -181,31 +200,36 @@ Tuplet_bracket::brew_molecule (SCM smob)
  */
 Molecule
 Tuplet_bracket::make_bracket (Axis protusion_axis,
-                             Real dx, Real dy, Real thick, Real lprotrusion,
-                             Real rprotrusion, Real gap, Real left_widen,
-                             Real right_widen)
+                             Real dx, Real dy, Real thick, Real left_height,
+                             Real right_height, Real gap, Real left_widen,
+                             Real right_widen, Real left_shorten, Real right_shorten)
 {
   Real len = Offset (dx,dy).length ();
-  Real gapx = dx*  (gap /  len);
-  Real gapy = dy*  (gap /  len);
+  Real gapx = dx * (gap /  len);
+  Real gapy = dy * (gap /  len);
+  Real lshortx = dx * (left_shorten /  len);
+  Real lshorty = dy * (left_shorten /  len);
+  Real rshortx = dx * (right_shorten /  len);
+  Real rshorty = dy * (right_shorten /  len);
   Axis other = other_axis (protusion_axis);
-
-  Molecule l1 = Lookup::line (thick, Offset(0,0),
+  
+  Molecule l1 = Lookup::line (thick, Offset(lshortx, lshorty),
                              Offset ( (dx - gapx)/2, (dy - gapy)/2 ));
+
   Molecule l2 = Lookup::line (thick, Offset((dx + gapx) / 2,(dy + gapy) / 2),
-                             
-                             Offset (dx,dy));
+                             Offset (dx - rshortx, dy - rshorty));
 
   Offset protusion;
-  protusion[other] = left_widen;
-  protusion[protusion_axis] = lprotrusion;
-  
-  Molecule p1 = Lookup::line (thick, Offset(0,0), protusion);
-
+  protusion[other] = -left_widen;
+  protusion[protusion_axis] = left_height;
+  Molecule p1 = Lookup::line (thick, 
+                             Offset(lshortx, lshorty), 
+                             Offset(lshortx, lshorty) + protusion);
   protusion[other] = right_widen;
-  protusion[protusion_axis] = rprotrusion;
-  Molecule p2 = Lookup::line (thick, Offset(dx,dy),Offset(dx,dy) + protusion);  
-
+  protusion[protusion_axis] = right_height;
+  Molecule p2 = Lookup::line (thick, 
+                             Offset(dx - rshortx, dy - rshorty), 
+                             Offset(dx - rshortx, dy - rshorty) + protusion);  
 
   Molecule m;
   m.add_molecule (p1);
@@ -227,10 +251,11 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy)
     Pointer_group_interface__extract_grobs (me, (Grob*)0, "note-columns");
 
 
-  Grob * commony = me->common_refpoint (me->get_grob_property ("note-columns"), Y_AXIS);
-  Grob * commonx = me->common_refpoint (me->get_grob_property ("note-columns"), X_AXIS);  
+  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);  
   
-  Direction d = Directional_element_interface::get (me);
+  Direction dir = Directional_element_interface::get (me);
 
   /*
     Use outer non-rest columns to determine slope
@@ -245,22 +270,25 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy)
   
   if (l < r)
     {
-      *dy = column_arr[r]->extent (commony, Y_AXIS) [d]
-       - column_arr[l]->extent (commony, Y_AXIS) [d] ;
+      *dy = column_arr[r]->extent (commony, Y_AXIS) [dir]
+       - column_arr[l]->extent (commony, Y_AXIS) [dir] ;
     }
   else
     * dy = 0;
 
 
-  *offset = - d * infinity_f;
+  *offset = - dir * infinity_f;
 
   if (!column_arr.size ())
     return;
 
 
   
-  Real x0 = get_x_offset (column_arr[0], commonx, d);
-  Real x1 = get_x_offset (column_arr.top(), commonx, d);
+  Grob * lgr = get_x_bound_grob (column_arr[0], dir);
+  Grob * rgr = get_x_bound_grob (column_arr.top(), dir);  
+  Real x0 = lgr->extent (commonx,X_AXIS)[LEFT];
+  Real x1 = rgr->extent (commonx,X_AXIS)[RIGHT];
+
 
     /*
       Slope.
@@ -269,18 +297,18 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy)
   
   for (int i = 0; i < column_arr.size ();  i++)
     {
-      Real notey = column_arr[i]->extent (commony, Y_AXIS)[d] 
+      Real notey = column_arr[i]->extent (commony, Y_AXIS)[dir
        - me->relative_coordinate (commony, Y_AXIS);
 
       Real x = column_arr[i]->relative_coordinate (commonx, X_AXIS) - x0;
       Real tuplety =  *dy * x * factor;
 
-      if (notey * d > (*offset + tuplety) * d)
+      if (notey * dir > (*offset + tuplety) * dir)
        *offset = notey - tuplety; 
     }
 
   // padding
-  *offset +=  gh_scm2double (me->get_grob_property ("padding")) *d;
+  *offset +=  gh_scm2double (me->get_grob_property ("padding")) *dir;
 
   
   /*
@@ -294,7 +322,7 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy)
       
       *offset = rint (*offset);
       if (Staff_symbol_referencer::on_staffline (me, (int) rint (*offset)))
-       *offset += d;
+       *offset += dir;
 
       *offset *= 0.5 * ss;
     }
@@ -372,8 +400,12 @@ Tuplet_bracket::after_line_breaking (SCM smob)
   bool equally_long = false;
   Grob * par_beam = parallel_beam (me, column_arr, &equally_long);
 
+  /*
+    We follow the beam only if there is one, and we are next to it.
+   */
   Real dy, offset;
-  if (!par_beam)
+  if (!par_beam
+      || Directional_element_interface::get (par_beam) != dir)
     {
       calc_position_and_height (me,&offset,&dy);
     }
@@ -445,16 +477,11 @@ Tuplet_bracket::add_column (Grob*me, Item*n)
 }
 
 
-bool
-Tuplet_bracket::has_interface (Grob*me)
-{
-  return me->has_interface (ly_symbol2scm ("tuplet-bracket-interface"));
-}
 
 
 
 
 ADD_INTERFACE (Tuplet_bracket,"tuplet-bracket-interface",
   "A bracket with a number in the middle, used for tuplets.",
-  "note-columns padding gap left-position right-position bracket-visibility number-visibility thickness direction");
+  "note-columns edge-width edge-height shorten-pair padding gap left-position right-position bracket-visibility number-visibility thickness direction");