]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-spanner.cc
patch::: 1.1.25.jcn1: jcn1
[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--1998 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "atom.hh"
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 #include "text-def.hh"
21 #include "pointer.tcc"
22
23 template class P<Text_def>;             // UGH
24
25
26 Volta_spanner::Volta_spanner ()
27 {
28   last_b_ = false;
29   visible_b_ = true;
30   number_p_.set_p (new Text_def);
31   number_p_->align_dir_ = LEFT;
32 }
33
34 Molecule*
35 Volta_spanner::do_brew_molecule_p () const
36 {
37   Molecule* mol_p = new Molecule;
38
39   if (!column_arr_.size ())
40     return mol_p;
41
42   if (!visible_b_)
43     return mol_p;
44
45   Real internote_f = paper ()->internote_f ();
46   Real dx = internote_f;
47   Real w = extent (X_AXIS).length () - dx;
48   Atom volta (lookup_l ()->volta (w, last_b_));
49   Real h = volta.dim_.y ().length ();
50   Atom num (number_p_->get_atom (paper (), LEFT));
51   Real dy = column_arr_.top ()->extent (Y_AXIS) [UP] > 
52      column_arr_[0]->extent (Y_AXIS) [UP];
53   dy += 2 * h;
54
55   /*
56     UGH.  Must use extent  ()[dir_]
57    */
58   for (int i = 0; i < note_column_arr_.size (); i++)
59     dy = dy >? note_column_arr_[i]->extent (Y_AXIS).max ();
60   dy -= h;
61
62   Real gap = num.dim_.x ().length () / 2;
63   Offset off (num.dim_.x ().length () + gap, 
64               h / internote_f - gap);
65   num.translate (off);
66   mol_p->add_atom (volta);
67   mol_p->add_atom (num);
68   mol_p->translate (Offset (0, dy));
69   return mol_p;
70 }
71   
72 void
73 Volta_spanner::do_add_processing ()
74 {
75   if (column_arr_.size ())
76     {
77       set_bounds (LEFT, column_arr_[0]);
78       set_bounds (RIGHT, column_arr_.top ());  
79     }
80
81   number_p_->style_str_ = "number-1";
82 }
83   
84 Interval
85 Volta_spanner::do_height () const
86 {
87   /*
88     in most cases, it's a lot better not no have height...
89   */
90   Interval i;
91   return i;
92 }
93
94 void
95 Volta_spanner::do_post_processing ()
96 {
97   if (column_arr_.size())
98     translate_axis (column_arr_[0]->extent (Y_AXIS)[UP], Y_AXIS);
99 }
100
101 void
102 Volta_spanner::do_substitute_dependency (Score_element* o, Score_element* n)
103 {
104   if (Note_column* c = dynamic_cast <Note_column*> (o))
105     note_column_arr_.substitute (c, dynamic_cast<Note_column*> (n));
106   else if (Bar* c = dynamic_cast <Bar*> (o))
107     column_arr_.substitute (c, dynamic_cast<Bar*> (n));
108 }
109   
110 void
111 Volta_spanner::add_column (Bar* c)
112 {
113   column_arr_.push (c);
114   add_dependency (c);
115 }
116
117 void
118 Volta_spanner::add_column (Note_column* c)
119 {
120   note_column_arr_.push (c);
121   add_dependency (c);
122 }
123