]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/note-head.cc
* lily/my-lily-lexer.cc (My_lily_lexer): don't crash
[lilypond.git] / lily / note-head.cc
index f77eea73c77d58dfc4ec1c6a14dbfcd1552ce33f..4c291ae32d9c107f799ada95b4daa30724799c13 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 #include <math.h>
 #include <ctype.h>
 #include "misc.hh"
 #include "dots.hh"
 #include "note-head.hh"
-#include "debug.hh"
+#include "warn.hh"
 #include "font-interface.hh"
 #include "molecule.hh"
-#include "musical-request.hh"
+#include "event.hh"
 #include "rhythmic-head.hh"
 #include "staff-symbol-referencer.hh"
 #include "lookup.hh"
 
 */
 
+/*
+  TODO: ledger lines are also a property of the staff. Maybe move them
+  to there?
+ */
 Molecule
 Note_head::brew_ledger_lines (Grob *me,
                               int pos,
@@ -73,21 +77,16 @@ Note_head::brew_ledger_lines (Grob *me,
   if (lines_i)
     {
       Real ledgerlinethickness =
-       (me->paper_l ()->get_var ("ledgerlinethickness"));
+       (me->get_paper ()->get_realvar (ly_symbol2scm ("ledgerlinethickness")));
       Real blotdiameter = ledgerlinethickness;
-      //       (me->paper_l ()->get_var ("blotdiameter"));
+      //       (me->get_paper ()->get_realvar (ly_symbol2scm ("blotdiameter")));
       Interval y_extent =
        Interval (-0.5*(ledgerlinethickness),
                  +0.5*(ledgerlinethickness));
       Box ledger_line (x_extent, y_extent);
 
-#if 1
       Molecule proto_ledger_line =
-       Lookup::roundfilledbox (ledger_line, blotdiameter);
-#else
-      Molecule proto_ledger_line = // if you like it the old way
-       Lookup::filledbox (ledger_line);
-#endif
+       Lookup::round_filled_box (ledger_line, blotdiameter);
       
       if (!take_space)
         proto_ledger_line.set_empty (true);
@@ -108,35 +107,35 @@ Note_head::brew_ledger_lines (Grob *me,
 }
 
 Molecule
-internal_brew_molecule (Grob *me,  bool ledger_take_space)
+internal_brew_molecule (Grob *me, bool ledger_take_space)
 {
   SCM style  = me->get_grob_property ("style");
   if (!gh_symbol_p (style))
     {
-      return Molecule();
+      return Molecule ();
     }
 
-  /*
-    ugh: use gh_call () / scm_apply ().
+  SCM log = gh_int2scm (Note_head::get_balltype (me));
+  SCM proc = me->get_grob_property ("glyph-name-procedure");
+  SCM scm_font_char = scm_call_2 (proc, log, style);
+  String font_char = "noteheads-" + ly_scm2string (scm_font_char);
 
-    UGH: use grob-property.
-  */
-  SCM log = gh_int2scm (Rhythmic_head::balltype_i (me));
-  SCM exp = scm_list_n (ly_symbol2scm ("find-notehead-symbol"), log,
-                       ly_quote_scm (style),
-                       SCM_UNDEFINED);
-  String name = "noteheads-" + ly_scm2string (scm_primitive_eval (exp));
-  Molecule out = Font_interface::get_default_font (me)->find_by_name (name);
+  Font_metric * fm = Font_interface::get_default_font (me);
+  Molecule out = fm->find_by_name (font_char);
+  if (out.empty_b())
+    {
+      me->warning (_f ("note head `%s' not found", font_char.to_str0 ()));
+    }
 
   int interspaces = Staff_symbol_referencer::line_count (me)-1;
-  int pos = (int)rint (Staff_symbol_referencer::position_f (me));
+  int pos = (int)rint (Staff_symbol_referencer::get_position (me));
   if (abs (pos) - interspaces > 1)
     {
       Interval hd = out.extent (X_AXIS);
       Real left_ledger_protusion = hd.length ()/4;
       Real right_ledger_protusion = left_ledger_protusion;
 
-      if (unsmob_grob(me->get_grob_property ("accidentals-grob")))
+      if (unsmob_grob(me->get_grob_property ("accidental-grob")))
        {
          /*
            make a little room for accidentals.
@@ -173,11 +172,15 @@ Note_head::brew_molecule (SCM smob)
 
 /*
   Compute the width the head without ledgers.
+
+  -- there used to be some code from the time that ledgers
+  did take space. Nowadays, we can simply take the standard extent.
  */
 Interval
 Note_head::head_extent (Grob *me, Axis a)
 {
-  return internal_brew_molecule (me, false).extent (a);
+  Molecule * mol = me->get_molecule();
+  return mol ? mol ->extent (a) : Interval(0,0);
 }
 
 
@@ -188,7 +191,7 @@ SCM
 Note_head::brew_ez_molecule (SCM smob)
 {
   Grob *me = unsmob_grob (smob);
-  int l = Rhythmic_head::balltype_i (me);
+  int l = Note_head::get_balltype (me);
 
   int b = (l >= 2);
 
@@ -197,10 +200,10 @@ Note_head::brew_ez_molecule (SCM smob)
   Pitch* pit =  unsmob_pitch (spitch);
 
   char s[2] = "a";
-  s[0] = (pit->notename_i_ + 2)%7 + 'a';
+  s[0] = (pit->get_notename () + 2)%7 + 'a';
   s[0] = toupper (s[0]);
   
-  SCM charstr = ly_str02scm (s);
+  SCM charstr = scm_makfrom0str (s);
   
   SCM at = scm_list_n (ly_symbol2scm ("ez-ball"),
                       charstr,
@@ -210,7 +213,7 @@ Note_head::brew_ez_molecule (SCM smob)
   Box bx (Interval (0, 1.0), Interval (-0.5, 0.5));
   Molecule m (bx, at);
 
-  int pos = (int)rint (Staff_symbol_referencer::position_f (me));
+  int pos = (int)rint (Staff_symbol_referencer::get_position (me));
   int interspaces = Staff_symbol_referencer::line_count (me)-1;
   if (abs (pos) - interspaces > 1)
     {
@@ -233,7 +236,8 @@ Note_head::stem_attachment_coordinate (Grob *me, Axis a)
     return 0.0;
 
   SCM st = me->get_grob_property ("style");
-  SCM result = gh_apply (v, scm_list_n (st, SCM_UNDEFINED));
+  SCM log = gh_int2scm (get_balltype (me));
+  SCM result = gh_apply (v, scm_list_n (st, log, SCM_UNDEFINED));
 
   if (!gh_pair_p (result))
     return 0.0;
@@ -243,6 +247,14 @@ Note_head::stem_attachment_coordinate (Grob *me, Axis a)
   return gh_number_p (result) ?  gh_scm2double (result) : 0.0;
 }
 
+int
+Note_head::get_balltype (Grob*me) 
+{
+  SCM s = me->get_grob_property ("duration-log");
+  return gh_number_p (s) ? gh_scm2int (s) <? 2 : 0;
+}
+
 ADD_INTERFACE (Note_head,"note-head-interface",
   "Note head",
-  "accidentals-grob style stem-attachment-function");
+  "glyph-name-procedure accidental-grob style stem-attachment-function");
+