]> git.donarmstrong.com Git - lilypond.git/blob - lily/breathing-sign.cc
trim duplicate headers.
[lilypond.git] / lily / breathing-sign.cc
1 /*
2   breathing_sign.cc -- implement Breathing_sign
3
4   (c) 1999--2006 Michael Krause
5
6   written for the GNU LilyPond music typesetter
7
8   TODO: --> see breathing-sign-engraver.cc
9
10   Extensions for ancient notation (c) 2003--2006 by Juergen Reuter
11 */
12
13 #include "breathing-sign.hh"
14
15 #include "staff-symbol-referencer.hh"
16 #include "directional-element-interface.hh"
17 #include "output-def.hh"
18 #include "lookup.hh"
19 #include "dimensions.hh"
20 #include "direction.hh"
21 #include "text-interface.hh"
22 #include "font-interface.hh"
23 #include "grob.hh"
24
25 /*
26   TODO: thickness should be a grob property (unit: linethickness)
27   rather than hardwired to (staff_space / 6).
28 */
29
30 /*
31   UGH : this is full of C&P code. Consolidate!  --hwn
32 */
33
34 /*
35   Gregorian chant divisio minima.  (Actually, this was the original
36   breathing sign by Michael. -- jr)
37 */
38 MAKE_SCHEME_CALLBACK (Breathing_sign, divisio_minima, 1);
39 SCM
40 Breathing_sign::divisio_minima (SCM smob)
41 {
42   Grob *me = unsmob_grob (smob);
43   Real staff_space = Staff_symbol_referencer::staff_space (me);
44   Real staff_size;
45
46   Real thickness = Staff_symbol_referencer::line_thickness (me);
47   thickness *= robust_scm2double (me->get_property ("thickness"), 1.0);
48   if (Staff_symbol_referencer::get_staff_symbol (me))
49     staff_size = (Staff_symbol_referencer::line_count (me) - 1) * staff_space;
50   else
51     staff_size = 0.0;
52
53   Real blotdiameter = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
54
55   /*
56    * Draw a small vertical line through the uppermost (or, depending
57    * on direction, lowermost) staff line.
58    */
59   Interval xdim (0, thickness);
60   Interval ydim (-0.5 * staff_space, +0.5 * staff_space);
61   Box b (xdim, ydim);
62   Stencil out = Lookup::round_filled_box (b, blotdiameter);
63   return out.smobbed_copy ();
64 }
65
66 /*
67   Gregorian chant divisio maior.
68 */
69 MAKE_SCHEME_CALLBACK (Breathing_sign, divisio_maior, 1);
70 SCM
71 Breathing_sign::divisio_maior (SCM smob)
72 {
73   Grob *me = unsmob_grob (smob);
74   Real staff_space = Staff_symbol_referencer::staff_space (me);
75   Real staff_size;
76   Real thickness = Staff_symbol_referencer::line_thickness (me);
77   thickness *= robust_scm2double (me->get_property ("thickness"), 1.0);
78
79   if (Staff_symbol_referencer::get_staff_symbol (me))
80     staff_size = (Staff_symbol_referencer::line_count (me) - 1) * staff_space;
81   else
82     staff_size = 0.0;
83
84   Real blotdiameter = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
85
86   /*
87    * Draw a vertical line that is vertically centered in the staff
88    * (just like a bar).  The height of this line should be a little
89    * more than half the size of the staff, such that the endings of
90    * the line are in the middle of a staff space.
91    */
92   int lines = Staff_symbol_referencer::line_count (me);
93   int height = lines / 2; // little more than half of staff size
94   if ((lines & 1) != (height & 1))
95     height++; // ensure endings are centered in staff space
96
97   Interval xdim (0, thickness);
98   Interval ydim (-0.5 * height, +0.5 * height);
99   Box b (xdim, ydim);
100   Stencil out = Lookup::round_filled_box (b, blotdiameter);
101   return out.smobbed_copy ();
102 }
103
104 /*
105   Gregorian chant divisio maxima.
106 */
107 MAKE_SCHEME_CALLBACK (Breathing_sign, divisio_maxima, 1);
108 SCM
109 Breathing_sign::divisio_maxima (SCM smob)
110 {
111   Grob *me = unsmob_grob (smob);
112   Real staff_space = Staff_symbol_referencer::staff_space (me);
113   Real staff_size;
114   Real thickness = Staff_symbol_referencer::line_thickness (me);
115   thickness *= robust_scm2double (me->get_property ("thickness"), 1.0);
116
117   if (Staff_symbol_referencer::get_staff_symbol (me))
118     staff_size = (Staff_symbol_referencer::line_count (me) - 1) * staff_space;
119   else
120     staff_size = 0.0;
121
122   Real blotdiameter = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
123
124   // like a "|" type bar
125   Interval xdim (0, thickness);
126   Interval ydim (-0.5 * staff_size, +0.5 * staff_size);
127   Box b (xdim, ydim);
128   Stencil out = Lookup::round_filled_box (b, blotdiameter);
129   return out.smobbed_copy ();
130 }
131
132 /*
133   Gregorian chant finalis.
134 */
135 MAKE_SCHEME_CALLBACK (Breathing_sign, finalis, 1);
136 SCM
137 Breathing_sign::finalis (SCM smob)
138 {
139   Grob *me = unsmob_grob (smob);
140   Real staff_space = Staff_symbol_referencer::staff_space (me);
141   Real staff_size;
142   Real thickness = Staff_symbol_referencer::line_thickness (me);
143   thickness *= robust_scm2double (me->get_property ("thickness"), 1.0);
144
145   if (Staff_symbol_referencer::get_staff_symbol (me))
146     staff_size = (Staff_symbol_referencer::line_count (me) - 1) * staff_space;
147   else
148     staff_size = 0.0;
149
150   Real blotdiameter = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
151
152   // like a "||" type bar
153   Interval xdim (0, thickness);
154   Interval ydim (-0.5 * staff_size, +0.5 * staff_size);
155   Box b (xdim, ydim);
156   Stencil line1 = Lookup::round_filled_box (b, blotdiameter);
157   Stencil line2 (line1);
158   line2.translate_axis (0.5 * staff_space, X_AXIS);
159   line1.add_stencil (line2);
160
161   return line1.smobbed_copy ();
162 }
163
164 MAKE_SCHEME_CALLBACK (Breathing_sign, offset_callback, 1);
165 SCM
166 Breathing_sign::offset_callback (SCM smob)
167 {
168   Grob *me = unsmob_grob (smob);
169
170   Direction d = get_grob_direction (me);
171   if (!d)
172     {
173       d = UP;
174       set_grob_direction (me, d);
175     }
176
177   Real inter = Staff_symbol_referencer::staff_space (me) / 2;
178   int sz = Staff_symbol_referencer::line_count (me) - 1;
179   return scm_from_double (inter * sz * d);
180 }
181
182 ADD_INTERFACE (Breathing_sign,
183                "A breathing sign.",
184                
185                "direction "
186
187                );