]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/local-key-item.cc
patch::: 1.3.86.jcn2
[lilypond.git] / lily / local-key-item.cc
index 3791f48b974af6a6683e4a01732e625b85d04a72..6ef1dfba8a7f1b83f601742b61b7ba2f213bdb95 100644 (file)
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
-#include "dimension.hh"
 #include "local-key-item.hh"
 #include "molecule.hh"
-#include "scalar.hh"
+#include "staff-symbol-referencer.hh"
 #include "lookup.hh"
 #include "paper-def.hh"
 #include "musical-request.hh"
-#include "note-head.hh"
+#include "rhythmic-head.hh"
 #include "misc.hh"
 
-Local_key_item::Local_key_item ()
+SCM
+pitch_less  (SCM p1, SCM p2)
 {
-  c0_position_i_  = 0;
+  for (int i = 3; i--; p1 = gh_cdr (p1), p2 = gh_cdr (p2))
+    {
+      if (scm_less_p (gh_car (p1), gh_car (p2)))
+       return SCM_BOOL_T;
+      if (gh_car (p1) != gh_car (p2))
+       return SCM_BOOL_F;
+    }
+  return SCM_BOOL_T;
 }
 
+SCM pitch_less_proc;
+
+
 void
-Local_key_item::add_support (Item*head_l)
+init_pitch_funcs ()
 {
-  if (support_items_.find_l(head_l))
-    return ;
-  support_items_.push (head_l);
-  add_dependency (head_l);
+  pitch_less_proc = gh_new_procedure2_0 ("pitch-less", &pitch_less);
 }
 
+ADD_SCM_INIT_FUNC(pitch,init_pitch_funcs);
+
+
 void
-Local_key_item::add (Musical_pitch p)
+Local_key_item::add_pitch (Score_element*me, Musical_pitch p, bool cautionary, bool natural)
 {
-  for (int i=0; i< accs.size(); i++)
-    if (!Musical_pitch::compare (p, accs[i]))
-      return;
-  
-  accs.push (p);
+  SCM acs = me->get_elt_property ("accidentals");
+  SCM pitch = p.to_scm ();
+  SCM opts = SCM_EOL;
+  if (cautionary)
+    opts = gh_cons (ly_symbol2scm ("cautionary"), opts);
+  if (natural)
+    opts = gh_cons (ly_symbol2scm ("natural"), opts);
+
+  pitch = gh_append2 (pitch, opts);
+  acs = scm_merge_x (acs, gh_cons (pitch, SCM_EOL), pitch_less_proc);
+
+  me->set_elt_property ("accidentals", acs);
 }
 
-void
-Local_key_item::do_pre_processing()
+Molecule
+Local_key_item::parenthesize (Score_element*me, Molecule m)
 {
-  accs.sort (Musical_pitch::compare);
+  Molecule open = me->lookup_l ()->afm_find (String ("accidentals-("));
+  Molecule close = me->lookup_l ()->afm_find (String ("accidentals-)"));
+  m.add_at_edge(X_AXIS, LEFT, Molecule(open), 0);
+  m.add_at_edge(X_AXIS, RIGHT, Molecule(close), 0);
+
+  return m;
 }
 
