]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/note-head.cc
release: 1.3.25
[lilypond.git] / lily / note-head.cc
index 3ae349b28bfcef63ecdc2b218ac7e55f4b7010f5..d7da247660a90f0b37a419021e636ae9bbe7b97f 100644 (file)
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 #include "misc.hh"
 #include "dots.hh"
 #include "note-head.hh"
-#include "dimen.hh" 
 #include "debug.hh"
-#include "paper-def.hh"
 #include "lookup.hh"
 #include "molecule.hh"
 #include "musical-request.hh"
+#include "dimension-cache.hh"
+#include "staff-symbol-referencer.hh"
 
 
-Note_head::Note_head ()
+
+/*
+  build a ledger line for small pieces.
+ */
+Molecule
+Note_head::ledger_line (Interval xwid) const
 {
-  x_dir_ = CENTER;
-  staff_size_i_= 8;            // UGH
-  position_i_ = 0;
-  extremal_i_ = 0;
+  Drul_array<Molecule> endings;
+  endings[LEFT] = lookup_l()->afm_find ("noteheads-ledgerending");
+  Molecule * e = &endings[LEFT];
+  endings[RIGHT] = *e;
+  
+  Real thick = e->dim_[Y_AXIS].length();
+  Real len = e->dim_[X_AXIS].length () - thick;
+
+  Molecule total;
+  Direction d = LEFT;
+  do {
+    endings[d].translate_axis (xwid[d] - endings[d].dim_[X_AXIS][d], X_AXIS);
+    total.add_molecule (endings[d]);    
+  } while ((flip(&d)) != LEFT);
+
+  Real xpos = xwid [LEFT] + len;
+
+  while (xpos + len + thick /2 <= xwid[RIGHT])
+    {
+      e->translate_axis (len, X_AXIS);
+      total.add_molecule (*e);
+      xpos += len;
+    }
+
+  return total;
 }
 
+
 void
 Note_head::do_pre_processing ()
 {
   // 8 ball looks the same as 4 ball:
-  if (balltype_i_ > 2)
-    balltype_i_ = 2;
-  if (dots_l_)                 // move into Rhythmic_head?
-    dots_l_->position_i_ = position_i_;
-}
+  String type; 
+  SCM style  = get_elt_property ("style");
+  if (gh_string_p (style))
+    {
+      type = ly_scm2string (style);
+    }
+  
+  
+  if (balltype_i () > 2 || type == "harmonic" || type == "cross")
+    set_elt_property ("duration-log", gh_int2scm (2));
 
-IMPLEMENT_IS_TYPE_B1(Note_head,Rhythmic_head);
+  if (Dots *d = dots_l ())
+    { // move into Rhythmic_head?
+      Staff_symbol_referencer_interface si (d);
+      Staff_symbol_referencer_interface me (this);      
+      
+      si.set_position(int (me.position_f ()));
+    }
+}
 
 
-int
-Note_head::compare (Note_head *const  &a, Note_head * const &b)
-{
-  return a->position_i_ - b->position_i_;
-}
 
-Interval
-Note_head::do_width () const
-{
-  Atom a =  paper ()->lookup_l()->ball (balltype_i_);
-  Interval i = a.dim_[X_AXIS];
-  i+= x_dir_ * i.length ();
-  return i;
-}
 
 Molecule*
-Note_head::brew_molecule_p() const 
+Note_head::do_brew_molecule_p() const 
 {
-  Molecule*out = 0;
-  Paper_def *p = paper();
-  Real inter_f = p->internote_f ();
-
-  // ugh
-  int streepjes_i = abs (position_i_) < staff_size_i_/2 
+  Staff_symbol_referencer_interface si (this);
+  
+  Real inter_f = si.staff_space ()/2;
+  int sz = si.line_count ()-1;
+  Real p = si.position_f ();
+  int streepjes_i = abs (p) < sz 
     ? 0
-    : (abs(position_i_) - staff_size_i_/2) /2;
+    : (abs((int)p) - sz) /2;
+
+ String type; 
+  SCM style  = get_elt_property ("style");
+  if (gh_string_p (style))
+    {
+      type = ly_scm2string (style);
+    }
   
-  Atom  s = p->lookup_l()->ball (balltype_i_);
-  out = new Molecule (Atom (s));
-  out->translate_axis (x_dir_ * s.dim_[X_AXIS].length (), X_AXIS);
+  Molecule*  out =
+    new Molecule (lookup_l()->afm_find (String ("noteheads-") + to_str (balltype_i ()) + type));
+
+  Box ledgerless = out->dim_;
 
   if (streepjes_i) 
     {
-      int dir = sign (position_i_);
-      Atom streepje = p->lookup_l ()->streepje (balltype_i_);
+      Direction dir = (Direction)sign (p);
+      Interval hd = out->dim_[X_AXIS];
+      Real hw = hd.length ()/4;
       
-      int parity =  (position_i_ % 2) ? 1 : 0;
-       
+      Molecule ledger (ledger_line  (Interval (hd[LEFT] - hw,
+                                              hd[RIGHT] + hw)));
+      
+      int parity =  abs(int (p)) % 2;
       
       for (int i=0; i < streepjes_i; i++)
        {
-         Atom s = streepje;
+         Molecule s (ledger);
          s.translate_axis (-dir * inter_f * (i*2 + parity),
                           Y_AXIS);
-         out->add (s);
+         out->add_molecule (s);
        }
     }
-  
-  out->translate_axis (inter_f*position_i_, Y_AXIS);
+
+  out->dim_ = ledgerless;
   return out;
 }
+