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