]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/tuplet-bracket.cc
*** empty log message ***
[lilypond.git] / lily / tuplet-bracket.cc
index b75b602b5434c74dd0ebc64ff08be44572387861..380a5f43637dde5470f42f920f85d0882bcc07b5 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997--2004 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 1997--2005 Jan Nieuwenhuizen <janneke@gnu.org>
   Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
   
  */
 
+/*
+
+    TODO: quantise, we don't want to collide with staff lines.
+ (or should we be above staff?)
+
+  todo: handle breaking elegantly.
+*/
+
 #include <math.h>
 
+#include "tuplet-bracket.hh"
 #include "line-interface.hh"
 #include "beam.hh"
-#include "box.hh"
 #include "warn.hh"
 #include "font-interface.hh"
-#include "stencil.hh"
-#include "paper-def.hh"
+#include "output-def.hh"
 #include "text-item.hh"
-#include "tuplet-bracket.hh"
 #include "stem.hh"
 #include "note-column.hh"
 #include "group-interface.hh"
@@ -42,7 +48,6 @@
 #include "staff-symbol-referencer.hh"
 #include "lookup.hh"
 
-
 static Grob*
 get_x_bound_grob (Grob *g, Direction my_dir)
 {
@@ -70,7 +75,7 @@ Tuplet_bracket::parallel_beam (Grob *me, Link_array<Grob> const &cols, bool *equ
   
   Spanner*sp = dynamic_cast<Spanner*> (me);  
 
-  *equally_long= false;
+  *equally_long = false;
   if (! (b1 && (b1 == b2) && !sp->is_broken ()))
       return 0;
 
@@ -96,13 +101,13 @@ Tuplet_bracket::parallel_beam (Grob *me, Link_array<Grob> const &cols, bool *equ
   follow beam precisely for determining tuplet number location.
   
  */
-MAKE_SCHEME_CALLBACK (Tuplet_bracket,print,1);
+MAKE_SCHEME_CALLBACK (Tuplet_bracket, print, 1);
 SCM
 Tuplet_bracket::print (SCM smob) 
 {
-  Grob *me= unsmob_grob (smob);
+  Grob *me = unsmob_grob (smob);
   Stencil  mol;
-  Link_array<Grob> columns=
+  Link_array<Grob> columns =
     Pointer_group_interface__extract_grobs (me, (Grob*)0, "note-columns");
 
   if (!columns.size ())
@@ -114,7 +119,7 @@ Tuplet_bracket::print (SCM smob)
     SCM lp = me->get_property ("left-position");
     SCM rp = me->get_property ("right-position");  
 
-    if (!gh_number_p (rp) || !gh_number_p (lp))
+    if (!scm_is_number (rp) || !scm_is_number (lp))
       after_line_breaking (smob);
   }
   
@@ -133,22 +138,22 @@ Tuplet_bracket::print (SCM smob)
     Fixme: the type of this prop is sucky.
    */
   SCM bracket = me->get_property ("bracket-visibility");
-  if (gh_boolean_p (bracket))
+  if (scm_is_bool (bracket))
     {
-      bracket_visibility = gh_scm2bool (bracket);
+      bracket_visibility = ly_scm2bool (bracket);
     }
   else if (bracket == ly_symbol2scm ("if-no-beam"))
     bracket_visibility = !par_beam;
 
   SCM numb = me->get_property ("number-visibility");  
-  if (gh_boolean_p (numb))
+  if (scm_is_bool (numb))
     {
-      number_visibility = gh_scm2bool (numb);
+      number_visibility = ly_scm2bool (numb);
     }
   else if (numb == ly_symbol2scm ("if-no-beam"))
     number_visibility = !par_beam;
        
-  Grob * commonx = columns[0]->common_refpoint (columns.top (),X_AXIS);
+  Grob * commonx = columns[0]->common_refpoint (columns.top (), X_AXIS);
 
   /*
     Tuplet brackets are normally not broken, but we shouldn't crash if
@@ -160,20 +165,20 @@ Tuplet_bracket::print (SCM smob)
   Direction dir = get_grob_direction (me);
 
   Grob * lgr = get_x_bound_grob (columns[0], dir);
-  Grob * rgr = get_x_bound_grob (columns.top (), dir);  
-  Real x0 = lgr->extent (commonx,X_AXIS)[LEFT];
-  Real x1 = rgr->extent (commonx,X_AXIS)[RIGHT];
-
+  Grob * rgr = get_x_bound_grob (columns.top (), dir);
+  
+  Real x0 = robust_relative_extent (lgr, commonx, X_AXIS)[LEFT];
+  Real x1 = robust_relative_extent (rgr, commonx, X_AXIS)[RIGHT];
   Real w = x1 -x0;
   
   SCM number = me->get_property ("text");
 
-  Paper_def *pap = me->get_paper ();
+  Output_def *pap = me->get_layout ();
   Stencil num;
- if (gh_string_p (number) && number_visibility)
+ if (scm_is_string (number) && number_visibility)
     {
       SCM properties = Font_interface::text_font_alist_chain (me);
-      SCM snum = Text_item::interpret_markup (pap->self_scm (), properties, number);
+      SCM snum = Text_interface::interpret_markup (pap->self_scm (), properties, number);
       num = *unsmob_stencil (snum);
       num.align_to (X_AXIS, CENTER);
       num.translate_axis (w/2, X_AXIS);
@@ -199,7 +204,7 @@ Tuplet_bracket::print (SCM smob)
   if (bracket_visibility)      
     {
       Real ss =   Staff_symbol_referencer::staff_space (me);
-      Real gap=0.;
+      Real gap = 0.;
 
       if (!num.extent (X_AXIS).is_empty ())
        gap = num.extent (X_AXIS).length () + 1.0;
@@ -213,11 +218,11 @@ Tuplet_bracket::print (SCM smob)
       do {
        flare[d] =  height[d] = shorten[d] = 0.0;
        if (is_number_pair (fl))
-         flare[d] +=  ss * gh_scm2double (index_get_cell (fl, d));
+         flare[d] +=  ss * scm_to_double (index_get_cell (fl, d));
        if (is_number_pair (eh))
-         height[d] +=  - dir * ss *gh_scm2double (index_get_cell (eh, d));
+         height[d] +=  - dir * ss *scm_to_double (index_get_cell (eh, d));
        if (is_number_pair (sp))
-         shorten[d] +=  ss *gh_scm2double (index_get_cell (sp, d));
+         shorten[d] +=  ss *scm_to_double (index_get_cell (sp, d));
       }
       while (flip (&d) != LEFT);
       
@@ -234,7 +239,7 @@ Tuplet_bracket::print (SCM smob)
     }
   
   mol.translate_axis (ly, Y_AXIS);
-  mol.translate_axis (x0  - sp->get_bound (LEFT)->relative_coordinate (commonx,X_AXIS),X_AXIS);
+  mol.translate_axis (x0  - sp->get_bound (LEFT)->relative_coordinate (commonx, X_AXIS), X_AXIS);
   return mol.smobbed_copy ();
 }
 
@@ -245,7 +250,7 @@ Tuplet_bracket::print (SCM smob)
   brackets.
  */
 Stencil
-Tuplet_bracket::make_bracket (Grob *me,        // for line properties.
+Tuplet_bracket::make_bracket (Grob *me,        // for line properties.
                              Axis protusion_axis,
                              Offset dz,
                              Drul_array<Real> height,
@@ -253,7 +258,7 @@ Tuplet_bracket::make_bracket (Grob *me,     // for line properties.
                              Drul_array<Real> flare,
                              Drul_array<Real> shorten)
 {
-  Drul_array<Offset> corners (Offset (0,0), dz);
+  Drul_array<Offset> corners (Offset (0, 0), dz);
   
   Real length = dz.length ();
   Drul_array<Offset> gap_corners;
@@ -270,7 +275,7 @@ Tuplet_bracket::make_bracket (Grob *me,     // for line properties.
 
 
   if (gap.is_empty())
-    gap = Interval (0,0);
+    gap = Interval (0, 0);
   do {
     gap_corners[d] = (dz * 0.5) + gap[d] / length * dz;
   } while (flip (&d) != LEFT);
@@ -285,10 +290,10 @@ Tuplet_bracket::make_bracket (Grob *me,   // for line properties.
   Stencil m;
   do {
     m.add_stencil (Line_interface::line (me, straight_corners[d],
-                                                gap_corners[d]));
+                                        gap_corners[d]));
     
     m.add_stencil (Line_interface::line (me,  straight_corners[d],
-                                                flare_corners[d]));
+                                        flare_corners[d]));
   } while (flip (&d) != LEFT);
 
   return m;  
@@ -299,12 +304,11 @@ Tuplet_bracket::make_bracket (Grob *me,   // for line properties.
   use first -> last note for slope, and then correct for disturbing
   notes in between.  */
 void
-Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy) 
+Tuplet_bracket::calc_position_and_height (Grob*me, Real *offset, Real * dy) 
 {
-  Link_array<Grob> columns=
+  Link_array<Grob> columns =
     Pointer_group_interface__extract_grobs (me, (Grob*)0, "note-columns");
 
-
   SCM cols = me->get_property ("note-columns");
   Grob * commony = common_refpoint_of_list (cols, me, Y_AXIS);
   Grob * commonx = common_refpoint_of_list (cols, me, X_AXIS);  
@@ -328,8 +332,8 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy)
   
   if (l < r)
     {
-      Interval rv =columns[r]->extent (commony, Y_AXIS);
-      Interval lv =columns[l]->extent (commony, Y_AXIS);
+      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];
@@ -360,9 +364,8 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy)
   
   Grob * lgr = get_x_bound_grob (columns[0], dir);
   Grob * rgr = get_x_bound_grob (columns.top (), dir);  
-  Real x0 = lgr->extent (commonx,X_AXIS)[LEFT];
-  Real x1 = rgr->extent (commonx,X_AXIS)[RIGHT];
-
+  Real x0 = robust_relative_extent (lgr, commonx, X_AXIS)[LEFT];
+  Real x1 = robust_relative_extent (rgr, commonx, X_AXIS)[RIGHT];
 
   /*
     Slope.
@@ -371,7 +374,7 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy)
   
   for (int i = 0; i < columns.size ();  i++)
     {
-      Interval note_ext =columns[i]->extent (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);
       
@@ -383,14 +386,14 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy)
     }
 
   // padding
-  *offset +=  gh_scm2double (me->get_property ("padding")) *dir;
+  *offset +=  scm_to_double (me->get_property ("padding")) *dir;
 
   
   /*
     horizontal brackets should not collide with staff lines.
     
    */
-  Real ss= Staff_symbol_referencer::staff_space (me);
+  Real ss = Staff_symbol_referencer::staff_space (me);
   if (*dy == 0 && fabs (*offset) <  ss * Staff_symbol_referencer::staff_radius (me))
     {
       // quantize, then do collision check.
@@ -410,32 +413,32 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy)
 /*
   We depend on the beams if there are any.
  */
-MAKE_SCHEME_CALLBACK (Tuplet_bracket,before_line_breaking,1);
+MAKE_SCHEME_CALLBACK (Tuplet_bracket, before_line_breaking, 1);
 SCM
 Tuplet_bracket::before_line_breaking (SCM smob)
 {
   Grob *me = unsmob_grob (smob);
-  Link_array<Grob> columns=
+  Link_array<Grob> columns =
     Pointer_group_interface__extract_grobs (me, (Grob*)0, "note-columns");
 
 
   for (int i = columns.size (); i--;)
     {
-      Grob * s =Note_column::get_stem (columns[i]);
+      Grob * s = Note_column::get_stem (columns[i]);
       Grob * b = s ? Stem::get_beam (s): 0;
       if (b)
        me->add_dependency (b);
     }
-  return SCM_UNDEFINED;
+  return SCM_UNSPECIFIED;
 }
 
-MAKE_SCHEME_CALLBACK (Tuplet_bracket,after_line_breaking,1);
+MAKE_SCHEME_CALLBACK (Tuplet_bracket, after_line_breaking, 1);
 
 SCM
 Tuplet_bracket::after_line_breaking (SCM smob)
 {
   Grob * me = unsmob_grob (smob);
-  Link_array<Grob> columns=
+  Link_array<Grob> columns =
     Pointer_group_interface__extract_grobs (me, (Grob*)0, "note-columns");
 
   if (!columns.size ())
@@ -467,19 +470,19 @@ Tuplet_bracket::after_line_breaking (SCM smob)
   if (!par_beam
       || get_grob_direction (par_beam) != dir)
     {
-      calc_position_and_height (me,&offset,&dy);
+      calc_position_and_height (me, &offset, &dy);
     }
   else
     {
       SCM ps =  par_beam->get_property ("positions"); 
 
-      Real lp = gh_scm2double (gh_car (ps));
-      Real rp = gh_scm2double (gh_cdr (ps));
+      Real lp = scm_to_double (scm_car (ps));
+      Real rp = scm_to_double (scm_cdr (ps));
 
       /*
        duh. magic.
        */
-      offset = lp + dir * (0.5 + gh_scm2double (me->get_property ("padding")));
+      offset = lp + dir * (0.5 + scm_to_double (me->get_property ("padding")));
       dy = rp- lp;
     }
   
@@ -487,18 +490,18 @@ Tuplet_bracket::after_line_breaking (SCM smob)
   SCM lp =  me->get_property ("left-position");
   SCM rp = me->get_property ("right-position");  
   
-  if (gh_number_p (lp) && !gh_number_p (rp))
+  if (scm_is_number (lp) && !scm_is_number (rp))
     {
-      rp = gh_double2scm (gh_scm2double (lp) + dy);
+      rp = scm_make_real (scm_to_double (lp) + dy);
     }
-  else if (gh_number_p (rp) && !gh_number_p (lp))
+  else if (scm_is_number (rp) && !scm_is_number (lp))
     {
-      lp = gh_double2scm (gh_scm2double (rp) - dy);
+      lp = scm_make_real (scm_to_double (rp) - dy);
     }
-  else if (!gh_number_p (rp) && !gh_number_p (lp))
+  else if (!scm_is_number (rp) && !scm_is_number (lp))
     {
-      lp = gh_double2scm (offset);
-      rp = gh_double2scm (offset +dy);
+      lp = scm_make_real (offset);
+      rp = scm_make_real (offset + dy);
     }
 
   me->set_property ("left-position", lp);
@@ -514,10 +517,10 @@ Tuplet_bracket::after_line_breaking (SCM smob)
 Direction
 Tuplet_bracket::get_default_dir (Grob*me)
 {
-  Drul_array<int> dirs (0,0);  
-  for (SCM s = me->get_property ("note-columns"); gh_pair_p (s); s = ly_cdr (s))
+  Drul_array<int> dirs (0, 0);  
+  for (SCM s = me->get_property ("note-columns"); scm_is_pair (s); s = scm_cdr (s))
     {
-      Grob * nc = unsmob_grob (ly_car (s));
+      Grob * nc = unsmob_grob (scm_car (s));
       Direction d = Note_column::dir (nc);
       if (d)
        dirs[d]++;
@@ -540,7 +543,11 @@ Tuplet_bracket::add_column (Grob*me, Item*n)
 
 
 
-ADD_INTERFACE (Tuplet_bracket,"tuplet-bracket-interface",
-  "A bracket with a number in the middle, used for tuplets.",
-  "note-columns bracket-flare edge-height shorten-pair padding left-position right-position bracket-visibility number-visibility thickness direction");
+ADD_INTERFACE (Tuplet_bracket,
+              "tuplet-bracket-interface",
+              "A bracket with a number in the middle, used for tuplets.",
+              
+              "note-columns bracket-flare edge-height shorten-pair "
+              "padding left-position right-position bracket-visibility "
+              "number-visibility thickness direction");