]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/local-key-item.cc
release: 1.5.19
[lilypond.git] / lily / local-key-item.cc
index 634a4b7b3f6236066a1e98fc36fa52c7afc18663..52e7a65f775b03f063d2b9eab60c4a94ee80c07b 100644 (file)
@@ -20,7 +20,7 @@
 static SCM
 pitch_less (SCM p1, SCM p2)
 {
-  return Pitch::less_p (gh_car (p1),  gh_car (p2));
+  return Pitch::less_p (ly_car (p1),  ly_car (p2));
 }
 
 static SCM pitch_less_proc;
@@ -28,7 +28,7 @@ static SCM pitch_less_proc;
 void
 init_pitch_funcs ()
 {
-  pitch_less_proc = gh_new_procedure2_0 ("pits-less", &pitch_less);
+  pitch_less_proc = gh_new_procedure2_0 ("pitch-less", &pitch_less);
 }
 
 ADD_SCM_INIT_FUNC (lkpitch,init_pitch_funcs);
@@ -40,7 +40,10 @@ Local_key_item::add_pitch (Grob*me, Pitch p, bool cautionary, bool natural,
 {
   SCM acs = me->get_grob_property ("accidentals");
   SCM pitch = p.smobbed_copy ();
-  SCM opts = SCM_EOL;
+  SCM opts = scm_assoc (pitch, acs);
+  bool new_pitch = !gh_pair_p (opts);
+  opts= new_pitch ? SCM_EOL : gh_cdr (opts);
+  
   if (cautionary)
     opts = gh_cons (ly_symbol2scm ("cautionary"), opts);
   if (natural)
@@ -52,8 +55,13 @@ Local_key_item::add_pitch (Grob*me, Pitch p, bool cautionary, bool natural,
       opts = gh_cons (ly_symbol2scm ("tie-break-reminder"), opts);
     }
 
-  pitch = gh_cons (pitch, opts);
-  acs = scm_merge_x (acs, gh_cons (pitch, SCM_EOL), pitch_less_proc);
+  if (new_pitch)
+    {
+      pitch = gh_cons (pitch, opts);
+      acs = scm_merge_x (acs, gh_cons (pitch, SCM_EOL), pitch_less_proc);
+    }
+  else
+    scm_assoc_set_x (acs, pitch, opts);
 
   me->set_grob_property ("accidentals", acs);
 }
@@ -61,7 +69,7 @@ Local_key_item::add_pitch (Grob*me, Pitch p, bool cautionary, bool natural,
 Molecule
 Local_key_item::parenthesize (Grob*me, Molecule m)
 {
-  Molecule open = Font_interface::get_default_font (me)->find_by_name (String ("accidentals- ("));
+  Molecule open = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-("));
   Molecule close = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-)"));
   m.add_at_edge (X_AXIS, LEFT, Molecule (open), 0);
   m.add_at_edge (X_AXIS, RIGHT, Molecule (close), 0);
@@ -85,19 +93,19 @@ Local_key_item::after_line_breaking (SCM smob)
 
   SCM accs = me->get_grob_property ("accidentals");
   for (SCM s = accs;
-       gh_pair_p (s); s = gh_cdr (s))
+       gh_pair_p (s); s = ly_cdr (s))
     {
-      SCM opts = gh_cdar (s);
+      SCM opts = ly_cdar (s);
 
       SCM t = scm_memq (ly_symbol2scm ("tie-break-reminder"), opts);
       if (t != SCM_BOOL_F)
        {
-         Grob *tie = unsmob_grob (gh_cadr (t));
+         Grob *tie = unsmob_grob (ly_cadr (t));
          Spanner *sp = dynamic_cast<Spanner*> (tie);
          if (!sp->original_l_)
            {
              /* there should be a better way to delete part of me */
-             scm_set_car_x (s, gh_list (gh_caar (s),
+             scm_set_car_x (s, scm_list_n (ly_caar (s),
                                         ly_symbol2scm ("deleted"),
                                         SCM_UNDEFINED));
              me->set_grob_property ("molecule", SCM_EOL);
@@ -126,12 +134,26 @@ Local_key_item::brew_molecule (SCM smob)
   bool oct_b = false;
   int lastoct = -100;
 
+  SCM scm_style = me->get_grob_property ("style");
+  String style;
+  if (gh_symbol_p (scm_style))
+    {
+      style = ly_scm2string (scm_symbol_to_string (scm_style));
+    }
+  else
+    {
+      /*
+       preferably no name for the default style.
+       */
+      style = "";
+    }
+
   SCM accs = me->get_grob_property ("accidentals");
   for (SCM s = accs;
-       gh_pair_p (s); s = gh_cdr (s))
+       gh_pair_p (s); s = ly_cdr (s))
     {
-      Pitch p (*unsmob_pitch (gh_caar (s)));
-      SCM opts = gh_cdar (s);
+      Pitch p (*unsmob_pitch (ly_caar (s)));
+      SCM opts = ly_cdar (s);
       
       if (scm_memq (ly_symbol2scm ("deleted"), opts) != SCM_BOOL_F)
        continue;
@@ -149,23 +171,38 @@ Local_key_item::brew_molecule (SCM smob)
          oct_b = true; 
        }
       
+
       lastoct = p.octave_i () ;
 
+      bool cautionary = (scm_memq (ly_symbol2scm ("cautionary"), opts) != SCM_BOOL_F);
+      SCM font_rel_siz = me->get_grob_property("font-relative-size");
+      SCM caut_siz = me->get_grob_property("cautionary-size");
+      int frs = (gh_exact_p(font_rel_siz) ? gh_scm2int(font_rel_siz) : 0);
+      int cs = (gh_exact_p(caut_siz) ? gh_scm2int(caut_siz) : 0);
+
+
+      // Ugh. This will only work if only called once on each grob. --rz
+      if (cautionary && caut_siz!=0)
+       me->set_grob_property ("font-relative-size",gh_int2scm(frs+cs));
+
       SCM c0 =  me->get_grob_property ("c0-position");
       Real dy = (gh_number_p (c0) ? gh_scm2int (c0) : 0 + p.notename_i_)
        * note_distance;
-      
-      Molecule acc (Font_interface::get_default_font (me)->find_by_name (String ("accidentals-")
-                                              + to_str (p.alteration_i_)));
+
+      Molecule acc (Font_interface::get_default_font (me)->
+                   find_by_name (String ("accidentals-") +
+                                 style +
+                                 to_str (p.alteration_i_)));
       
       if (scm_memq (ly_symbol2scm ("natural"), opts) != SCM_BOOL_F)
        {
-         Molecule prefix = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-0"));
+         Molecule prefix = Font_interface::get_default_font (me)->
+             find_by_name (String ("accidentals-") + style + String ("0"));
          acc.add_at_edge (X_AXIS, LEFT, Molecule (prefix), 0);
        }
 
-      if (scm_memq (ly_symbol2scm ("cautionary"), opts) != SCM_BOOL_F)
-       acc = parenthesize (me, acc);
+      if (cautionary && to_boolean(me->get_grob_property("paren-cautionaries")))
+        acc = parenthesize (me, acc);
 
       acc.translate_axis (dy, Y_AXIS);
       octave_mol.add_at_edge (X_AXIS, RIGHT, acc, 0);