]> git.donarmstrong.com Git - lilypond.git/blob - lily/system-start-delimiter.cc
release: 1.3.100
[lilypond.git] / lily / system-start-delimiter.cc
1 /*   
2   system-start-delimiter.cc --  implement System_start_delimiter
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9 #include <math.h>
10
11 #include "axis-group-interface.hh"
12 #include "system-start-delimiter.hh"
13 #include "paper-def.hh"
14 #include "molecule.hh"
15 #include "font-interface.hh"
16 #include "all-font-metrics.hh"
17 #include "score-element.hh"
18 #include "lookup.hh"
19
20 Molecule
21 System_start_delimiter::staff_bracket (Score_element*me,Real height)  
22 {
23   Paper_def* p= me->paper_l ();
24   SCM scmss = p->get_scmvar ("staffspace");
25   Real ss = gh_scm2double (scmss);
26   Real arc_height = gh_scm2double (me->get_elt_property("arch-height")) * ss ;
27   
28   SCM at = gh_list (ly_symbol2scm ("bracket"),
29                     scm_product (me->get_elt_property ("arch-angle"), scmss),
30                     scm_product (me->get_elt_property ("arch-width"), scmss),
31                     gh_double2scm (arc_height),
32                     scm_product (me->get_elt_property ("bracket-width"),scmss),
33                     gh_double2scm (height),
34                     scm_product (me->get_elt_property ("arch-thick"),scmss),
35                     scm_product (me->get_elt_property ("bracket-thick"),scmss),
36                     SCM_UNDEFINED);
37
38   Real h = height + 2 * arc_height;
39   Box b (Interval (0, 1.5 * ss), Interval (-h/2, h/2));
40   Molecule mol (b, at);
41   mol.align_to (X_AXIS, CENTER);
42   return mol;
43 }
44
45 void
46 System_start_delimiter::set_interface (Score_element*me)
47 {
48   me->set_interface (ly_symbol2scm ("system-start-delimiter-interface"));
49 }
50
51 bool
52 System_start_delimiter::has_interface (Score_element*me)
53 {
54   return  me->has_interface (ly_symbol2scm ("system-start-delimiter-interface"));
55 }
56
57 Molecule
58 System_start_delimiter::simple_bar (Score_element*me,Real h) 
59 {
60   Real w = me->paper_l ()->get_var ("stafflinethickness") *
61     gh_scm2double (me->get_elt_property ("thickness"));
62   return Lookup::filledbox (Box (Interval(0,w), Interval(-h/2, h/2)));
63 }
64
65 MAKE_SCHEME_CALLBACK(System_start_delimiter,after_line_breaking,1);
66
67 SCM
68 System_start_delimiter::after_line_breaking (SCM smob)
69 {
70   try_collapse (unsmob_element (smob));
71   return SCM_UNSPECIFIED;
72 }
73
74 void
75 System_start_delimiter::try_collapse (Score_element*me)
76 {
77   SCM   gl = me->get_elt_property ("glyph");
78   
79   if (scm_ilength (me->get_elt_property ("elements")) <=  1 && gl == ly_symbol2scm ("bar-line"))
80     {
81       me->suicide ();
82     }
83   
84 }
85
86
87 MAKE_SCHEME_CALLBACK(System_start_delimiter,brew_molecule,1);
88
89 SCM
90 System_start_delimiter::brew_molecule (SCM smob)
91 {
92   Score_element * me = unsmob_element (smob);
93   Interval ext = ly_scm2interval (Axis_group_interface::group_extent_callback (me->self_scm(), gh_int2scm (Y_AXIS)));
94   Real l = ext.length (); 
95   Molecule m;
96
97   SCM s = me->get_elt_property ("collapse-height");
98   if (gh_number_p (s) && l < gh_scm2double (s))
99     {
100       me->suicide();
101       return SCM_EOL;
102     }
103
104   s = me->get_elt_property ("glyph");
105   if (!gh_symbol_p(s))
106     return SCM_EOL;
107   
108   if (s == ly_symbol2scm ("bracket"))
109     m = staff_bracket (me,l);
110   else if (s == ly_symbol2scm ("brace"))
111     m =  staff_brace (me,l);
112   else if (s == ly_symbol2scm ("bar-line"))
113     m = simple_bar (me,l);
114   
115   
116   m.translate_axis (ext.center (), Y_AXIS);
117   return m.create_scheme ();
118 }
119
120 /*
121   Ugh. Suck me plenty.
122  */
123 Molecule
124 System_start_delimiter::staff_brace (Score_element*me,Real y)  
125 {
126   int staff_size  = 20;         // URG.
127
128   // URG
129   Real step  = 1.0;
130   int minht  = 2 * staff_size;
131   int maxht = 7 *  minht;
132   int idx = int (((maxht - step) <? y - minht) / step);
133   idx = idx >? 0;
134
135   Font_metric *fm = Font_interface::get_default_font (me);
136   
137   SCM at =gh_list (ly_symbol2scm ("char"), gh_int2scm (idx), SCM_UNDEFINED);
138   at = fontify_atom (fm, at);
139   
140   Box b (Interval (0,0), Interval (-y/2, y/2));
141
142   return Molecule(b, at);
143 }
144