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