]> git.donarmstrong.com Git - lilypond.git/blob - lily/system-start-delimiter.cc
5be06b334ee7315995f45859eade2c84ffcaa918
[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 GLUE_SCORE_ELEMENT(System_start_delimiter,after_line_breaking);
59 SCM
60 System_start_delimiter::member_after_line_breaking ()
61 {
62   SCM   gl = get_elt_property ("glyph");
63   
64   if (scm_ilength (get_elt_pointer ("elements")) <=  1 && gl == ly_symbol2scm ("bar-line"))
65     {
66       suicide ();
67     }
68   return SCM_UNDEFINED;
69 }
70
71 MAKE_SCHEME_SCORE_ELEMENT_CALLBACK(System_start_delimiter,brew_molecule);
72
73 SCM
74 System_start_delimiter::brew_molecule (SCM smob)
75 {
76   Score_element * sc = unsmob_element (smob);
77
78   System_start_delimiter * ssd= dynamic_cast<System_start_delimiter*> (sc);
79   
80   Interval ext = Axis_group_interface::group_extent_callback (sc, Y_AXIS);
81   Real l = ext.length (); 
82   Molecule m;
83
84   SCM s = sc->get_elt_property ("collapse-height");
85   if (gh_number_p (s) && l < gh_scm2double (s))
86     {
87       sc->suicide();
88       return SCM_EOL;
89     }
90
91   s = sc->get_elt_property ("glyph");
92   if (!gh_symbol_p(s))
93     return SCM_EOL;
94   
95   if (s == ly_symbol2scm ("bracket"))
96     m = ssd->staff_bracket (l);
97   else if (s == ly_symbol2scm ("brace"))
98     m = ssd-> staff_brace (l);
99   else if (s == ly_symbol2scm ("bar-line"))
100     m = ssd->simple_bar (l);
101   
102   
103   m.translate_axis (ext.center (), Y_AXIS);
104   return m.create_scheme ();
105 }
106
107 /*
108   Ugh. Suck me plenty.
109  */
110 Molecule
111 System_start_delimiter::staff_brace (Real y)  const
112 {
113   Real staffht  = paper_l ()->get_var ("staffheight");
114   int staff_size  = int (rint (staffht ));
115
116   // URG
117   Real step  = 1.0;
118   int minht  = 2 * staff_size;
119   int maxht = 7 *  minht;
120   int idx = int (((maxht - step) <? y - minht) / step);
121   idx = idx >? 0;
122
123   SCM l = scm_assoc (ly_str02scm ("brace"),
124                      scm_eval (ly_symbol2scm ("cmr-alist")));
125   
126   String nm = "feta-braces";
127   if (l != SCM_BOOL_F)
128     nm = ly_scm2string (gh_cdr (l));
129   nm += to_str (staff_size);
130   SCM e =gh_list (ly_symbol2scm ("char"), gh_int2scm (idx), SCM_UNDEFINED);
131   SCM at = (e);
132
133   at = fontify_atom (find_font (nm), at);
134   
135   Box b (Interval (0,0), Interval (-y/2, y/2));
136
137   return Molecule(b, at);
138 }
139