]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-spanner.cc
86a16e1c324fb04026d01fb23042f05192ba62de
[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" // urg
16 #include "bar.hh"
17 #include "p-col.hh"
18 #include "paper-def.hh"
19 #include "volta-spanner.hh"
20 #include "stem.hh"
21 #include "text-def.hh"
22
23 /*
24    Hmm, should probably make generic Bracket_spanner,
25    or and derive Plet and volta spanner from that.
26  */
27
28 Volta_spanner::Volta_spanner ()
29 {
30   dir_ = UP;
31   last_b_ = false;
32   number_p_.set_p (new Text_def);
33   number_p_->align_dir_ = LEFT;
34   dot_p_.set_p (new Text_def);
35   dot_p_->align_dir_ = LEFT;
36 }
37
38 Molecule*
39 Volta_spanner::brew_molecule_p () const
40 {
41   Molecule* mol_p = new Molecule;
42
43   if (column_arr_.size ()){
44     Real dx = paper ()->internote_f ();
45     Real w = width ().length () - 2 * dx;
46     Real dy = column_arr_.top ()->extent (Y_AXIS) [dir_] > 
47       column_arr_[0]->extent (Y_AXIS) [dir_];
48     dy += 4;
49
50     Atom num (number_p_->get_atom (paper (), LEFT));
51     Atom dot (dot_p_->get_atom (paper (), LEFT));
52     Real gap = num.dim_.x ().length () / 2;
53     Offset off (num.dim_.x ().length () + gap, 
54       num.dim_.y ().length () - 4 - gap / paper ()->internote_f ());
55     // urg?
56     off -= Offset (0, num.dim_.y ().length () + gap / paper ()->internote_f ());
57     num.translate (off);
58     dot.translate (off);
59     mol_p->add_atom (num);
60     mol_p->add_atom (dot);
61     mol_p->add_atom (lookup_l ()->volta (w, last_b_));
62     mol_p->translate (Offset (dx, dy));
63   }
64   return mol_p;
65 }
66   
67 void
68 Volta_spanner::do_add_processing ()
69 {
70   if (column_arr_.size ())
71     {
72       set_bounds (LEFT, column_arr_[0]);
73       set_bounds (RIGHT, column_arr_.top ());  
74     }
75   number_p_->style_str_ = "number-1";
76   dot_p_->text_str_ = ".";
77   dot_p_->style_str_ = "bold";
78 }
79   
80 void
81 Volta_spanner::do_post_processing ()
82 {
83     if (column_arr_.size())
84         translate_axis (column_arr_[0]->extent (Y_AXIS)[dir_], Y_AXIS);
85 }
86
87 void
88 Volta_spanner::do_substitute_dependency (Score_element* o, Score_element* n)
89 {
90 //  if (Note_column* c = dynamic_cast <Note_column*> (o))
91 //    column_arr_.substitute (c, dynamic_cast<Note_column*> (n));
92   if (Bar* c = dynamic_cast <Bar*> (o))
93     column_arr_.substitute (c, dynamic_cast<Bar*> (n));
94 }
95   
96 void
97 //Volta_spanner::add_column (Note_column* c)
98 Volta_spanner::add_column (Bar* c)
99 {
100   column_arr_.push (c);
101   add_dependency (c);
102 }
103