]> git.donarmstrong.com Git - lilypond.git/blob - lily/breathing-sign.cc
Clean up g++ 4.6.1 compiler warnings (-Wunused-but-set-variable).
[lilypond.git] / lily / breathing-sign.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1999--2011 Michael Krause
5   Extensions for ancient notation (c) 2003--2011 by Juergen Reuter
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "breathing-sign.hh"
22
23 #include "dimensions.hh"
24 #include "direction.hh"
25 #include "directional-element-interface.hh"
26 #include "font-interface.hh"
27 #include "grob.hh"
28 #include "lookup.hh"
29 #include "output-def.hh"
30 #include "staff-symbol.hh"
31 #include "staff-symbol-referencer.hh"
32 #include "text-interface.hh"
33
34 /*
35   UGH : this is full of C&P code. Consolidate!  --hwn
36 */
37
38 /*
39   Gregorian chant divisio minima.  (Actually, this was the original
40   breathing sign by Michael. -- jr)
41 */
42 MAKE_SCHEME_CALLBACK (Breathing_sign, divisio_minima, 1);
43 SCM
44 Breathing_sign::divisio_minima (SCM smob)
45 {
46   Grob *me = unsmob_grob (smob);
47   Real staff_space = Staff_symbol_referencer::staff_space (me);
48
49   Real thickness = Staff_symbol_referencer::line_thickness (me);
50   thickness *= robust_scm2double (me->get_property ("thickness"), 1.0);
51
52   Real blotdiameter = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
53
54   /*
55    * Draw a small vertical line through the uppermost (or, depending
56    * on direction, lowermost) staff line.
57    */
58   Interval xdim (0, thickness);
59   Interval ydim (-0.5 * staff_space, +0.5 * staff_space);
60   Box b (xdim, ydim);
61   Stencil out = Lookup::round_filled_box (b, blotdiameter);
62   return out.smobbed_copy ();
63 }
64
65 /*
66   Gregorian chant divisio maior.
67 */
68 MAKE_SCHEME_CALLBACK (Breathing_sign, divisio_maior, 1);
69 SCM
70 Breathing_sign::divisio_maior (SCM smob)
71 {
72   Grob *me = unsmob_grob (smob);
73   Real thickness = Staff_symbol_referencer::line_thickness (me);
74   thickness *= robust_scm2double (me->get_property ("thickness"), 1.0);
75
76   Real blotdiameter = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
77
78   /*
79    * Draw a vertical line that is vertically centered in the staff
80    * (just like a bar).  The height of this line should be a little
81    * more than half the size of the staff, such that the endings of
82    * the line are in the middle of a staff space.
83    */
84   int lines = Staff_symbol_referencer::line_count (me);
85   int height = lines / 2; // little more than half of staff size
86   if ((lines & 1) != (height & 1))
87     height++; // ensure endings are centered in staff space
88
89   Interval xdim (0, thickness);
90   Interval ydim (-0.5 * height, +0.5 * height);
91   Box b (xdim, ydim);
92   Stencil out = Lookup::round_filled_box (b, blotdiameter);
93   return out.smobbed_copy ();
94 }
95
96 /*
97   Gregorian chant divisio maxima.
98 */
99 MAKE_SCHEME_CALLBACK (Breathing_sign, divisio_maxima, 1);
100 SCM
101 Breathing_sign::divisio_maxima (SCM smob)
102 {
103   Grob *me = unsmob_grob (smob);
104   Real staff_space = Staff_symbol_referencer::staff_space (me);
105   Real staff_size;
106   Real thickness = Staff_symbol_referencer::line_thickness (me);
107   thickness *= robust_scm2double (me->get_property ("thickness"), 1.0);
108
109   if (Staff_symbol_referencer::get_staff_symbol (me))
110     staff_size = (Staff_symbol_referencer::line_count (me) - 1) * staff_space;
111   else
112     staff_size = 0.0;
113
114   Real blotdiameter = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
115
116   // like a "|" type bar
117   Interval xdim (0, thickness);
118   Interval ydim (-0.5 * staff_size, +0.5 * staff_size);
119   Box b (xdim, ydim);
120   Stencil out = Lookup::round_filled_box (b, blotdiameter);
121   return out.smobbed_copy ();
122 }
123
124 /*
125   Gregorian chant finalis.
126 */
127 MAKE_SCHEME_CALLBACK (Breathing_sign, finalis, 1);
128 SCM
129 Breathing_sign::finalis (SCM smob)
130 {
131   Grob *me = unsmob_grob (smob);
132   Real staff_space = Staff_symbol_referencer::staff_space (me);
133   Real staff_size;
134   Real thickness = Staff_symbol_referencer::line_thickness (me);
135   thickness *= robust_scm2double (me->get_property ("thickness"), 1.0);
136
137   if (Staff_symbol_referencer::get_staff_symbol (me))
138     staff_size = (Staff_symbol_referencer::line_count (me) - 1) * staff_space;
139   else
140     staff_size = 0.0;
141
142   Real blotdiameter = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
143
144   // like a "||" type bar
145   Interval xdim (0, thickness);
146   Interval ydim (-0.5 * staff_size, +0.5 * staff_size);
147   Box b (xdim, ydim);
148   Stencil line1 = Lookup::round_filled_box (b, blotdiameter);
149   Stencil line2 (line1);
150   line2.translate_axis (0.5 * staff_space, X_AXIS);
151   line1.add_stencil (line2);
152
153   return line1.smobbed_copy ();
154 }
155
156 MAKE_SCHEME_CALLBACK (Breathing_sign, offset_callback, 1);
157 SCM
158 Breathing_sign::offset_callback (SCM smob)
159 {
160   Grob *me = unsmob_grob (smob);
161
162   Direction d = get_grob_direction (me);
163   if (!d)
164     {
165       d = UP;
166       set_grob_direction (me, d);
167     }
168
169   Grob *staff = Staff_symbol_referencer::get_staff_symbol (me);
170   if (staff)
171     {
172       Interval iv = Staff_symbol::line_span (staff);
173       Real inter = Staff_symbol::staff_space (me) / 2;
174       return scm_from_double (inter * iv[d]);
175     }
176
177   return scm_from_double (0.0);
178 }
179
180 ADD_INTERFACE (Breathing_sign,
181                "A breathing sign.",
182
183                /* properties */
184                "direction "
185               );