]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-spanner.cc
release: 1.3.46
[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
37   --
38
39   Should look for system_start_delim to find left edge of staff.
40 */
41 Molecule 
42 Volta_spanner::do_brew_molecule () const
43 {
44   Molecule  mol;
45
46   Link_array<Bar> bar_arr
47     = Group_interface__extract_elements (this, (Bar*)0, "bars");
48
49   if (!bar_arr.size ())
50     return mol;
51
52   bool no_vertical_start = false;
53   bool no_vertical_end = to_boolean (get_elt_property ("last-volta"));
54   Spanner *orig_span =  dynamic_cast<Spanner*> (original_l_);
55   if (orig_span && (orig_span->broken_into_l_arr_[0] != (Spanner*)this))
56     no_vertical_start = true;
57   if (orig_span && (orig_span->broken_into_l_arr_.top () != (Spanner*)this))
58     no_vertical_end = true;
59
60 #if 0
61   // FIXME
62   if (bar_arr.top ()->get_elt_property (type_str_.length_i () > 1)
63     no_vertical_end = false;
64 #endif
65
66   Real staff_space = paper_l ()->get_var ("interline");
67   Real half_space = staff_space / 2;
68
69   Real w = spanner_length () - get_broken_left_end_align () - half_space;
70   Real h = paper_l()->get_var ("volta_spanner_height");
71   Real t = paper_l ()->get_var ("volta_thick");
72
73   SCM at = (gh_list (ly_symbol2scm ("volta"),
74                      gh_double2scm (h),
75                      gh_double2scm (w),
76                      gh_double2scm (t),
77                      gh_int2scm (no_vertical_start),
78                      gh_int2scm (no_vertical_end),
79                      SCM_UNDEFINED));
80   //Box b (Interval (0, w), Interval (- h/2, h/2));
81   Box b (Interval (0, w), Interval (0, h));
82   Molecule volta (b, at);
83   mol.add_molecule (volta);
84   
85   Molecule num (lookup_l ()->text ("volta",
86                                    ly_scm2string (get_elt_property("text")),
87                                    paper_l ()));
88
89   mol.add_at_edge (X_AXIS, LEFT, num, - num.extent (X_AXIS).length ()
90                    - staff_space);
91   return mol;
92 }
93   
94 void
95 Volta_spanner::do_add_processing ()
96 {
97
98   Link_array<Bar> bar_arr
99     = Group_interface__extract_elements (this, (Bar*)0, "bars");
100
101   if (bar_arr.size ())
102     {
103       set_bound (LEFT, bar_arr[0]);
104       set_bound (RIGHT, bar_arr.top ());  
105     }
106 }
107
108 void
109 Volta_spanner::after_line_breaking ()
110 {
111   side_position (this).add_staff_support ();
112 }
113   
114 void
115 Volta_spanner::add_bar  (Bar* b)
116 {
117   Group_interface gi(this, "bars");
118   gi.add_element (b);
119
120   side_position (this).add_support (b);
121   add_dependency (b);
122 }
123
124 void
125 Volta_spanner::add_column (Note_column* c)
126 {
127   side_position (this).add_support (c);
128   add_dependency (c);
129 }