]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-spanner.cc
f1e641b78230c07a70105bffbe24fd5d221719fc
[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--1999 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 "pointer.tcc"
22
23 Volta_spanner::Volta_spanner ()
24 {
25   last_b_ = false;
26   dim_cache_ [Y_AXIS]->set_callback (dim_callback);
27 }
28
29 Molecule*
30 Volta_spanner::do_brew_molecule_p () const
31 {
32   Molecule* mol_p = new Molecule;
33
34   if (!bar_arr_.size ())
35     return mol_p;
36   
37   bool no_vertical_start = false;
38   bool no_vertical_end = last_b_;
39   Spanner *orig_span =  dynamic_cast<Spanner*> (original_l_);
40   if (orig_span && (orig_span->broken_into_l_arr_[0] != (Spanner*)this))
41     no_vertical_start = true;
42   if (orig_span && (orig_span->broken_into_l_arr_.top () != (Spanner*)this))
43     no_vertical_end = true;
44   if (bar_arr_.top ()->type_str_.length_i () > 1)
45     no_vertical_end = false;
46
47   Real interline_f = paper_l ()->get_var ("interline");
48   Real internote_f = interline_f/2;
49   Real t = paper_l ()->get_var ("volta_thick");
50
51   Real dx = internote_f;
52   Real w = extent (X_AXIS).length () - dx - get_broken_left_end_align ();
53   Real h = paper_l()->get_var ("volta_spanner_height");
54   Molecule volta (lookup_l ()->volta (h, w, t, no_vertical_start, no_vertical_end));
55
56   
57   Molecule num (lookup_l ()->text ("volta", number_str_, paper_l ()));
58   Real dy = bar_arr_.top ()->extent (Y_AXIS) [UP] > 
59      bar_arr_[0]->extent (Y_AXIS) [UP];
60   dy += 2 * h;
61
62   for (int i = 0; i < note_column_arr_.size (); i++)
63     dy = dy >? note_column_arr_[i]->extent (Y_AXIS)[BIGGER];
64   dy -= h;
65
66   Molecule two (lookup_l ()->text ("number", "2", paper_l ()));
67   Real gap = two.dim_.x ().length () / 2;
68   Offset off (num.dim_.x ().length () + gap, 
69               h / internote_f - gap);
70   num.translate (off);
71   mol_p->add_molecule (volta);
72   mol_p->add_molecule (num);
73   mol_p->translate (Offset (0, dy));
74   return mol_p;
75 }
76   
77 void
78 Volta_spanner::do_add_processing ()
79 {
80   if (bar_arr_.size ())
81     {
82       set_bounds (LEFT, bar_arr_[0]);
83       set_bounds (RIGHT, bar_arr_.top ());  
84     }
85 }
86
87 /*
88     Originally the following comment existed here
89     "in most cases, it's a lot better not no have height...",
90     but problems existed with collision between volta spanner
91     and above staff or lyrics for multi-staff music, so the proper
92     height is now being returned. Additional space should still
93     be added elsewhere so lyrics from above staff do not sit on
94     volta spanner. (Roy R. Rankin)
95 */
96 Interval
97 Volta_spanner::dim_callback (Dimension_cache const *c)
98 {
99   Volta_spanner * v = dynamic_cast<Volta_spanner*> (c->element_l ());
100   Real h = v->paper_l()->get_var ("volta_spanner_height") * 2.;
101   return Interval (0., h);
102 }
103
104 void
105 Volta_spanner::do_post_processing ()
106 {
107   if (bar_arr_.size())
108     translate_axis (bar_arr_[0]->extent (Y_AXIS)[UP], Y_AXIS);
109   translate_axis (get_broken_left_end_align (), X_AXIS);
110 }
111
112 void
113 Volta_spanner::do_substitute_element_pointer (Score_element* o, Score_element* n)
114 {
115   if (Note_column* c = dynamic_cast <Note_column*> (o))
116     note_column_arr_.substitute (c, dynamic_cast<Note_column*> (n));
117   else if (Bar* c = dynamic_cast <Bar*> (o))
118     bar_arr_.substitute (c, dynamic_cast<Bar*> (n));
119 }
120   
121 void
122 Volta_spanner::add_bar  (Bar* c)
123 {
124   bar_arr_.push (c);
125   add_dependency (c);
126 }
127
128 void
129 Volta_spanner::add_column (Note_column* c)
130 {
131   note_column_arr_.push (c);
132   add_dependency (c);
133 }
134
135