]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-line.cc
* lily/beam.cc (brew_molecule): rewrite debug output: split up scores.
[lilypond.git] / lily / bar-line.cc
1 /*
2   bar.cc -- implement Bar
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include <math.h>
10
11 #include "lookup.hh"
12 #include "paper-column.hh"
13 #include "main.hh"
14 #include "grob.hh"
15 #include "bar-line.hh"
16 #include "string.hh"
17 #include "molecule.hh"
18 #include "paper-def.hh"
19 #include "font-interface.hh"
20
21 #include "all-font-metrics.hh"
22 #include "item.hh"
23 #include "staff-symbol-referencer.hh"
24
25 MAKE_SCHEME_CALLBACK (Bar_line,brew_molecule,1);
26
27 SCM 
28 Bar_line::brew_molecule (SCM smob) 
29 {
30   Grob * me = unsmob_grob (smob);
31
32   SCM s = me->get_grob_property ("glyph");
33   SCM barsiz_proc = me->get_grob_property ("bar-size-procedure");
34   if (gh_string_p (s) && gh_procedure_p (barsiz_proc))
35     {
36       String str  =ly_scm2string (s);
37       SCM siz = gh_call1 (barsiz_proc, me->self_scm ());
38       Real sz =  gh_scm2double (siz);
39       if (sz < 0)
40         return SCM_EOL;
41       
42       return compound_barline (me, str, sz).smobbed_copy ();
43     }
44   return SCM_EOL;
45 }
46
47
48 Molecule
49 Bar_line::compound_barline (Grob*me, String str, Real h)
50 {
51   Real kern = gh_scm2double (me->get_grob_property ("kern"));
52   Real thinkern = gh_scm2double (me->get_grob_property ("thin-kern"));
53   Real hair = gh_scm2double (me->get_grob_property ("hair-thickness"));
54   Real fatline = gh_scm2double (me->get_grob_property ("thick-thickness"));
55
56   Real staffline = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness"));
57   Real staff_space = Staff_symbol_referencer::staff_space (me);
58
59   kern *= staffline;
60   thinkern *= staffline;
61   hair *= staffline;
62   fatline *= staffline;
63   
64   Molecule thin = simple_barline (me, hair, h);
65   Molecule thick = simple_barline (me, fatline, h);
66   Molecule colon;
67   Molecule dot = Font_interface::get_default_font (me)->find_by_name ("dots-dot");
68   Real dist = ( Staff_symbol_referencer::line_count (me) & 1 ? 1 :
69                 (staff_space<2 ? 2 : .5) ) * staff_space;
70   dot.translate_axis(dist/2,Y_AXIS);
71   colon.add_molecule(dot);
72   dot.translate_axis(-dist,Y_AXIS);
73   colon.add_molecule(dot);
74
75   Molecule m;
76   
77   if (str == "")
78     {
79       return Lookup::blank (Box (Interval (0, 0), Interval (-h/2, h/2)));
80     }
81   else if (str == "|")
82     {
83       return thin;
84     }
85   else if (str == "|." || (h == 0 && str == ":|"))
86     {
87       m.add_at_edge (X_AXIS, LEFT, thick, 0, 0);      
88       m.add_at_edge (X_AXIS, LEFT, thin, kern,0 );
89     }
90   else if (str == ".|" || (h == 0 && str == "|:"))
91     {
92       m.add_at_edge (X_AXIS, RIGHT, thick, 0, 0);
93       m.add_at_edge (X_AXIS, RIGHT, thin, kern, 0);
94     }
95   else if (str == ":|")
96     {
97       m.add_at_edge (X_AXIS, LEFT, thick, 0, 0);
98       m.add_at_edge (X_AXIS, LEFT, thin, kern, 0);
99       m.add_at_edge (X_AXIS, LEFT, colon, kern, 0);      
100     }
101   else if (str == "|:")
102     {
103       m.add_at_edge (X_AXIS, RIGHT, thick, 0, 0);
104       m.add_at_edge (X_AXIS, RIGHT, thin, 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, LEFT, colon, kern, 0);
111       m.add_at_edge (X_AXIS, RIGHT, thick, kern, 0);
112       m.add_at_edge (X_AXIS, RIGHT, colon, kern, 0);      
113     }
114   else if (str == ".|.")
115     {
116       m.add_at_edge (X_AXIS, LEFT, thick, thinkern, 0);
117       m.add_at_edge (X_AXIS, RIGHT, thick, kern, 0);
118     }
119   else if (str == "||")
120     {
121       /*
122         should align to other side? this never appears
123         on the system-start?
124       */
125       m.add_at_edge (X_AXIS, RIGHT, thin, 0, 0);
126       m.add_at_edge (X_AXIS, RIGHT, thin, thinkern, 0);
127     }
128
129   return m;
130 }
131
132 Molecule
133 Bar_line::simple_barline (Grob *me,Real w, Real h) 
134 {
135   Real blot = me->get_paper ()->get_realvar (ly_symbol2scm ("blotdiameter"));
136   return Lookup::round_filled_box (Box (Interval (0,w), Interval (-h/2, h/2)), blot);
137 }
138
139 MAKE_SCHEME_CALLBACK (Bar_line,before_line_breaking ,1);
140
141 SCM
142 Bar_line::before_line_breaking (SCM smob)
143 {
144   Grob*me=unsmob_grob (smob);
145   Item * item = dynamic_cast<Item*> (me);
146   
147   SCM g = me->get_grob_property ("glyph");
148   SCM orig = g;
149   Direction bsd = item->break_status_dir ();
150   if (gh_string_p (g) && bsd)
151     {
152       SCM proc = me->get_grob_property ("break-glyph-function");
153       g = gh_call2 (proc, g, scm_int2num (bsd));
154     }
155   
156   if (!gh_string_p (g))
157     {
158       me->set_grob_property ("molecule-callback", SCM_EOL);
159       me->set_extent (SCM_EOL, X_AXIS);
160       // leave y_extent for spanbar? 
161     }
162
163   if (! gh_equal_p (g, orig))
164     me->set_grob_property ("glyph", g);
165
166   return SCM_UNSPECIFIED;
167 }
168   
169
170
171
172 MAKE_SCHEME_CALLBACK (Bar_line,get_staff_bar_size,1);
173 SCM
174 Bar_line::get_staff_bar_size (SCM smob) 
175 {
176   Grob*me = unsmob_grob (smob);
177   Real ss = Staff_symbol_referencer::staff_space (me);
178   SCM size = me->get_grob_property ("bar-size");
179   if (gh_number_p (size))
180     return gh_double2scm (gh_scm2double (size)*ss);
181   else if (Staff_symbol_referencer::get_staff_symbol (me))
182     {
183       /*
184         If there is no staff-symbol, we get -1 from the next
185         calculation. That's a nonsense value, which would collapse the
186         barline so we return 0.0 in the next alternative.
187       */
188       return gh_double2scm ((Staff_symbol_referencer::line_count (me) -1) * ss);
189     }
190   else
191     return scm_int2num (0);
192 }
193
194
195
196 ADD_INTERFACE (Bar_line, "bar-line-interface",
197   "Bar line.\n"
198 "\n"
199 "Print a special bar symbol. It replaces the \n"
200 "regular bar symbol with a special\n"
201 "symbol.  The argument @var{bartype} is a string which specifies the\n"
202 "kind of bar to print.  Options are @code{:|},\n"
203 "@code{|:}, @code{:|:},\n"
204 "@code{||}, @code{|.},\n"
205 "@code{.|}, and @code{.|.}. \n"
206 "\n"
207 "These produce, respectively, a right repeat, a left repeat, a double\n"
208 "repeat, a double bar, a start bar, an end bar, and a thick double bar.\n"
209 "If @var{bartype} is set to @code{empty} then nothing is printed,\n"
210 "but a line break is allowed at that spot.\n",
211   "bar-size-procedure kern thin-kern hair-thickness thick-thickness glyph bar-size break-glyph-function");