]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head.cc
c072d2f461b505c0e3a9c03bd761efa85d8f38e5
[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--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "misc.hh"
10 #include "dots.hh"
11 #include "note-head.hh"
12 #include "debug.hh"
13 #include "lookup.hh"
14 #include "molecule.hh"
15 #include "musical-request.hh"
16 #include "dimension-cache.hh"
17 #include "staff-symbol-referencer.hh"
18
19
20
21 /*
22   build a ledger line for small pieces.
23  */
24 Molecule
25 Note_head::ledger_line (Interval xwid, Score_element *me) 
26 {
27   Drul_array<Molecule> endings;
28   endings[LEFT] = me->lookup_l()->afm_find ("noteheads-ledgerending");
29   Molecule *e = &endings[LEFT];
30   endings[RIGHT] = *e;
31   
32   Real thick = e->extent (Y_AXIS).length();
33   Real len = e->extent (X_AXIS).length () - thick;
34
35   Molecule total;
36   Direction d = LEFT;
37   do {
38     endings[d].translate_axis (xwid[d] - endings[d].extent (X_AXIS)[d], X_AXIS);
39     total.add_molecule (endings[d]);    
40   } while ((flip(&d)) != LEFT);
41
42   Real xpos = xwid [LEFT] + len;
43
44   while (xpos + len + thick /2 <= xwid[RIGHT])
45     {
46       e->translate_axis (len, X_AXIS);
47       total.add_molecule (*e);
48       xpos += len;
49     }
50
51   return total;
52 }
53
54
55
56
57 MAKE_SCHEME_SCORE_ELEMENT_CALLBACK(Note_head,brew_molecule);
58
59 SCM
60 Note_head::brew_molecule (SCM smob)  
61 {
62   Score_element *me = unsmob_element (smob);
63   Staff_symbol_referencer_interface si (me);
64   
65   Real inter_f = si.staff_space ()/2;
66   int sz = si.line_count ()-1;
67   Real p = si.position_f ();
68   int streepjes_i = abs (p) < sz 
69     ? 0
70     : (abs((int)p) - sz) /2;
71
72   SCM style  = me->get_elt_property ("style");
73   if (style == SCM_UNDEFINED)
74     {
75       style = ly_symbol2scm("default");
76     }
77   
78   Molecule out = me->lookup_l()->afm_find (String ("noteheads-") + 
79                 ly_scm2string (scm_eval (gh_list (ly_symbol2scm("find-notehead-symbol"),
80                                                   me->get_elt_property ("duration-log"),
81                                                   ly_quote_scm(style),
82                                                   SCM_UNDEFINED))));
83
84   if (streepjes_i) 
85     {
86       Direction dir = (Direction)sign (p);
87       Interval hd = out.extent (X_AXIS);
88       Real hw = hd.length ()/4;
89       Molecule ledger (ledger_line  (Interval (hd[LEFT] - hw,
90                                                hd[RIGHT] + hw), me));
91       
92
93       ledger.set_empty (true);
94       int parity =  abs(int (p)) % 2;
95       
96       for (int i=0; i < streepjes_i; i++)
97         {
98           Molecule s (ledger);
99           s.translate_axis (-dir * inter_f * (i*2 + parity),
100                            Y_AXIS);
101           out.add_molecule (s);
102         }
103     }
104   return out.create_scheme();
105 }