lilypond-1.3.140
[lilypond.git] / lily / rest.cc
blob2efbf78e0417761b5ffee0424dc0c1745f47dd56
1 /*
2 rest.cc -- implement Rest
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "molecule.hh"
10 #include "paper-def.hh"
11 #include "font-interface.hh"
12 #include "rest.hh"
13 #include "dots.hh"
14 #include "paper-score.hh"
15 #include "staff-symbol-referencer.hh"
17 // -> offset callback
18 MAKE_SCHEME_CALLBACK (Rest,after_line_breaking,1);
19 SCM
20 Rest::after_line_breaking (SCM smob)
22 Grob *me = unsmob_grob (smob);
23 int bt = gh_scm2int (me->get_grob_property ("duration-log"));
24 if (bt == 0)
26 me->translate_axis (Staff_symbol_referencer::staff_space (me) , Y_AXIS);
29 Grob * d = unsmob_grob (me->get_grob_property ("dot"));
30 if (d && bt > 4) // UGH.
32 d->set_grob_property ("staff-position",
33 gh_int2scm ((bt == 7) ? 4 : 3));
36 return SCM_UNSPECIFIED;
40 make this function easily usable in C++
43 String
44 Rest::glyph_name (Grob * me, int balltype, String style)
46 bool ledger_b =false;
48 if (balltype == 0 || balltype == 1)
50 Real rad = Staff_symbol_referencer::staff_radius (me) * 2.0;
51 Real pos = Staff_symbol_referencer::position_f (me);
54 Figure out when the rest is far enough outside the staff. This
55 could bemore generic, but hey, we understand this even after
56 dinner.
59 ledger_b = ledger_b || (balltype == 0 && (pos >= rad +2 || pos < -rad ));
60 ledger_b = ledger_b || (balltype == 1 &&
61 (pos <= -rad -2 || pos > rad));
64 return ("rests-") + to_str (balltype)
65 + (ledger_b ? "o" : "") + style;
71 MAKE_SCHEME_CALLBACK (Rest,brew_molecule,1);
73 SCM
74 Rest::brew_internal_molecule (SCM smob)
76 Grob* me = unsmob_grob (smob);
78 SCM balltype_scm = me->get_grob_property ("duration-log");
79 if (!gh_number_p (balltype_scm))
80 return Molecule ().smobbed_copy ();
81 int balltype = gh_scm2int (balltype_scm);
83 String style;
84 SCM style_sym =me->get_grob_property ("style");
85 if (balltype >= 2 && gh_symbol_p (style_sym))
87 style = ly_scm2string (scm_symbol_to_string (style_sym));
90 String idx = glyph_name (me, balltype, style);
91 return Font_interface::get_default_font (me)->find_by_name (idx).smobbed_copy ();
94 SCM
95 Rest::brew_molecule (SCM smob)
97 return brew_internal_molecule (smob);
99 MAKE_SCHEME_CALLBACK (Rest,extent_callback,2);
101 We need the callback. The real molecule has ledgers depending on
102 Y-position. The Y-position is known only after line breaking. */
104 Rest::extent_callback (SCM smob, SCM ax)
106 Axis a = (Axis) gh_scm2int (ax);
107 SCM m = brew_internal_molecule (smob);
108 return ly_interval2scm (unsmob_molecule (m)->extent (a));
111 bool
112 Rest::has_interface (Grob*m)
114 return m && m->has_interface (ly_symbol2scm ("rest-interface"));