]> git.donarmstrong.com Git - lilypond.git/blob - lily/breathing-sign.cc
7c605c4b1950c0012c3026a025d22b27d386b0e2
[lilypond.git] / lily / breathing-sign.cc
1 /*
2   breathing_sign.cc -- implement Breathing_sign
3
4   (c) 1999--2007 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--2007 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
45   Real thickness = Staff_symbol_referencer::line_thickness (me);
46   thickness *= robust_scm2double (me->get_property ("thickness"), 1.0);
47
48   Real blotdiameter = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
49
50   /*
51    * Draw a small vertical line through the uppermost (or, depending
52    * on direction, lowermost) staff line.
53    */
54   Interval xdim (0, thickness);
55   Interval ydim (-0.5 * staff_space, +0.5 * staff_space);
56   Box b (xdim, ydim);
57   Stencil out = Lookup::round_filled_box (b, blotdiameter);
58   return out.smobbed_copy ();
59 }
60
61 /*
62   Gregorian chant divisio maior.
63 */
64 MAKE_SCHEME_CALLBACK (Breathing_sign, divisio_maior, 1);
65 SCM
66 Breathing_sign::divisio_maior (SCM smob)
67 {
68   Grob *me = unsmob_grob (smob);
69   Real staff_space = Staff_symbol_referencer::staff_space (me);
70   Real staff_size;
71   Real thickness = Staff_symbol_referencer::line_thickness (me);
72   thickness *= robust_scm2double (me->get_property ("thickness"), 1.0);
73
74   if (Staff_symbol_referencer::get_staff_symbol (me))
75     staff_size = (Staff_symbol_referencer::line_count (me) - 1) * staff_space;
76   else
77     staff_size = 0.0;
78
79   Real blotdiameter = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
80
81   /*
82    * Draw a vertical line that is vertically centered in the staff
83    * (just like a bar).  The height of this line should be a little
84    * more than half the size of the staff, such that the endings of
85    * the line are in the middle of a staff space.
86    */
87   int lines = Staff_symbol_referencer::line_count (me);
88   int height = lines / 2; // little more than half of staff size
89   if ((lines & 1) != (height & 1))
90     height++; // ensure endings are centered in staff space
91
92   Interval xdim (0, thickness);
93   Interval ydim (-0.5 * height, +0.5 * height);
94   Box b (xdim, ydim);
95   Stencil out = Lookup::round_filled_box (b, blotdiameter);
96   return out.smobbed_copy ();
97 }
98
99 /*
100   Gregorian chant divisio maxima.
101 */
102 MAKE_SCHEME_CALLBACK (Breathing_sign, divisio_maxima, 1);
103 SCM
104 Breathing_sign::divisio_maxima (SCM smob)
105 {
106   Grob *me = unsmob_grob (smob);
107   Real staff_space = Staff_symbol_referencer::staff_space (me);
108   Real staff_size;
109   Real thickness = Staff_symbol_referencer::line_thickness (me);
110   thickness *= robust_scm2double (me->get_property ("thickness"), 1.0);
111
112   if (Staff_symbol_referencer::get_staff_symbol (me))
113     staff_size = (Staff_symbol_referencer::line_count (me) - 1) * staff_space;
114   else
115     staff_size = 0.0;
116
117   Real blotdiameter = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
118
119   // like a "|" type bar
120   Interval xdim (0, thickness);
121   Interval ydim (-0.5 * staff_size, +0.5 * staff_size);
122   Box b (xdim, ydim);
123   Stencil out = Lookup::round_filled_box (b, blotdiameter);
124   return out.smobbed_copy ();
125 }
126
127 /*
128   Gregorian chant finalis.
129 */
130 MAKE_SCHEME_CALLBACK (Breathing_sign, finalis, 1);
131 SCM
132 Breathing_sign::finalis (SCM smob)
133 {
134   Grob *me = unsmob_grob (smob);
135   Real staff_space = Staff_symbol_referencer::staff_space (me);
136   Real staff_size;
137   Real thickness = Staff_symbol_referencer::line_thickness (me);
138   thickness *= robust_scm2double (me->get_property ("thickness"), 1.0);
139
140   if (Staff_symbol_referencer::get_staff_symbol (me))
141     staff_size = (Staff_symbol_referencer::line_count (me) - 1) * staff_space;
142   else
143     staff_size = 0.0;
144
145   Real blotdiameter = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
146
147   // like a "||" type bar
148   Interval xdim (0, thickness);
149   Interval ydim (-0.5 * staff_size, +0.5 * staff_size);
150   Box b (xdim, ydim);
151   Stencil line1 = Lookup::round_filled_box (b, blotdiameter);
152   Stencil line2 (line1);
153   line2.translate_axis (0.5 * staff_space, X_AXIS);
154   line1.add_stencil (line2);
155
156   return line1.smobbed_copy ();
157 }
158
159 MAKE_SCHEME_CALLBACK (Breathing_sign, offset_callback, 1);
160 SCM
161 Breathing_sign::offset_callback (SCM smob)
162 {
163   Grob *me = unsmob_grob (smob);
164
165   Direction d = get_grob_direction (me);
166   if (!d)
167     {
168       d = UP;
169       set_grob_direction (me, d);
170     }
171
172   Real inter = Staff_symbol_referencer::staff_space (me) / 2;
173   int sz = Staff_symbol_referencer::line_count (me) - 1;
174   return scm_from_double (inter * sz * d);
175 }
176
177 ADD_INTERFACE (Breathing_sign,
178                "A breathing sign.",
179                
180                /* properties */
181                "direction "
182                );