]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-spanner.cc
release: 1.3.40
[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 "note-column.hh"
15 #include "paper-column.hh"
16 #include "bar.hh"
17 #include "paper-def.hh"
18 #include "volta-spanner.hh"
19 #include "stem.hh"
20 #include "dimension-cache.hh"
21 #include "group-interface.hh"
22 #include "side-position-interface.hh"
23 #include "directional-element-interface.hh"
24
25 Volta_spanner::Volta_spanner ()
26 {
27   set_elt_property ("bars", SCM_EOL);
28   side_position (this).set_axis (Y_AXIS);
29   directional_element (this).set (UP);
30 }
31
32
33 /*
34   this is too complicated. Yet another version of side-positioning,
35   badly implemented.  */
36 Molecule 
37 Volta_spanner::do_brew_molecule () const
38 {
39   Molecule  mol;
40
41   Link_array<Bar> bar_arr
42     = Group_interface__extract_elements (this, (Bar*)0, "bars");
43
44   if (!bar_arr.size ())
45     return mol;
46
47   bool no_vertical_start = false;
48   bool no_vertical_end = to_boolean (get_elt_property ("last-volta"));
49   Spanner *orig_span =  dynamic_cast<Spanner*> (original_l_);
50   if (orig_span && (orig_span->broken_into_l_arr_[0] != (Spanner*)this))
51     no_vertical_start = true;
52   if (orig_span && (orig_span->broken_into_l_arr_.top () != (Spanner*)this))
53     no_vertical_end = true;
54
55 #if 0
56   // FIXME
57   if (bar_arr.top ()->get_elt_property (type_str_.length_i () > 1)
58     no_vertical_end = false;
59 #endif
60
61   Real staff_space = paper_l ()->get_var ("interline");
62   Real half_space = staff_space / 2;
63
64   Real w = spanner_length () - get_broken_left_end_align () - half_space;
65   Real h = paper_l()->get_var ("volta_spanner_height");
66   Real t = paper_l ()->get_var ("volta_thick");
67
68   SCM at = (gh_list (ly_symbol2scm ("volta"),
69                      gh_double2scm (h),
70                      gh_double2scm (w),
71                      gh_double2scm (t),
72                      gh_int2scm (no_vertical_start),
73                      gh_int2scm (no_vertical_end),
74                      SCM_UNDEFINED));
75   //Box b (Interval (0, w), Interval (- h/2, h/2));
76   Box b (Interval (0, w), Interval (0, h));
77   Molecule volta (b, at);
78   mol.add_molecule (volta);
79   
80   Molecule num (lookup_l ()->text ("volta",
81                                    ly_scm2string (get_elt_property("text")),
82                                    paper_l ()));
83
84   mol.add_at_edge (X_AXIS, LEFT, num, - num.extent (X_AXIS).length ()
85                    - staff_space);
86   return mol;
87 }
88   
89 void
90 Volta_spanner::do_add_processing ()
91 {
92
93   Link_array<Bar> bar_arr
94     = Group_interface__extract_elements (this, (Bar*)0, "bars");
95
96   if (bar_arr.size ())
97     {
98       set_bound (LEFT, bar_arr[0]);
99       set_bound (RIGHT, bar_arr.top ());  
100     }
101 }
102
103 void
104 Volta_spanner::after_line_breaking ()
105 {
106   side_position (this).add_staff_support ();
107 }
108   
109 void
110 Volta_spanner::add_bar  (Bar* b)
111 {
112   Group_interface gi(this, "bars");
113   gi.add_element (b);
114
115   side_position (this).add_support (b);
116   add_dependency (b);
117 }
118
119 void
120 Volta_spanner::add_column (Note_column* c)
121 {
122   side_position (this).add_support (c);
123   add_dependency (c);
124 }