]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-spanner.cc
release: 1.1.53
[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 "p-col.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   Real interline_f = paper_l ()->get_realvar (interline_scm_sym);
37   Real internote_f = interline_f/2;
38   Real t = paper_l ()->get_realvar (volta_thick_scm_sym);
39
40   Real dx = internote_f;
41   Real w = extent (X_AXIS).length () - dx;
42   Molecule volta (lookup_l ()->volta (w, t, interline_f, last_b_));
43   Real h = volta.dim_.y ().length ();
44   
45   Molecule num (lookup_l ()->text ("volta", number_str_, paper_l ()));
46   Real dy = bar_arr_.top ()->extent (Y_AXIS) [UP] > 
47      bar_arr_[0]->extent (Y_AXIS) [UP];
48   dy += 2 * h;
49
50   for (int i = 0; i < note_column_arr_.size (); i++)
51     dy = dy >? note_column_arr_[i]->extent (Y_AXIS)[BIGGER];
52   dy -= h;
53
54   Molecule two (lookup_l ()->text ("number", "2", paper_l ()));
55   Real gap = two.dim_.x ().length () / 2;
56   Offset off (num.dim_.x ().length () + gap, 
57               h / internote_f - gap);
58   num.translate (off);
59   mol_p->add_molecule (volta);
60   mol_p->add_molecule (num);
61   mol_p->translate (Offset (0, dy));
62   return mol_p;
63 }
64   
65 void
66 Volta_spanner::do_add_processing ()
67 {
68   if (bar_arr_.size ())
69     {
70       set_bounds (LEFT, bar_arr_[0]);
71       set_bounds (RIGHT, bar_arr_.top ());  
72     }
73 }
74   
75 Interval
76 Volta_spanner::do_height () const
77 {
78   /*
79     in most cases, it's a lot better not no have height...
80   */
81   Interval i;
82   return i;
83 }
84
85 void
86 Volta_spanner::do_post_processing ()
87 {
88   if (bar_arr_.size())
89     translate_axis (bar_arr_[0]->extent (Y_AXIS)[UP], Y_AXIS);
90 }
91
92 void
93 Volta_spanner::do_substitute_element_pointer (Score_element* o, Score_element* n)
94 {
95   if (Note_column* c = dynamic_cast <Note_column*> (o))
96     note_column_arr_.substitute (c, dynamic_cast<Note_column*> (n));
97   else if (Bar* c = dynamic_cast <Bar*> (o))
98     bar_arr_.substitute (c, dynamic_cast<Bar*> (n));
99 }
100   
101 void
102 Volta_spanner::add_bar  (Bar* c)
103 {
104   bar_arr_.push (c);
105   add_dependency (c);
106 }
107
108 void
109 Volta_spanner::add_column (Note_column* c)
110 {
111   note_column_arr_.push (c);
112   add_dependency (c);
113 }
114