]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-line.cc
* lily/script-engraver.cc (make_script_from_event): don't trigger callback.
[lilypond.git] / lily / bar-line.cc
1 /*
2   bar-line.cc -- implement Bar_line
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "bar-line.hh"
10
11 #include "all-font-metrics.hh"
12 #include "font-interface.hh"
13 #include "lookup.hh"
14 #include "output-def.hh"
15 #include "paper-column.hh"
16 #include "staff-symbol-referencer.hh"
17
18 MAKE_SCHEME_CALLBACK (Bar_line, print, 1);
19 SCM
20 Bar_line::print (SCM smob)
21 {
22   Grob *me = unsmob_grob (smob);
23
24   SCM s = me->get_property ("glyph-name");
25   SCM barsize = me->get_property ("bar-size");
26   
27   if (scm_is_string (s) && scm_is_number (barsize))
28     {
29       String str = ly_scm2string (s);
30       Real sz = robust_scm2double (barsize, 0);
31       if (sz <= 0)
32         return SCM_EOL;
33
34       return compound_barline (me, str, sz, false).smobbed_copy ();
35     }
36   return SCM_EOL;
37 }
38
39 Stencil
40 Bar_line::compound_barline (Grob *me, String str, Real h,
41                             bool rounded)
42 {
43   Real kern = robust_scm2double (me->get_property ("kern"), 1);
44   Real thinkern = robust_scm2double (me->get_property ("thin-kern"), 1);
45   Real hair = robust_scm2double (me->get_property ("hair-thickness"), 1);
46   Real fatline = robust_scm2double (me->get_property ("thick-thickness"), 1);
47
48   Real staffline = me->get_layout ()->get_dimension (ly_symbol2scm ("linethickness"));
49   Real staff_space = Staff_symbol_referencer::staff_space (me);
50
51   kern *= staffline;
52   thinkern *= staffline;
53   hair *= staffline;
54   fatline *= staffline;
55
56   Stencil thin = simple_barline (me, hair, h, rounded);
57   Stencil thick = simple_barline (me, fatline, h, rounded);
58   Stencil dot = Font_interface::get_default_font (me)->find_by_name ("dots.dot");
59
60   int lines = Staff_symbol_referencer::line_count (me);
61   Real dist
62     = ((lines & 1 || lines == 0)
63        ? 1
64        : (staff_space < 2 ? 2 : .5)) * staff_space;
65   Stencil colon (dot);
66   colon.translate_axis (dist, Y_AXIS);
67   colon.add_stencil (dot);
68   colon.translate_axis (-dist / 2, Y_AXIS);
69
70   Stencil m;
71   if (str == "||:")
72     str = "|:";
73
74   if (str == "")
75     return Lookup::blank (Box (Interval (0, 0), Interval (-h / 2, h / 2)));
76   else if (str == "|")
77     return thin;
78   else if (str == "|." || (h == 0 && str == ":|"))
79     {
80       m.add_at_edge (X_AXIS, LEFT, thick, 0, 0);
81       m.add_at_edge (X_AXIS, LEFT, thin, kern, 0);
82     }
83   else if (str == ".|" || (h == 0 && str == "|:"))
84     {
85       m.add_at_edge (X_AXIS, RIGHT, thick, 0, 0);
86       m.add_at_edge (X_AXIS, RIGHT, thin, kern, 0);
87     }
88   else if (str == ":|")
89     {
90       m.add_at_edge (X_AXIS, LEFT, thick, 0, 0);
91       m.add_at_edge (X_AXIS, LEFT, thin, kern, 0);
92       m.add_at_edge (X_AXIS, LEFT, colon, kern, 0);
93     }
94   else if (str == "|:")
95     {
96       m.add_at_edge (X_AXIS, RIGHT, thick, 0, 0);
97       m.add_at_edge (X_AXIS, RIGHT, thin, kern, 0);
98       m.add_at_edge (X_AXIS, RIGHT, colon, kern, 0);
99     }
100   else if (str == ":|:")
101     {
102       m.add_at_edge (X_AXIS, LEFT, thick, thinkern, 0);
103       m.add_at_edge (X_AXIS, LEFT, colon, kern, 0);
104       m.add_at_edge (X_AXIS, RIGHT, thick, kern, 0);
105       m.add_at_edge (X_AXIS, RIGHT, colon, kern, 0);
106     }
107   else if (str == ".|.")
108     {
109       m.add_at_edge (X_AXIS, LEFT, thick, thinkern, 0);
110       m.add_at_edge (X_AXIS, RIGHT, thick, kern, 0);
111     }
112   else if (str == "||")
113     {
114       /*
115         should align to other side? this never appears
116         on the system-start?
117       */
118       m.add_at_edge (X_AXIS, RIGHT, thin, 0, 0);
119       m.add_at_edge (X_AXIS, RIGHT, thin, thinkern, 0);
120     }
121   else if (str == ":")
122     {
123       int c = (Staff_symbol_referencer::line_count (me));
124
125       for (int i = 0; i < c - 1; i++)
126         {
127           Real y = (- (c - 1.0) / 2 + 0.5 + i * staff_space);
128           Stencil d (dot);
129
130           d.translate_axis (y, Y_AXIS);
131           m.add_stencil (d);
132         }
133     }
134   return m;
135 }
136
137 Stencil
138 Bar_line::simple_barline (Grob *me,
139                           Real w,
140                           Real h,
141                           bool rounded)
142 {
143   Real blot
144     = rounded
145     ? me->get_layout ()->get_dimension (ly_symbol2scm ("blotdiameter"))
146     : 0.0;
147
148   return Lookup::round_filled_box (Box (Interval (0, w),
149                                         Interval (-h / 2, h / 2)), blot);
150 }
151
152 MAKE_SCHEME_CALLBACK (Bar_line, calc_bar_size, 1);
153 SCM
154 Bar_line::calc_bar_size (SCM smob)
155 {
156   Grob *me = unsmob_grob (smob);
157   Real ss = Staff_symbol_referencer::staff_space (me);
158
159   if (Staff_symbol_referencer::get_staff_symbol (me))
160     {
161       /*
162         If there is no staff-symbol, we get -1 from the next
163         calculation. That's a nonsense value, which would collapse the
164         barline so we return 0.0 in the next alternative.
165       */
166       Real ysize = (Staff_symbol_referencer::line_count (me) -1);
167       ysize = ysize * ss + Staff_symbol_referencer::line_thickness (me);
168       return scm_from_double (ysize);
169     }
170   return scm_from_int (0);
171 }
172
173
174 ADD_INTERFACE (Bar_line,
175                "bar-line-interface",
176
177                "Bar line.\n"
178                "\n"
179                "Print a special bar symbol. It replaces the \n"
180                "regular bar symbol with a special\n"
181                "symbol.  The argument @var{bartype} is a string which specifies the\n"
182                "kind of bar to print.  Options are @code{:|}, \n"
183                "@code{|:}, @code{:|:},\n"
184                "@code{||}, @code{|.},\n"
185                "@code{.|}, and @code{.|.}. \n"
186                "\n"
187                "These produce, respectively, a right repeat, a left repeat, a double\n"
188                "repeat, a double bar, a start bar, an end bar, and a thick double bar.\n"
189                "If @var{bartype} is set to @code{empty} then nothing is printed,\n"
190                "but a line break is allowed at that spot.\n",
191
192
193                /* properties */ 
194                "kern "
195                "thin-kern "
196                "hair-thickness "
197                "thick-thickness "
198                "glyph "
199                "bar-size "
200                );