]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar.cc
release: 1.3.72
[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       return compound_barline (me, str, gh_scm2double (siz)).create_scheme ();
37     }
38   return SCM_EOL;
39 }
40
41
42 Molecule
43 Bar::compound_barline (Score_element*me, String str, Real h)
44 {
45   Real kern = gh_scm2double (me->get_elt_property ("kern"));
46   Real thinkern = gh_scm2double (me->get_elt_property ("thin-kern"));
47   Real hair = gh_scm2double (me->get_elt_property ("hair-thickness"));
48   Real fatline = gh_scm2double (me->get_elt_property ("thick-thickness"));
49
50   Real staffline = me->paper_l ()->get_var ("stafflinethickness");
51
52   kern *= staffline;
53   thinkern *= staffline;
54   hair *= staffline;
55   fatline *= staffline;
56   
57   Molecule thin = simple_barline (me, hair, h);
58   Molecule thick = simple_barline (me, fatline, h);
59   Molecule colon = me->lookup_l ()->afm_find ("dots-repeatcolon");  
60
61   Molecule m;
62   
63   if (str == "")
64     {
65       return me->lookup_l ()->blank (Box (Interval(0, 0), Interval (-h/2, h/2)));
66     }
67   if (str == "scorepostbreak")
68     {
69       return simple_barline (me, me->paper_l ()->get_var ("barthick_score"), h);
70     }
71   else if (str == "|")
72     {
73       return thin;
74     }
75   else if (str == "|.")
76     {
77       m.add_at_edge (X_AXIS, LEFT, thick, 0);      
78       m.add_at_edge (X_AXIS, LEFT, thin, kern);
79     }
80   else if (str == ".|")
81     {
82       m.add_at_edge (X_AXIS, RIGHT, thick, 0);
83       m.add_at_edge (X_AXIS, RIGHT, thin, kern);
84     }
85   else if (str == ":|")
86     {
87       m.add_at_edge (X_AXIS, LEFT, thick, 0);
88       m.add_at_edge (X_AXIS, LEFT, thin, kern);
89       m.add_at_edge (X_AXIS, LEFT, colon, kern);      
90     }
91   else if (str == "|:")
92     {
93       m.add_at_edge (X_AXIS, RIGHT, thick, 0);
94       m.add_at_edge (X_AXIS, RIGHT, thin, kern);
95       m.add_at_edge (X_AXIS, RIGHT, colon, kern);      
96     }
97   else if (str == ":|:")
98     {
99       m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
100       m.add_at_edge (X_AXIS, LEFT, colon, kern);      
101       m.add_at_edge (X_AXIS, RIGHT, thick, kern);
102       m.add_at_edge (X_AXIS, RIGHT, colon, kern);      
103     }
104   else if (str == ".|.")
105     {
106       m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
107       m.add_at_edge (X_AXIS, RIGHT, thick, kern);      
108     }
109   else if (str == "||")
110     {
111       m.add_at_edge (X_AXIS, RIGHT, thin, 0);
112       m.add_at_edge (X_AXIS, RIGHT, thin, thinkern);      
113     }
114
115   return m;
116 }
117
118
119 Molecule
120 Bar::simple_barline (Score_element*me,Real w, Real h) 
121 {
122   return me->lookup_l ()->filledbox (Box (Interval(0,w), Interval(-h/2, h/2)));
123 }
124
125 MAKE_SCHEME_CALLBACK(Bar,before_line_breaking );
126
127 SCM
128 Bar::before_line_breaking  (SCM smob)
129 {
130   Score_element*me=unsmob_element (smob);
131   Item * item = dynamic_cast<Item*> (me);
132   
133   SCM g = me->get_elt_property ("glyph");
134   SCM orig = g;
135   Direction bsd = item->break_status_dir ();
136   if (gh_string_p (g))
137     {
138       if (bsd)
139         {
140           SCM breakdir = gh_int2scm (bsd);
141           g = scm_eval (gh_list (ly_symbol2scm ("break-barline"),
142                                  g,
143                                  breakdir,
144                                  SCM_UNDEFINED));
145         }
146     }
147   else
148     {
149       g = SCM_EOL;
150     }
151   
152   if (!gh_string_p (g))
153     {
154       me->set_elt_property ("molecule-callback", SCM_BOOL_T);
155       me->set_extent_callback (0, X_AXIS);
156       // leave y_extent for spanbar? 
157     }
158   else if (! gh_equal_p  (g, orig))
159     me->set_elt_property ("glyph", g);
160
161
162   return SCM_UNSPECIFIED;
163 }
164   
165 void
166 Bar::set_interface (Score_element*me)
167 {
168   me->set_elt_property ("interfaces",
169                         gh_cons (ly_symbol2scm ("bar-interface"), me->get_elt_property ("interfaces")));
170 }
171
172 bool
173 Bar::has_interface (Score_element*m)
174 {
175   return m && m->has_interface (ly_symbol2scm ("bar-interface"));
176 }
177
178
179 MAKE_SCHEME_CALLBACK(Bar,get_staff_bar_size);
180 SCM
181 Bar::get_staff_bar_size (SCM smob) 
182 {
183   Score_element*me = unsmob_element (smob);
184   Real ss = Staff_symbol_referencer::staff_space (me);
185   SCM size = me->get_elt_property ("bar-size");
186   if (gh_number_p (size))
187     return gh_double2scm (gh_scm2double(size)*ss);
188   else
189     {
190       return gh_double2scm ((Staff_symbol_referencer::line_count (me) -1) * ss);
191     }
192 }