]> git.donarmstrong.com Git - lilypond.git/commitdiff
robust_scm2fraction
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 18 Jan 2007 12:11:47 +0000 (13:11 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 18 Jan 2007 12:11:47 +0000 (13:11 +0100)
lily/accidental.cc
lily/ambitus-engraver.cc
lily/include/lily-guile.hh
lily/include/tie-formatting-problem.hh
lily/key-engraver.cc
lily/lily-guile.cc

index 46db4f4f2f0bf51af1694c30dfc0fe3827d014e2..3bfd1b816d1e91f15f7257979381efde7df3c53d 100644 (file)
@@ -66,13 +66,16 @@ Accidental_interface::accurate_boxes (Grob *me, Grob **common)
   vector<Box> boxes;
 
   bool parens = to_boolean (me->get_property ("parenthesized"));
+  if (!me->is_live ())
+    return boxes;
 
   SCM scm_style = me->get_property ("style");
   if (!scm_is_symbol (scm_style)
       && !to_boolean (me->get_property ("restore-first"))
       && !parens)
     {
-      Rational alteration = ly_scm2rational (me->get_property ("alteration"));
+      Rational alteration
+       = robust_scm2rational (me->get_property ("alteration"), 0);
       if (alteration == FLAT_ALTERATION)
        {
          Box stem = b;
@@ -151,7 +154,7 @@ Accidental_interface::print (SCM smob)
   if (!scm_is_string (glyph_name))
     {
       me->warning (_f ("Could not find glyph-name for alteration %s",
-                      ly_scm2rational (alt).to_string ().c_str ()));
+                      ly_scm_write_string (alt).c_str ()));
       return SCM_EOL;
     }
   
index 0e4e2d949b8006bfb899909b10837a1d9176e0f5..e2fdcc9595cb38dcf50aa7b46155b29efe3ab705 100644 (file)
@@ -149,7 +149,7 @@ Ambitus_engraver::finalize ()
                                start_key_sig_);
 
          Rational sig_alter = (handle != SCM_BOOL_F)
-           ? ly_scm2rational (scm_cdr (handle)) : Rational (0);
+           ? robust_scm2rational (scm_cdr (handle), Rational (0)) : Rational (0);
 
          if (sig_alter == p.get_alteration ())
            {
index 6eef555bf599cef61ca47dc41299d06e31cf4551..6f21a29b03c172e53c7c720a9628027a556a7e06 100644 (file)
@@ -32,7 +32,7 @@
     A ly_B2A (B b);  */
 
 SCM ly_last (SCM list);
-SCM ly_write2scm (SCM s);
+string ly_scm_write_string (SCM s);
 SCM ly_deep_copy (SCM);
 SCM ly_truncate_list (int k, SCM lst);
 
@@ -65,6 +65,7 @@ Drul_array<bool> robust_scm2booldrul (SCM, Drul_array<bool>);
 Interval robust_scm2interval (SCM, Drul_array<Real>);
 Offset robust_scm2offset (SCM, Offset);
 string robust_scm2string (SCM, string);
+Rational robust_scm2rational (SCM, Rational);
 
   
 SCM ly_quote_scm (SCM s);
@@ -81,6 +82,8 @@ SCM ly_hash2alist (SCM tab);
 SCM ly_hash_table_keys (SCM tab);
 
 SCM ly_assoc_prepend_x (SCM alist, SCM key, SCM val);
+inline bool ly_is_fraction (SCM x) { return SCM_FRACTIONP(x) || scm_is_integer (x); }
+    
 inline bool ly_is_list (SCM x) { return SCM_NFALSEP (scm_list_p (x)); }
 inline bool ly_is_procedure (SCM x) { return SCM_NFALSEP (scm_procedure_p (x)); }
 inline bool ly_is_port (SCM x) { return SCM_NFALSEP (scm_port_p (x)); }
index ebee98877fd69b4c9f03686ff008fbb250028149..50f1746b86ba374abb138d9e1a2372051fb16fff 100644 (file)
@@ -31,6 +31,7 @@ struct Tie_configuration_variation
 typedef map < Tuple<int, 2>, Skyline> Chord_outline_map;
 typedef map < Tuple<int, 2>, Box> Column_extent_map;
 typedef map <int, Slice> Position_extent_map;
+
 class Tie_formatting_problem
 {
   Chord_outline_map chord_outlines_;
index c086f3d250198c6ce37431a81e70952825e8e5a3..36199d704146b7b9b1609a5c971ee1929526a296 100644 (file)
@@ -77,7 +77,7 @@ Key_engraver::create_key (bool is_default)
          for (SCM s = last; scm_is_pair (s); s = scm_cdr (s))
            {
              SCM new_alter_pair = scm_assoc (scm_caar (s), key);
-             Rational old_alter = ly_scm2rational (scm_cdar (s));
+             Rational old_alter = robust_scm2rational (scm_cdar (s), 0);
              if (new_alter_pair == SCM_BOOL_F
                  || extranatural
                  && (ly_scm2rational (scm_cdr (new_alter_pair)) - old_alter)*old_alter < Rational (0))
index a1a635961c02cc9e46bc4587ce32e1cc3ef76241..976b19e47c0819a32111fea6f28d5261d24ee2ae 100644 (file)
@@ -34,8 +34,8 @@ using namespace std;
 /*
   symbols/strings.
  */
-SCM
-ly_write2scm (SCM s)
+string
+ly_scm_write_string (SCM s)
 {
   SCM port = scm_mkstrport (SCM_INUM0,
                            scm_make_string (SCM_INUM0, SCM_UNDEFINED),
@@ -46,7 +46,7 @@ ly_write2scm (SCM s)
 
   // scm_apply (write, port, SCM_EOL);
   scm_call_2 (write, s, port);
-  return scm_strport_to_string (port);
+  return ly_scm2string (scm_strport_to_string (port));
 }
 
 SCM
@@ -394,7 +394,7 @@ ly_deep_copy (SCM src)
 string
 print_scm_val (SCM val)
 {
-  string realval = ly_scm2string (ly_write2scm (val));
+  string realval = ly_scm_write_string (val);
   if (realval.length () > 200)
     realval = realval.substr (0, 100)
       + "\n :\n :\n"
@@ -582,6 +582,14 @@ ly_scm2rational (SCM r)
                   scm_to_int (scm_denominator (r)));
 }
 
+Rational
+robust_scm2rational (SCM n, Rational rat)
+{
+  if (ly_is_fraction (n))
+    return ly_scm2rational (n);
+  else
+    return rat;
+}
 
 SCM
 alist_to_hashq (SCM alist)
@@ -653,13 +661,7 @@ parse_symbol_list (char const *symbols)
   return ly_string_array_to_scm (string_split (s, ' '));
 }
 
-
-bool
-ly_is_fraction (SCM x)
-{
-  return SCM_FRACTIONP(x);
-}
-
+/* GDB debugging. */
 struct ly_t_double_cell
 {
   SCM a;