]> git.donarmstrong.com Git - lilypond.git/blob - lily/system-start-delimiter.cc
release: 1.3.72
[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 "lookup.hh"
16 #include "all-font-metrics.hh"
17 #include "score-element.hh"
18
19 Molecule
20 System_start_delimiter::staff_bracket (Score_element*me,Real height)  
21 {
22   Paper_def* p= me->paper_l ();
23   SCM scmss = p->get_scmvar ("staffspace");
24   Real ss = gh_scm2double (scmss);
25   Real arc_height = gh_scm2double (me->get_elt_property("arch-height")) * ss ;
26   
27   SCM at = gh_list (ly_symbol2scm ("bracket"),
28                     scm_product (me->get_elt_property ("arch-angle"), scmss),
29                     scm_product (me->get_elt_property ("arch-width"), scmss),
30                     gh_double2scm (arc_height),
31                     scm_product (me->get_elt_property ("bracket-width"),scmss),
32                     gh_double2scm (height),
33                     scm_product (me->get_elt_property ("arch-thick"),scmss),
34                     scm_product (me->get_elt_property ("bracket-thick"),scmss),
35                     SCM_UNDEFINED);
36
37   Real h = height + 2 * arc_height;
38   Box b (Interval (0, 1.5 * ss), Interval (-h/2, h/2));
39   Molecule mol (b, at);
40   mol.align_to (X_AXIS, CENTER);
41   return mol;
42 }
43
44 void
45 System_start_delimiter::set_interface (Score_element*me)
46 {
47   me->set_extent_callback (0, Y_AXIS);
48   Pointer_group_interface (me).set_interface();
49   me->set_interface (ly_symbol2scm ("system-start-delimiter-interface"));
50 }
51
52 bool
53 System_start_delimiter::has_interface (Score_element*me)
54 {
55   return  me->has_interface (ly_symbol2scm ("system-start-delimiter-interface"));
56 }
57
58 Molecule
59 System_start_delimiter::simple_bar (Score_element*me,Real h) 
60 {
61   Real w = me->paper_l ()->get_var ("stafflinethickness") *
62     gh_scm2double (me->get_elt_property ("thickness"));
63   return me->lookup_l ()->filledbox (Box (Interval(0,w), Interval(-h/2, h/2)));
64 }
65
66 MAKE_SCHEME_CALLBACK(System_start_delimiter,after_line_breaking);
67
68 SCM
69 System_start_delimiter::after_line_breaking (SCM smob)
70 {
71   try_collapse (unsmob_element (smob));
72   return SCM_UNSPECIFIED;
73 }
74
75 void
76 System_start_delimiter::try_collapse (Score_element*me)
77 {
78   SCM   gl = me->get_elt_property ("glyph");
79   
80   if (scm_ilength (me->get_elt_property ("elements")) <=  1 && gl == ly_symbol2scm ("bar-line"))
81     {
82       me->suicide ();
83     }
84   
85 }
86
87
88 MAKE_SCHEME_CALLBACK(System_start_delimiter,brew_molecule);
89
90 SCM
91 System_start_delimiter::brew_molecule (SCM smob)
92 {
93   Score_element * me = unsmob_element (smob);
94   Interval ext = Axis_group_interface::group_extent_callback (me, Y_AXIS);
95   Real l = ext.length (); 
96   Molecule m;
97
98   SCM s = me->get_elt_property ("collapse-height");
99   if (gh_number_p (s) && l < gh_scm2double (s))
100     {
101       me->suicide();
102       return SCM_EOL;
103     }
104
105   s = me->get_elt_property ("glyph");
106   if (!gh_symbol_p(s))
107     return SCM_EOL;
108   
109   if (s == ly_symbol2scm ("bracket"))
110     m = staff_bracket (me,l);
111   else if (s == ly_symbol2scm ("brace"))
112     m =  staff_brace (me,l);
113   else if (s == ly_symbol2scm ("bar-line"))
114     m = simple_bar (me,l);
115   
116   
117   m.translate_axis (ext.center (), Y_AXIS);
118   return m.create_scheme ();
119 }
120
121 /*
122   Ugh. Suck me plenty.
123  */
124 Molecule
125 System_start_delimiter::staff_brace (Score_element*me,Real y)  
126 {
127   Real staffht  = me->paper_l ()->get_var ("staffheight");
128   int staff_size  = int (rint (staffht ));
129
130   // URG
131   Real step  = 1.0;
132   int minht  = 2 * staff_size;
133   int maxht = 7 *  minht;
134   int idx = int (((maxht - step) <? y - minht) / step);
135   idx = idx >? 0;
136
137   SCM l = scm_assoc (ly_str02scm ("brace"),
138                      scm_eval (ly_symbol2scm ("cmr-alist")));
139   
140   String nm = "feta-braces";
141   if (l != SCM_BOOL_F)
142     nm = ly_scm2string (gh_cdr (l));
143   nm += to_str (staff_size);
144   SCM e =gh_list (ly_symbol2scm ("char"), gh_int2scm (idx), SCM_UNDEFINED);
145   SCM at = (e);
146
147   at = fontify_atom (find_font (nm), at);
148   
149   Box b (Interval (0,0), Interval (-y/2, y/2));
150
151   return Molecule(b, at);
152 }
153