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