]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar.cc
release: 1.3.83
[lilypond.git] / lily / bar.cc
1 /*
2   bar.cc -- implement Bar
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include <math.h>
9
10 #include "main.hh"
11 #include "dimensions.hh"
12 #include "score-element.hh"
13 #include "bar.hh"
14 #include "string.hh"
15 #include "molecule.hh"
16 #include "paper-def.hh"
17 #include "lookup.hh"
18 #include "debug.hh"
19 #include "all-font-metrics.hh"
20 #include "item.hh"
21 #include "staff-symbol-referencer.hh"
22
23 MAKE_SCHEME_CALLBACK(Bar,brew_molecule);
24
25 SCM 
26 Bar::brew_molecule (SCM smob) 
27 {
28   Score_element * me = unsmob_element (smob);
29
30   SCM s = me->get_elt_property ("glyph");
31   SCM barsiz_proc = me->get_elt_property ("barsize-procedure");
32   if (gh_string_p (s) && gh_procedure_p (barsiz_proc))
33     {
34       String str  =ly_scm2string (s);
35       SCM siz = gh_call1 (barsiz_proc, me->self_scm ());
36       Real sz =  gh_scm2double (siz);
37       if (sz < 0)
38         return SCM_EOL;
39       
40       return compound_barline (me, str, sz).create_scheme ();
41     }
42   return SCM_EOL;
43 }
44
45
46 Molecule
47 Bar::compound_barline (Score_element*me, String str, Real h)
48 {
49   Real kern = gh_scm2double (me->get_elt_property ("kern"));
50   Real thinkern = gh_scm2double (me->get_elt_property ("thin-kern"));
51   Real hair = gh_scm2double (me->get_elt_property ("hair-thickness"));
52   Real fatline = gh_scm2double (me->get_elt_property ("thick-thickness"));
53
54   Real staffline = me->paper_l ()->get_var ("stafflinethickness");
55
56   kern *= staffline;
57   thinkern *= staffline;
58   hair *= staffline;
59   fatline *= staffline;
60   
61   Molecule thin = simple_barline (me, hair, h);
62   Molecule thick = simple_barline (me, fatline, h);
63   Molecule colon = me->lookup_l ()->afm_find ("dots-repeatcolon");  
64
65   Molecule m;
66   
67   if (str == "")
68     {
69       return me->lookup_l ()->blank (Box (Interval(0, 0), Interval (-h/2, h/2)));
70     }
71   if (str == "scorepostbreak")
72     {
73       return simple_barline (me, me->paper_l ()->get_var ("barthick_score"), h);
74     }
75   else if (str == "|")
76     {
77       return thin;
78     }
79   else if (str == "|.")
80     {
81       m.add_at_edge (X_AXIS, LEFT, thick, 0);      
82       m.add_at_edge (X_AXIS, LEFT, thin, kern);
83     }
84   else if (str == ".|")
85     {
86       m.add_at_edge (X_AXIS, RIGHT, thick, 0);
87       m.add_at_edge (X_AXIS, RIGHT, thin, kern);
88     }
89   else if (str == ":|")
90     {
91       m.add_at_edge (X_AXIS, LEFT, thick, 0);
92       m.add_at_edge (X_AXIS, LEFT, thin, kern);
93       m.add_at_edge (X_AXIS, LEFT, colon, kern);      
94     }
95   else if (str == "|:")
96     {
97       m.add_at_edge (X_AXIS, RIGHT, thick, 0);
98       m.add_at_edge (X_AXIS, RIGHT, thin, kern);
99       m.add_at_edge (X_AXIS, RIGHT, colon, kern);      
100     }
101   else if (str == ":|:")
102     {
103       m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
104       m.add_at_edge (X_AXIS, LEFT, colon, kern);      
105       m.add_at_edge (X_AXIS, RIGHT, thick, kern);
106       m.add_at_edge (X_AXIS, RIGHT, colon, kern);      
107     }
108   else if (str == ".|.")
109     {
110       m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
111       m.add_at_edge (X_AXIS, RIGHT, thick, kern);      
112     }
113   else if (str == "||")
114     {
115       m.add_at_edge (X_AXIS, RIGHT, thin, 0);
116       m.add_at_edge (X_AXIS, RIGHT, thin, thinkern);      
117     }
118
119   return m;
120 }
121
122
123 Molecule
124 Bar::simple_barline (Score_element*me,Real w, Real h) 
125 {
126   return me->lookup_l ()->filledbox (Box (Interval(0,w), Interval(-h/2, h/2)));
127 }
128
129 MAKE_SCHEME_CALLBACK(Bar,before_line_breaking );
130
131 SCM
132 Bar::before_line_breaking  (SCM smob)
133 {
134   Score_element*me=unsmob_element (smob);
135   Item * item = dynamic_cast<Item*> (me);
136   
137   SCM g = me->get_elt_property ("glyph");
138   SCM orig = g;
139   Direction bsd = item->break_status_dir ();
140   if (gh_string_p (g))
141     {
142       if (bsd)
143         {
144           SCM breakdir = gh_int2scm (bsd);
145           g = scm_eval2 (gh_list (ly_symbol2scm ("break-barline"),
146                                  g,
147                                  breakdir,
148                                  SCM_UNDEFINED),
149                          SCM_EOL);
150         }
151     }
152   else
153     {
154       g = SCM_EOL;
155     }
156   
157   if (!gh_string_p (g))
158     {
159       me->set_elt_property ("molecule-callback", SCM_BOOL_T);
160       me->set_extent_callback (0, X_AXIS);
161
162       // leave y_extent for spanbar? 
163     }
164
165   if (! gh_equal_p  (g, orig))
166     me->set_elt_property ("glyph", g);
167
168
169   return SCM_UNSPECIFIED;
170 }
171   
172 void
173 Bar::set_interface (Score_element*me)
174 {
175   me->set_elt_property ("interfaces",
176                         gh_cons (ly_symbol2scm ("bar-interface"), me->get_elt_property ("interfaces")));
177 }
178
179 bool
180 Bar::has_interface (Score_element*m)
181 {
182   return m && m->has_interface (ly_symbol2scm ("bar-interface"));
183 }
184
185
186 MAKE_SCHEME_CALLBACK(Bar,get_staff_bar_size);
187 SCM
188 Bar::get_staff_bar_size (SCM smob) 
189 {
190   Score_element*me = unsmob_element (smob);
191   Real ss = Staff_symbol_referencer::staff_space (me);
192   SCM size = me->get_elt_property ("bar-size");
193   if (gh_number_p (size))
194     return gh_double2scm (gh_scm2double(size)*ss);
195   else
196     {
197       return gh_double2scm ((Staff_symbol_referencer::line_count (me) -1) * ss);
198     }
199 }