-Molecule*
-Local_key_item::brew_molecule_p() const
+/*
+  UGH. clean me, revise placement routine (See Ross & Wanske;
+  accidental placement is more complicated than this.
+ */
+
+MAKE_SCHEME_CALLBACK(Local_key_item,brew_molecule);
+SCM
+Local_key_item::brew_molecule (SCM smob)
 {
-  Molecule*output = new Molecule;
+  Score_element* me = unsmob_element (smob);
+  
+  Molecule mol;
 
-  Molecule *octave_mol_p = 0;
+  Real note_distance = Staff_symbol_referencer::staff_space (me)/2;
+  Molecule octave_mol;
+  bool oct_b = false;
   int lastoct = -100;
-  for  (int i = 0; i <  accs.size(); i++) 
+
+  SCM accs = me->get_elt_property ("accidentals");
+  for  (SCM s = accs;
+       gh_pair_p (s); s = gh_cdr (s))
     {
+      Musical_pitch p (gh_car (s));
+      
       // do one octave
-      if (accs[i].octave_i_ != lastoct) 
+      if (p.octave_i_ != lastoct) 
        {
-         if (octave_mol_p)
+         if (oct_b)
            {
-             Real dy =lastoct*7*paper()->internote_f ();
-             octave_mol_p->translate_axis (dy, Y_AXIS);
-             output->add_molecule (*octave_mol_p);
-             delete octave_mol_p;
+             Real dy =lastoct*7* note_distance;
+             octave_mol.translate_axis (dy, Y_AXIS);
+             mol.add_molecule (octave_mol);
+             octave_mol = Molecule ();
            }
-         octave_mol_p= new Molecule;
+         oct_b = true; 
+       }
+      
+      lastoct = p.octave_i_;
+
+      SCM c0 =  me->get_elt_property ("c0-position");
+      Real dy = (gh_number_p (c0) ? gh_scm2int (c0) : 0 + p.notename_i_)
+       * note_distance;
+      
+      Molecule acc (me->lookup_l ()->afm_find (String ("accidentals-")
+                                              + to_str (p.accidental_i_)));
+      
+      if (scm_memq (ly_symbol2scm ("natural"), gh_car (s)) != SCM_BOOL_F)
+       {
+         Molecule prefix = me->lookup_l ()->afm_find (String ("accidentals-0"));
+         acc.add_at_edge(X_AXIS, LEFT, Molecule(prefix), 0);
        }
-      lastoct = accs[i].octave_i_;
-      Real dy = (accs[i].notename_i_ + c0_position_i_) * paper()->internote_f ();
-      Atom a (lookup_l ()->accidental (accs[i].accidental_i_));
 
-      a.translate_axis (dy, Y_AXIS);
-      Molecule m(a);
-      octave_mol_p->add_at_edge (X_AXIS, RIGHT, m);
+      if (scm_memq (ly_symbol2scm ("cautionary"), gh_car (s)) != SCM_BOOL_F)
+       acc = parenthesize (me, acc);
+
+      acc.translate_axis (dy, Y_AXIS);
+      octave_mol.add_at_edge (X_AXIS, RIGHT, acc, 0);
     }
 
-  if (octave_mol_p)
+  if (oct_b)
     {
-      Real dy =lastoct*7*paper()->internote_f ();
-      octave_mol_p->translate_axis (dy, Y_AXIS);
-      output->add_molecule (*octave_mol_p);
-      delete octave_mol_p;
+      Real dy =lastoct*7*note_distance;
+      octave_mol.translate_axis (dy, Y_AXIS);
+      mol.add_molecule (octave_mol);
+      octave_mol = Molecule ();
     }
   
- if (accs.size()) 
+ if (gh_pair_p (accs))
     {
-      Box b(Interval (0, paper()->internote_f ()), Interval (0,0));
-      Molecule m (lookup_l ()->fill (b));
-      output->add_at_edge (X_AXIS, RIGHT, m);
+      Drul_array<SCM> pads;
+
+      /*
+       Use a cons?
+       */
+      pads[RIGHT] = me->get_elt_property ("right-padding");
+      pads[LEFT] = me->get_elt_property ("left-padding");
+
+
+      // unused ?
+      Direction d = LEFT;
+      do {
+       if (!gh_number_p (pads[d]))
+         continue;
+
+       Box b(Interval (0, gh_scm2double (pads[d]) * note_distance),
+             Interval (0,0));
+       Molecule m (me->lookup_l ()->blank (b));
+       mol.add_at_edge (X_AXIS, d, m, 0);
+      } while ( flip (&d)!= LEFT);
     }
 
-  Interval x_int;
-  for (int i=0; i < support_items_.size(); i++) 
-    {
-      Graphical_axis_group *common = 
-       common_group (support_items_[i], X_AXIS);
-
-      Real x = support_items_[i]->relative_coordinate (common, X_AXIS)  
-       -relative_coordinate (common, X_AXIS);
-
-      x_int.unite (x + support_items_[i]->width());
-    }
-  if (x_int.empty_b ())
-    x_int = Interval(0,0);
-  
-  output->translate_axis (-output->extent()[X_AXIS][RIGHT] + x_int[LEFT], X_AXIS);
-  
-  return output;
+  return mol.create_scheme();
 }
 
-IMPLEMENT_IS_TYPE_B1(Local_key_item,Item);
-
+bool
+Local_key_item::has_interface (Score_element*m)
+{
+  return m && m->has_interface (ly_symbol2scm ("accidentals-interface"));
+}
 void
-Local_key_item::do_substitute_dependency (Score_element*o,Score_element*n)
+Local_key_item::set_interface (Score_element*m)
 {
-  Item* o_l = o->access_Item ();
-  Item* n_l = n?n->access_Item ():0;
-
-  support_items_.substitute (o_l, n_l);
+  m->set_interface (ly_symbol2scm ("accidentals-interface"));
 }