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