]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest.cc
a8264b0ef67d4582570ee69fd5abe4f6b37f454f
[lilypond.git] / lily / rest.cc
1 /*
2  rest.cc -- implement Rest
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 "molecule.hh"
10 #include "paper-def.hh"
11 #include "lookup.hh"
12 #include "rest.hh"
13 #include "dots.hh"
14 #include "paper-score.hh"
15 #include "staff-symbol-referencer.hh"
16
17 // -> offset callback
18 MAKE_SCHEME_SCORE_ELEMENT_CALLBACK(Rest,after_line_breaking);
19 SCM
20 Rest::after_line_breaking (SCM smob)
21 {
22   Score_element *me = unsmob_element (smob);
23   int bt = gh_scm2int (me->get_elt_property ("duration-log"));
24   if (bt == 0)
25     {
26       Staff_symbol_referencer_interface si (me);
27       me->translate_axis (si.staff_space() , Y_AXIS);
28     }
29
30   Score_element * d = unsmob_element (me->get_elt_pointer ("dot"));
31   if (d && bt > 4) // UGH.
32     {
33       d->set_elt_property ("staff-position",
34                            gh_int2scm ((bt == 7) ? 4 : 3));
35     }
36
37   return SCM_UNDEFINED;
38 }
39
40
41 MAKE_SCHEME_SCORE_ELEMENT_CALLBACK(Rest,brew_molecule)
42 SCM 
43 Rest::brew_molecule (SCM smob) 
44 {
45   Score_element* sc = unsmob_element (smob);
46   
47   bool ledger_b =false;
48
49   SCM balltype = sc->get_elt_property ("duration-log");
50   
51   if (balltype == gh_int2scm (0) || balltype == gh_int2scm (1))
52     {
53       Staff_symbol_referencer_interface si(sc);
54       ledger_b = abs(si.position_f ()  - (2* gh_scm2int (balltype) - 1))
55         > si.line_count (); 
56     }
57   
58   String style; 
59   SCM style_sym =sc->get_elt_property ("style");
60   if (gh_scm2int (balltype) >= 2 && gh_string_p (style_sym))
61     {
62       style = ly_scm2string (style_sym);
63     }
64
65   String idx =  ("rests-") + to_str (gh_scm2int (balltype))
66     + (ledger_b ? "o" : "") + style;
67
68   return sc-> lookup_l ()->afm_find (idx).create_scheme();
69 }
70