]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head.cc
* lily/tie-column.cc (set_manual_tie_configuration): new function.
[lilypond.git] / lily / note-head.cc
1 /*
2   notehead.cc -- implement Note_head
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "note-head.hh"
10
11 #include <cmath>
12 #include <cctype>
13 #include <algorithm>            //  min, max
14 using namespace std;
15
16 #include "directional-element-interface.hh"
17 #include "staff-symbol.hh"
18 #include "misc.hh"
19 #include "dots.hh"
20 #include "warn.hh"
21 #include "font-interface.hh"
22 #include "music.hh"
23 #include "rhythmic-head.hh"
24 #include "staff-symbol-referencer.hh"
25 #include "lookup.hh"
26 #include "output-def.hh"
27
28 /*
29   clean up the mess left by ledger line handling.
30 */
31 static Stencil
32 internal_print (Grob *me, String *font_char)
33 {
34   SCM style = me->get_property ("style");
35   if (!scm_is_symbol (style))
36     style = ly_symbol2scm ("default");
37
38   SCM log = scm_from_int (Note_head::get_balltype (me));
39   String suffix = to_string (min (robust_scm2int (me->get_property ("duration-log"), 2), 2));
40   if (style != ly_symbol2scm ("default"))
41     {
42       SCM proc = me->get_property ("glyph-name-procedure");
43       if (ly_is_procedure (proc))
44         suffix = ly_scm2string (scm_call_2 (proc, log, style));
45     }
46   Font_metric *fm = Font_interface::get_default_font (me);
47
48   String idx = "noteheads.s" + suffix;
49
50   Stencil out = fm->find_by_name (idx);
51   if (out.is_empty ())
52     {
53       String prefix = "noteheads.";
54       Grob *stem = unsmob_grob (me->get_object ("stem"));
55       Direction stem_dir = stem ? get_grob_direction (stem) : CENTER;
56
57       if (stem_dir == CENTER)
58         programming_error ("must have stem dir for note head");
59       String idx = prefix + ((stem_dir == UP) ? "u" : "d") + suffix;
60       out = fm->find_by_name (idx);
61     }
62
63   if (out.is_empty ())
64     {
65       me->warning (_f ("note head `%s' not found", idx.to_str0 ()));
66       out = Stencil (Box (Interval (0, 0), Interval (0, 0)), SCM_EOL);
67     }
68   else
69     *font_char = idx;
70
71   return out;
72 }
73
74 MAKE_SCHEME_CALLBACK (Note_head, print, 1);
75 SCM
76 Note_head::print (SCM smob)
77 {
78   Grob *me = unsmob_grob (smob);
79
80   String idx;
81   return internal_print (me, &idx).smobbed_copy ();
82 }
83
84 Real
85 Note_head::stem_attachment_coordinate (Grob *me, Axis a)
86 {
87   SCM brewer = me->get_property ("print-function");
88   Font_metric *fm = Font_interface::get_default_font (me);
89
90   if (brewer == Note_head::print_proc)
91     {
92       String key;
93       internal_print (me, &key);
94
95       int k = fm->name_to_index (key);
96       if (k >= 0)
97         {
98           Box b = fm->get_indexed_char (k);
99           Offset wxwy = fm->attachment_point (key);
100           Interval v = b[a];
101           if (!v.is_empty ())
102             return 2 * (wxwy[a] - v.center ()) / v.length ();
103         }
104     }
105
106   /*
107     Fallback
108   */
109   SCM v = me->get_property ("stem-attachment-function");
110   if (!ly_is_procedure (v))
111     return 0.0;
112
113   SCM result = scm_call_2 (v, me->self_scm (), scm_from_int (a));
114   if (!scm_is_pair (result))
115     return 0.0;
116
117   result = (a == X_AXIS) ? scm_car (result) : scm_cdr (result);
118
119   return robust_scm2double (result, 0);
120 }
121
122 int
123 Note_head::get_balltype (Grob *me)
124 {
125   SCM s = me->get_property ("duration-log");
126   return scm_is_number (s) ? min (scm_to_int (s), 2) : 0;
127 }
128
129 ADD_INTERFACE (Note_head, "note-head-interface",
130                "Note head",
131
132                /* properties */
133                "note-names "
134                "glyph-name-procedure "
135                "accidental-grob "
136                "style "
137                "stem-attachment-function");
138