]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest.cc
release: 1.3.110
[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 "font-interface.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_CALLBACK(Rest,after_line_breaking,1);
19 SCM
20 Rest::after_line_breaking (SCM smob)
21 {
22   Grob *me = unsmob_grob (smob);
23   int bt = gh_scm2int (me->get_grob_property ("duration-log"));
24   if (bt == 0)
25     {
26       me->translate_axis (Staff_symbol_referencer::staff_space (me) , Y_AXIS);
27     }
28
29   Grob * d = unsmob_grob (me->get_grob_property ("dot"));
30   if (d && bt > 4) // UGH.
31     {
32       d->set_grob_property ("staff-position",
33                            gh_int2scm ((bt == 7) ? 4 : 3));
34     }
35
36   return SCM_UNSPECIFIED;
37 }
38
39
40 MAKE_SCHEME_CALLBACK(Rest,brew_molecule,1);
41
42 SCM
43 Rest::brew_internal_molecule (SCM smob)
44 {
45   Grob* me = unsmob_grob (smob);
46   
47   bool ledger_b =false;
48
49   SCM balltype = me->get_grob_property ("duration-log");
50   
51   if (balltype == gh_int2scm (0) || balltype == gh_int2scm (1))
52     {
53       int sz = Staff_symbol_referencer::line_count (me);
54       Real dif = abs(Staff_symbol_referencer::position_f (me)  - (2* gh_scm2int (balltype) - 1)); 
55       ledger_b = dif > sz;
56     }
57   
58   String style; 
59   SCM style_sym =me->get_grob_property ("style");
60   if (gh_scm2int (balltype) >= 2 && gh_symbol_p (style_sym))
61     {
62       style = ly_scm2string (scm_symbol_to_string (style_sym));
63     }
64
65   String idx =  ("rests-") + to_str (gh_scm2int (balltype))
66     + (ledger_b ? "o" : "") + style;
67
68   return Font_interface::get_default_font (me)->find_by_name (idx).smobbed_copy();
69 }
70
71 SCM 
72 Rest::brew_molecule (SCM smob) 
73 {
74   return brew_internal_molecule (smob);
75 }
76 MAKE_SCHEME_CALLBACK(Rest,extent_callback,2);
77 /*
78   We need the callback. The real molecule has ledgers depending on
79   Y-position. The Y-position is known only after line breaking.  */
80 SCM
81 Rest::extent_callback (SCM smob, SCM ax)
82 {
83   Axis a = (Axis) gh_scm2int (ax);
84   SCM m = brew_internal_molecule (smob);
85   return ly_interval2scm (unsmob_molecule (m)->extent (a));
86 }
87
88 bool
89 Rest::has_interface (Grob*m)
90 {
91   return m && m->has_interface (ly_symbol2scm ("rest-interface"));
92 }