2 notehead.cc -- implement Note_head
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "note-head.hh"
14 #include "font-interface.hh"
15 #include "molecule.hh"
16 #include "musical-request.hh"
18 #include "staff-symbol-referencer.hh"
21 build a ledger line for small pieces.
24 Note_head::ledger_line (Interval xwid
, Grob
*me
)
26 Drul_array
<Molecule
> endings
;
27 endings
[LEFT
] = Font_interface::get_default_font (me
)->find_by_name ("noteheads-ledgerending");
28 Molecule
*e
= &endings
[LEFT
];
31 Real thick
= e
->extent (Y_AXIS
).length ();
32 Real len
= e
->extent (X_AXIS
).length () - thick
;
37 endings
[d
].translate_axis (xwid
[d
] - endings
[d
].extent (X_AXIS
)[d
], X_AXIS
);
38 total
.add_molecule (endings
[d
]);
39 } while ((flip (&d
)) != LEFT
);
41 Real xpos
= xwid
[LEFT
] + len
;
43 while (xpos
+ len
+ thick
/2 <= xwid
[RIGHT
])
45 e
->translate_axis (len
, X_AXIS
);
46 total
.add_molecule (*e
);
55 Note_head::ledger_lines (Grob
*me
, int count
, Direction dir
, Interval idw
)
57 Real inter_f
= Staff_symbol_referencer::staff_space (me
)/2;
58 Molecule
ledger (ledger_line (idw
, me
));
60 ledger
.set_empty (true);
61 Real offs
= (Staff_symbol_referencer::on_staffline (me
))
66 for (int i
=0; i
< count
; i
++)
69 s
.translate_axis (-dir
* inter_f
* i
*2 + offs
,
71 legs
.add_molecule (s
);
77 MAKE_SCHEME_CALLBACK (Note_head
,brew_molecule
,1);
80 Note_head::brew_molecule (SCM smob
)
82 Grob
*me
= unsmob_grob (smob
);
84 int sz
= Staff_symbol_referencer::line_count (me
)-1;
85 int p
= (int) rint (Staff_symbol_referencer::position_f (me
));
86 int streepjes_i
= abs (p
) < sz
90 SCM style
= me
->get_grob_property ("style");
91 if (!gh_symbol_p (style
))
97 ugh: use gh_call () / scm_apply ().
99 UGH: use grob-property.
101 Molecule out
= Font_interface::get_default_font (me
)->find_by_name (String ("noteheads-") +
102 ly_scm2string (scm_primitive_eval (gh_list (ly_symbol2scm ("find-notehead-symbol"),
103 me
->get_grob_property ("duration-log"),
104 ly_quote_scm (style
),
109 Direction dir
= (Direction
)sign (p
);
110 Interval hd
= out
.extent (X_AXIS
);
111 Real hw
= hd
.length ()/4;
112 out
.add_molecule (ledger_lines (me
, streepjes_i
, dir
,
113 Interval (hd
[LEFT
] - hw
,
117 return out
.smobbed_copy ();
121 Note_head::has_interface (Grob
*m
)
123 return m
&& m
->has_interface (ly_symbol2scm ("note-head-interface"));
127 MAKE_SCHEME_CALLBACK (Note_head
,brew_ez_molecule
,1);
130 Note_head::brew_ez_molecule (SCM smob
)
132 Grob
*me
= unsmob_grob (smob
);
133 int l
= gh_scm2int (me
->get_grob_property ("duration-log"));
136 SCM at
= gh_list (ly_symbol2scm ("ez-ball"),
137 me
->get_grob_property ("note-character"),
141 Box
bx (Interval (0, 1.0), Interval (-0.5, 0.5));
143 int p
= (int) rint (Staff_symbol_referencer::position_f (me
));
145 int sz
= Staff_symbol_referencer::line_count (me
)-1;
146 int streepjes_i
= abs (p
) < sz
152 Direction dir
= (Direction
)sign (p
);
153 Interval hd
= m
.extent (X_AXIS
);
154 Real hw
= hd
.length ()/4;
155 m
.add_molecule (ledger_lines (me
, streepjes_i
, dir
,
156 Interval (hd
[LEFT
] - hw
,
160 return m
.smobbed_copy ();
165 Note_head::stem_attachment_coordinate (Grob
*me
, Axis a
)
167 SCM v
= me
->get_grob_property ("stem-attachment-function");
169 if (!gh_procedure_p (v
))
172 SCM st
= me
->get_grob_property ("style");
173 SCM result
= gh_apply (v
, gh_list (st
, SCM_UNDEFINED
));
175 if (!gh_pair_p (result
))
178 result
= (a
== X_AXIS
) ? gh_car (result
) : gh_cdr (result
);
180 return gh_number_p (result
) ? gh_scm2double (result
) : 0.0;