]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/stem.cc
* lily/ledger-line-spanner.cc (print): swap linear_combination
[lilypond.git] / lily / stem.cc
index faca4aa1843e610f9a991f9b4737c271d478e2dd..c7242f4af40541bcc083008c8f46907eb5cb6be9 100644 (file)
@@ -40,7 +40,7 @@ Stem::set_beaming (Grob *me, int beam_count, Direction d)
 {
   SCM pair = me->get_property ("beaming");
 
-  if (!ly_c_pair_p (pair))
+  if (!scm_is_pair (pair))
     {
       pair = scm_cons (SCM_EOL, SCM_EOL);
       me->set_property ("beaming", pair);
@@ -56,7 +56,7 @@ int
 Stem::get_beaming (Grob *me, Direction d)
 {
   SCM pair = me->get_property ("beaming");
-  if (!ly_c_pair_p (pair))
+  if (!scm_is_pair (pair))
     return 0;
 
   SCM lst = index_get_cell (pair, d);
@@ -91,13 +91,13 @@ Stem::stem_end_position (Grob *me)
 {
   SCM p = me->get_property ("stem-end-position");
   Real pos;
-  if (!ly_c_number_p (p))
+  if (!scm_is_number (p))
     {
       pos = get_default_stem_end_position (me);
       me->set_property ("stem-end-position", scm_make_real (pos));
     }
   else
-    pos = ly_scm2double (p);
+    pos = scm_to_double (p);
 
   return pos;
 }
@@ -135,7 +135,7 @@ Stem::support_head (Grob *me)
 {
   if (head_count (me) == 1)
     /* UGH. */
-    return unsmob_grob (ly_car (me->get_property ("note-heads")));
+    return unsmob_grob (scm_car (me->get_property ("note-heads")));
   return first_head (me);
 }
 
@@ -182,10 +182,10 @@ Stem::extremal_heads (Grob *me)
   Drul_array<Grob *> exthead;
   exthead[LEFT] = exthead[RIGHT] =0;
 
-  for (SCM s = me->get_property ("note-heads"); ly_c_pair_p (s);
-       s = ly_cdr (s))
+  for (SCM s = me->get_property ("note-heads"); scm_is_pair (s);
+       s = scm_cdr (s))
     {
-      Grob *n = unsmob_grob (ly_car (s));
+      Grob *n = unsmob_grob (scm_car (s));
       int p = Staff_symbol_referencer::get_rounded_position (n);
 
       Direction d = LEFT;
@@ -212,10 +212,10 @@ Array<int>
 Stem::note_head_positions (Grob *me)
 {
   Array<int> ps ;
-  for (SCM s = me->get_property ("note-heads"); ly_c_pair_p (s);
-       s = ly_cdr (s))
+  for (SCM s = me->get_property ("note-heads"); scm_is_pair (s);
+       s = scm_cdr (s))
     {
-      Grob *n = unsmob_grob (ly_car (s));
+      Grob *n = unsmob_grob (scm_car (s));
       int p = Staff_symbol_referencer::get_rounded_position (n);
 
       ps.push (p);
@@ -240,7 +240,7 @@ bool
 Stem::is_invisible (Grob *me)
 {
   return !(head_count (me)
-          && ly_scm2int (me->get_property ("duration-log")) >= 1);
+          && scm_to_int (me->get_property ("duration-log")) >= 1);
 }
 
 Direction
@@ -271,13 +271,13 @@ Stem::get_default_stem_end_position (Grob *me)
   /* WARNING: IN HALF SPACES */
   Real length = 7;
   SCM scm_len = me->get_property ("length");
-  if (ly_c_number_p (scm_len))
-    length = ly_scm2double (scm_len);
+  if (scm_is_number (scm_len))
+    length = scm_to_double (scm_len);
   else
     {
       s = me->get_property ("lengths");
-      if (ly_c_pair_p (s))
-       length = 2 * ly_scm2double (robust_list_ref (durlog - 2, s));
+      if (scm_is_pair (s))
+       length = 2 * scm_to_double (robust_list_ref (durlog - 2, s));
     }
 
   /* URGURGURG
@@ -295,7 +295,7 @@ Stem::get_default_stem_end_position (Grob *me)
   if (dir && dir * hp[dir] >= 0)
     {
       SCM sshorten = me->get_property ("stem-shorten");
-      SCM scm_shorten = ly_c_pair_p (sshorten) ?
+      SCM scm_shorten = scm_is_pair (sshorten) ?
        robust_list_ref ((duration_log (me) - 2) >? 0, sshorten): SCM_EOL;
       Real shorten = 2* robust_scm2double (scm_shorten,0);
 
@@ -380,7 +380,7 @@ int
 Stem::duration_log (Grob *me)
 {
   SCM s = me->get_property ("duration-log");
-  return (ly_c_number_p (s)) ? ly_scm2int (s) : 2;
+  return (scm_is_number (s)) ? scm_to_int (s) : 2;
 }
 
 void
@@ -401,10 +401,9 @@ Stem::position_noteheads (Grob *me)
   Real thick = thickness (me);
 
   Grob *hed = support_head (me);
-  Real w = Note_head::head_extent (hed, X_AXIS)[dir];
+  Real w = hed->extent (hed, X_AXIS)[dir];
   for (int i = 0; i < heads.size (); i++)
-    heads[i]->translate_axis (w - Note_head::head_extent (heads[i],
-                                                         X_AXIS)[dir],
+    heads[i]->translate_axis (w - heads[i]->extent (heads[i], X_AXIS)[dir],
                              X_AXIS);
 
   bool parity = true;
@@ -422,7 +421,7 @@ Stem::position_noteheads (Grob *me)
        {
          if (parity)
            {
-             Real ell = Note_head::head_extent (heads[i], X_AXIS).length ();
+             Real ell = heads[i]->extent (heads[i], X_AXIS).length ();
 
              Direction d = get_direction (me);
              /*
@@ -495,7 +494,7 @@ MAKE_SCHEME_CALLBACK (Stem, height, 2);
 SCM
 Stem::height (SCM smob, SCM ax)
 {
-  Axis a = (Axis)ly_scm2int (ax);
+  Axis a = (Axis)scm_to_int (ax);
   Grob *me = unsmob_grob (smob);
   assert (a == Y_AXIS);
 
@@ -532,7 +531,7 @@ Stem::flag (Grob *me)
   String flag_style;
 
   SCM flag_style_scm = me->get_property ("flag-style");
-  if (ly_c_symbol_p (flag_style_scm))
+  if (scm_is_symbol (flag_style_scm))
     flag_style = ly_symbol2string (flag_style_scm);
   
   if (flag_style == "no-flag")
@@ -551,37 +550,13 @@ Stem::flag (Grob *me)
     */
     {
       if (adjust)
-        {
-         /* Urrgh!  We have to detect wether this stem ends on a staff
-            line or between two staff lines.  But we can not call
-            stem_end_position (me) or get_default_stem_end_position (me),
-            since this encounters the flag and hence results in an
-            infinite recursion.  However, in pure mensural notation,
-            there are no multiple note heads attached to a single stem,
-            neither is there usually need for using the stem_shorten
-            property (except for 32th and 64th notes, but that is not a
-            problem since the stem length in this case is augmented by
-            an integral multiple of staff_space).  Hence, it should be
-            sufficient to just take the first note head, assume it's
-            the only one, look if it's on a staff line, and select the
-            flag's shape accordingly.  In the worst case, the shape
-            looks slightly misplaced, but that will usually be the
-            programmer's fault (e.g. when trying to attach multiple
-            note heads to a single stem in mensural notation).
-         */
-
-         /*
-           perhaps the detection whether this correction is needed should
-           happen in a different place  to avoid the recursion.
-       
-           --hwn.
-         */
-         int p = Staff_symbol_referencer::get_rounded_position (me);
-         staffline_offs = Staff_symbol_referencer::on_staffline (me, p)
-           ? "1" : "0";
+       {
+         int p = (int)(rint (stem_end_position (me)));
+         staffline_offs =
+           Staff_symbol_referencer::on_staffline (me, p) ? "0" : "1";
        }
       else
-        {
+       {
          staffline_offs = "2";
        }
     }
@@ -599,7 +574,7 @@ Stem::flag (Grob *me)
     me->warning (_f ("flag `%s' not found", font_char));
 
   SCM stroke_style_scm = me->get_property ("stroke-style");
-  if (ly_c_string_p (stroke_style_scm))
+  if (scm_is_string (stroke_style_scm))
     {
       String stroke_style = ly_scm2string (stroke_style_scm);
       if (!stroke_style.is_empty ())
@@ -620,22 +595,33 @@ MAKE_SCHEME_CALLBACK (Stem,dim_callback,2);
 SCM
 Stem::dim_callback (SCM e, SCM ax)
 {
-  Axis a = (Axis) ly_scm2int (ax);
+  Axis a = (Axis) scm_to_int (ax);
   assert (a == X_AXIS);
   Grob *me = unsmob_grob (e);
-  Interval r (0, 0);
-  if (unsmob_grob (me->get_property ("beam")) || abs (duration_log (me)) <= 2)
-    ;  // TODO!
+
+  Interval r;
+  
+  if (is_invisible (me))
+    {
+      r.set_empty ();
+    }    
+  else if (unsmob_grob (me->get_property ("beam")) || abs (duration_log (me)) <= 2)
+    {
+      r = Interval (-1,1);
+      r *= thickness (me)/2; 
+    }
   else
-    r = flag (me).extent (X_AXIS)
-      + thickness (me)/2;
+    {
+      r = flag (me).extent (X_AXIS)
+       + thickness (me)/2;
+    }  
   return ly_interval2scm (r);
 }
 
 Real
 Stem::thickness (Grob *me)
 {
-  return ly_scm2double (me->get_property ("thickness"))
+  return scm_to_double (me->get_property ("thickness"))
     * Staff_symbol_referencer::line_thickness (me);
 }
 
@@ -671,7 +657,7 @@ Stem::print (SCM smob)
       /*
        must not take ledgers into account.
        */
-      Interval head_height = Note_head::head_extent (hed,Y_AXIS);
+      Interval head_height = hed->extent (hed,Y_AXIS);
       Real y_attach = Note_head::stem_attachment_coordinate (hed, Y_AXIS);
 
       y_attach = head_height.linear_combination (y_attach);
@@ -682,7 +668,7 @@ Stem::print (SCM smob)
   // URG
   Real stem_width = thickness (me);
   Real blot =
-       me->get_paper ()->get_dimension (ly_symbol2scm ("blotdiameter"));
+       me->get_layout ()->get_dimension (ly_symbol2scm ("blotdiameter"));
 
   Box b = Box (Interval (-stem_width/2, stem_width/2),
               Interval (stem_y[DOWN]*dy, stem_y[UP]*dy));
@@ -714,7 +700,7 @@ Stem::off_callback (SCM element_smob, SCM)
   if (head_count (me))
     if (Grob *f = first_head (me))
       {
-       Interval head_wid = Note_head::head_extent (f, X_AXIS);
+       Interval head_wid = f->extent (f, X_AXIS);
        Real attach = 0.0;
        
        if (is_invisible (me))
@@ -736,11 +722,11 @@ Stem::off_callback (SCM element_smob, SCM)
   return scm_make_real (r);
 }
 
-Grob *
+Spanner *
 Stem::get_beam (Grob *me)
 {
   SCM b = me->get_property ("beam");
-  return unsmob_grob (b);
+  return dynamic_cast<Spanner*> (unsmob_grob (b));
 }
 
 Stem_info
@@ -748,7 +734,7 @@ Stem::get_stem_info (Grob *me)
 {
   /* Return cached info if available */
   SCM scm_info = me->get_property ("stem-info");
-  if (!ly_c_pair_p (scm_info))
+  if (!scm_is_pair (scm_info))
     {
       calc_stem_info (me);
       scm_info = me->get_property ("stem-info");
@@ -756,8 +742,8 @@ Stem::get_stem_info (Grob *me)
 
   Stem_info si;
   si.dir_ = get_grob_direction (me);
-  si.ideal_y_ = ly_scm2double (ly_car (scm_info));
-  si.shortest_y_ = ly_scm2double (ly_cadr (scm_info));
+  si.ideal_y_ = scm_to_double (scm_car (scm_info));
+  si.shortest_y_ = scm_to_double (scm_cadr (scm_info));
   return si;
 }
 
@@ -784,16 +770,18 @@ Stem::calc_stem_info (Grob *me)
   /* Simple standard stem length */
   SCM lengths = me->get_property ("beamed-lengths");
   Real ideal_length =
-    ly_scm2double (robust_list_ref (beam_count - 1,lengths))
+    scm_to_double (robust_list_ref (beam_count - 1,lengths))
                
     * staff_space
-    /* stem only extends to center of beam */
-    - 0.5 * beam_thickness;
+    /* stem only extends to center of beam
+    */
+    - 0.5 * beam_thickness
+    ;
 
   /* Condition: sane minimum free stem length (chord to beams) */
   lengths = me->get_property ("beamed-minimum-free-lengths");
   Real ideal_minimum_free =
-    ly_scm2double (robust_list_ref (beam_count - 1, lengths))
+    scm_to_double (robust_list_ref (beam_count - 1, lengths))
     * staff_space;
 
 
@@ -853,7 +841,7 @@ Stem::calc_stem_info (Grob *me)
   ideal_y -= robust_scm2double (beam->get_property ("shorten"), 0);
 
   Real minimum_free =
-    ly_scm2double (robust_list_ref
+    scm_to_double (robust_list_ref
                   (beam_count - 1,
                    me->get_property
                    ("beamed-extreme-minimum-free-lengths")))
@@ -877,8 +865,8 @@ Slice
 Stem::beam_multiplicity (Grob *stem)
 {
   SCM beaming= stem->get_property ("beaming");
-  Slice le = int_list_to_slice (ly_car (beaming));
-  Slice ri = int_list_to_slice (ly_cdr (beaming));
+  Slice le = int_list_to_slice (scm_car (beaming));
+  Slice ri = int_list_to_slice (scm_cdr (beaming));
   le.unite (ri);
   return le;
 }