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