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