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