]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest.cc
9cdd9078c71148974e9852771f5105dd42209192
[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--2002 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   int lc = Staff_symbol_referencer::line_count (me);
25   Real ss = Staff_symbol_referencer::staff_space (me);
26   if(lc % 2)
27     {
28       if (bt == 0 && lc > 1)
29         {
30           me->translate_axis (ss , Y_AXIS);
31         }
32     }
33   else
34     {
35       me->translate_axis (ss/2 , Y_AXIS);
36     }
37
38   Grob * d = unsmob_grob (me->get_grob_property ("dot"));
39   if (d && bt > 4) // UGH.
40     {
41       d->set_grob_property ("staff-position",
42                             gh_int2scm ((bt == 7) ? 4 : 3));
43     }
44
45   return SCM_UNSPECIFIED;
46 }
47
48 /*
49   make this function easily usable in C++
50  */
51
52 String
53 Rest::glyph_name (Grob * me, int balltype, String style)
54 {
55   bool ledger_b =false;
56
57   if (balltype == 0 || balltype == 1)
58     {
59       Real rad = Staff_symbol_referencer::staff_radius (me) * 2.0;
60       Real pos = Staff_symbol_referencer::get_position (me);
61
62       /*
63         Figure out when the rest is far enough outside the staff. This
64         could bemore generic, but hey, we understand this even after
65         dinner.
66         
67        */
68       ledger_b = ledger_b || (balltype == 0 && (pos >= rad +2   || pos < -rad ));
69       ledger_b = ledger_b || (balltype == 1 &&
70                               (pos  <= -rad -2 || pos > rad));
71     }
72
73   return ("rests-") + to_string (balltype)
74     + (ledger_b ? "o" : "") + style;
75 }
76
77
78
79
80 MAKE_SCHEME_CALLBACK (Rest,brew_molecule,1);
81
82 SCM
83 Rest::brew_internal_molecule (SCM smob)
84 {
85   Grob* me = unsmob_grob (smob);
86
87   SCM balltype_scm = me->get_grob_property ("duration-log");
88   if (!gh_number_p (balltype_scm))
89     return Molecule ().smobbed_copy ();
90
91   int balltype = gh_scm2int (balltype_scm);
92   
93   String style; 
94   SCM style_sym =me->get_grob_property ("style");
95   if (gh_symbol_p (style_sym))
96     {
97       style = ly_scm2string (scm_symbol_to_string (style_sym));
98     }
99
100   for(;;) {
101     String idx = glyph_name (me, balltype, style);
102     Molecule res = Font_interface::get_default_font (me)->find_by_name (idx);
103     if(res.empty_b() && style!="")
104       style="";
105     else
106       return res.smobbed_copy();
107   }
108 }
109
110 SCM 
111 Rest::brew_molecule (SCM smob) 
112 {
113   return brew_internal_molecule (smob);
114 }
115 MAKE_SCHEME_CALLBACK (Rest,extent_callback,2);
116 /*
117   We need the callback. The real molecule has ledgers depending on
118   Y-position. The Y-position is known only after line breaking.  */
119 SCM
120 Rest::extent_callback (SCM smob, SCM ax)
121 {
122   Axis a = (Axis) gh_scm2int (ax);
123   SCM m = brew_internal_molecule (smob);
124   return ly_interval2scm (unsmob_molecule (m)->extent (a));
125 }
126
127
128
129 ADD_INTERFACE (Rest,"rest-interface",
130   "a rest",
131   "style minimum-beam-collision-distance");
132