]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-spanner.cc
b2b42ac4f5dc479c27231d6d5be6c6d0f64d085b
[lilypond.git] / lily / volta-spanner.cc
1 /*
2   volta-spanner.cc -- implement Volta_spanner
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9
10 #include "box.hh"
11 #include "debug.hh"
12 #include "lookup.hh"
13 #include "molecule.hh"
14 #include "paper-column.hh"
15 #include "paper-def.hh"
16 #include "volta-spanner.hh"
17 #include "group-interface.hh"
18 #include "side-position-interface.hh"
19 #include "directional-element-interface.hh"
20
21
22 void
23 Volta_spanner::set_interface (Score_element*me)
24 {
25   Side_position::set_axis (me, Y_AXIS);
26   Directional_element_interface::set (me, UP);
27 }
28
29
30 /*
31   this is too complicated. Yet another version of side-positioning,
32   badly implemented.
33
34   --
35
36   * Should look for system_start_delim to find left edge of staff.
37   
38   
39 */
40
41 MAKE_SCHEME_CALLBACK(Volta_spanner,brew_molecule,1);
42 SCM
43 Volta_spanner::brew_molecule (SCM smob) 
44 {
45   Score_element *me = unsmob_element (smob);
46   Link_array<Item> bar_arr
47     = Pointer_group_interface__extract_elements (me, (Item*)0, "bars");
48
49   if (!bar_arr.size ())
50     return SCM_EOL;
51
52   bool no_vertical_start = false;
53   bool no_vertical_end = to_boolean (me->get_elt_property ("last-volta"));
54   Spanner *orig_span =  dynamic_cast<Spanner*> (me->original_l_);
55   if (orig_span && (orig_span->broken_into_l_arr_[0] != (Spanner*)me))
56     no_vertical_start = true;
57   if (orig_span && (orig_span->broken_into_l_arr_.top () != (Spanner*)me))
58     no_vertical_end = true;
59
60 #if 0
61   // FIXME
62   if (bar_arr.top ()->me->get_elt_property (type_str_.length_i () > 1)
63     no_vertical_end = false;
64 #endif
65
66   Real staff_space = me->paper_l ()->get_var ("staffspace");
67   Real staff_thick = me->paper_l ()->get_var ("stafflinethickness");  
68   Real half_space = staff_space / 2;
69
70   /*
71     the volta spanner is attached to the bar-line, which is moved
72     to the right. We don't need to compensate for the left edge.
73    */
74   Real left = 0.0;
75   Real w = dynamic_cast<Spanner*>(me)->spanner_length () - left - half_space;
76   Real h = staff_space * gh_scm2double (me->get_elt_property ("height"));
77   Real t = staff_thick * gh_scm2double (me->get_elt_property ("thickness"));
78
79   /*
80     ugh: should build from line segments.
81    */
82   SCM at = (gh_list (ly_symbol2scm ("volta"),
83                      gh_double2scm (h),
84                      gh_double2scm (w),
85                      gh_double2scm (t),
86                      gh_int2scm (no_vertical_start),
87                      gh_int2scm (no_vertical_end),
88                      SCM_UNDEFINED));
89
90   Box b (Interval (0, w), Interval (0, h));
91   Molecule  mol (b, at);
92   Molecule num (me->lookup_l ()->text ("volta",
93                                        ly_scm2string (me->get_elt_property("text")),
94                                        me->paper_l ()));
95
96   mol.add_at_edge (X_AXIS, LEFT, num, - num.extent (X_AXIS).length ()
97                    - staff_space);
98   mol.translate_axis (left, X_AXIS);
99   return mol.create_scheme();
100 }
101
102
103 void
104 Volta_spanner::add_bar  (Score_element *me, Item* b)
105 {
106   Pointer_group_interface::add_element(me, "bars",b);
107   Side_position::add_support (me,b);
108   add_bound_item (dynamic_cast<Spanner*>(me), b); 
109 }
110
111 void
112 Volta_spanner::add_column (Score_element*me, Score_element* c)
113 {
114   Side_position::add_support (me,c);
115 }