]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar.cc
ea076435857e0096f56c8d37a1d758ac1c249185
[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 "dimension-cache.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
21 Bar::Bar (SCM s)
22   : Item (s)
23 {
24 }
25
26
27 Real
28 Bar::get_bar_size () const
29 {
30   // Never called!
31   return 0;
32 }
33
34
35 SCM 
36 Bar::scheme_molecule (SCM smob) 
37 {
38   Score_element * self = unsmob_element (smob);
39   Bar * fly = dynamic_cast<Bar*> (self);
40   SCM s = self->get_elt_property ("glyph");
41   if (gh_string_p (s))
42     {
43       String str  =ly_scm2string (s);
44       return fly->compound_barline (str, fly->get_bar_size ()).create_scheme ();
45     }
46   return SCM_EOL;
47 }
48
49 MAKE_SCHEME_SCORE_ELEMENT_NON_DEFAULT_CALLBACKS(Bar);
50
51 Molecule
52 Bar::compound_barline (String str, Real h) const
53 {
54   Real kern = gh_scm2double (get_elt_property ("kern"));
55   Real thinkern = gh_scm2double (get_elt_property ("thin-kern"));
56   Real hair = gh_scm2double (get_elt_property ("hair-thickness"));
57   Real fatline = gh_scm2double (get_elt_property ("thick-thickness"));
58
59   Real staffline = paper_l ()->get_var ("stafflinethickness");
60
61   kern *= staffline;
62   thinkern *= staffline;
63   hair *= staffline;
64   fatline *= staffline;
65   
66   Molecule thin = simple_barline (hair, h);
67   Molecule thick = simple_barline (fatline, h);
68   Molecule colon = lookup_l ()->afm_find ("dots-repeatcolon");  
69
70   Molecule m;
71   
72   if (str == "")
73     {
74       return lookup_l ()->blank (Box (Interval(0, 0), Interval (-h/2, h/2)));
75     }
76   if (str == "scorepostbreak")
77     {
78       return simple_barline (paper_l ()->get_var ("barthick_score"), h);
79     }
80   else if (str == "|")
81     {
82       return thin;
83     }
84   else if (str == "|.")
85     {
86       m.add_at_edge (X_AXIS, LEFT, thick, 0);      
87       m.add_at_edge (X_AXIS, LEFT, thin, kern);
88     }
89   else if (str == ".|")
90     {
91       m.add_at_edge (X_AXIS, RIGHT, thick, 0);
92       m.add_at_edge (X_AXIS, RIGHT, thin, kern);
93     }
94   else if (str == ":|")
95     {
96       m.add_at_edge (X_AXIS, LEFT, thick, 0);
97       m.add_at_edge (X_AXIS, LEFT, thin, kern);
98       m.add_at_edge (X_AXIS, LEFT, colon, kern);      
99     }
100   else if (str == "|:")
101     {
102       m.add_at_edge (X_AXIS, RIGHT, thick, 0);
103       m.add_at_edge (X_AXIS, RIGHT, thin, kern);
104       m.add_at_edge (X_AXIS, RIGHT, colon, kern);      
105     }
106   else if (str == ":|:")
107     {
108       m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
109       m.add_at_edge (X_AXIS, LEFT, colon, kern);      
110       m.add_at_edge (X_AXIS, RIGHT, thick, kern);
111       m.add_at_edge (X_AXIS, RIGHT, colon, kern);      
112     }
113   else if (str == ".|.")
114     {
115       m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
116       m.add_at_edge (X_AXIS, RIGHT, thick, kern);      
117     }
118   else if (str == "||")
119     {
120       m.add_at_edge (X_AXIS, RIGHT, thin, 0);
121       m.add_at_edge (X_AXIS, RIGHT, thin, thinkern);      
122     }
123
124   return m;
125 }
126
127
128 Molecule
129 Bar::simple_barline (Real w, Real h) const
130 {
131   return lookup_l ()->filledbox (Box (Interval(0,w), Interval(-h/2, h/2)));
132 }
133
134
135 void
136 Bar::before_line_breaking ()
137 {
138   SCM g = get_elt_property ("glyph");
139   SCM orig = g;
140   Direction bsd = break_status_dir ();
141   if (gh_string_p (g))
142     {
143       if (bsd)
144         {
145           SCM breakdir = gh_int2scm (bsd);
146           g = scm_eval (gh_list (ly_symbol2scm ("break-barline"),
147                                  g,
148                                  breakdir,
149                                  SCM_UNDEFINED));
150         }
151     }
152   else
153     {
154       g = SCM_UNDEFINED;
155     }
156   
157   if (!gh_string_p (g))
158     {
159       set_elt_property ("molecule-callback", SCM_BOOL_T);
160       set_extent_callback (0, X_AXIS);
161       // leave y_extent for spanbar? 
162     }
163   else if (! gh_equal_p  (g, orig))
164     set_elt_property ("glyph", g);
165 }
166   
167