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