]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-spanner.cc
a5b6f629a03e44d9b15a1ee1a0b417c25bf7802d
[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::do_brew_molecule_p () const
40 {
41   Molecule* mol_p = new Molecule;
42
43   if (column_arr_.size ())
44     {
45       Real internote_f = paper ()->internote_f ();
46       Real dx = internote_f;
47       Real w = extent (X_AXIS).length () - 2 * 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       Atom dot (dot_p_->get_atom (paper (), LEFT));
52       Real dy = column_arr_.top ()->extent (Y_AXIS) [dir_] > 
53         column_arr_[0]->extent (Y_AXIS) [dir_];
54       dy += 2 * h;
55
56       /*
57         UGH.  Must use extent  ()[dir_]
58        */
59       for (int i = 0; i < note_column_arr_.size (); i++)
60         dy = dy >? note_column_arr_[i]->extent (Y_AXIS).max ();
61       dy -= h;
62
63       Real gap = num.dim_.x ().length () / 2;
64       Offset off (num.dim_.x ().length () + gap, 
65         (h - num.dim_.y ().length ()) / internote_f - gap);
66       num.translate (off);
67       Real dotheight = dot.dim_.y ().length () / 7;
68       off -= Offset (0, dotheight);
69       dot.translate (off);
70       mol_p->add_atom (volta);
71       mol_p->add_atom (num);
72       mol_p->add_atom (dot);
73       mol_p->translate (Offset (dx, dy));
74     }
75   return mol_p;
76 }
77   
78 void
79 Volta_spanner::do_add_processing ()
80 {
81   if (column_arr_.size ())
82     {
83       set_bounds (LEFT, column_arr_[0]);
84       set_bounds (RIGHT, column_arr_.top ());  
85     }
86   number_p_->style_str_ = "number-1";
87   dot_p_->text_str_ = ".";
88   dot_p_->style_str_ = "bold";
89 }
90   
91 void
92 Volta_spanner::do_post_processing ()
93 {
94     if (column_arr_.size())
95         translate_axis (column_arr_[0]->extent (Y_AXIS)[dir_], Y_AXIS);
96 }
97
98 void
99 Volta_spanner::do_substitute_dependency (Score_element* o, Score_element* n)
100 {
101   if (Note_column* c = dynamic_cast <Note_column*> (o))
102     note_column_arr_.substitute (c, dynamic_cast<Note_column*> (n));
103   else if (Bar* c = dynamic_cast <Bar*> (o))
104     column_arr_.substitute (c, dynamic_cast<Bar*> (n));
105 }
106   
107 void
108 Volta_spanner::add_column (Bar* c)
109 {
110   column_arr_.push (c);
111   add_dependency (c);
112 }
113
114 void
115 Volta_spanner::add_column (Note_column* c)
116 {
117   note_column_arr_.push (c);
118   add_dependency (c);
119 }
120