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