]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-spanner.cc
patch::: 1.1.23.jcn4: %-|
[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 Volta_spanner::Volta_spanner ()
24 {
25   last_b_ = false;
26   number_p_.set_p (new Text_def);
27   number_p_->align_dir_ = LEFT;
28   dot_p_.set_p (new Text_def);
29   dot_p_->align_dir_ = LEFT;
30 }
31
32 Molecule*
33 Volta_spanner::do_brew_molecule_p () const
34 {
35   Molecule* mol_p = new Molecule;
36
37   if (!column_arr_.size ())
38     return mol_p;
39
40   Real internote_f = paper ()->internote_f ();
41   Real dx = internote_f;
42   Real w = extent (X_AXIS).length () - 2 * dx;
43   Atom volta (lookup_l ()->volta (w, last_b_));
44   Real h = volta.dim_.y ().length ();
45   Atom num (number_p_->get_atom (paper (), LEFT));
46   Atom dot (dot_p_->get_atom (paper (), LEFT));
47   Real dy = column_arr_.top ()->extent (Y_AXIS) [UP] > 
48      column_arr_[0]->extent (Y_AXIS) [UP];
49   dy += 2 * h;
50
51   /*
52     UGH.  Must use extent  ()[dir_]
53    */
54   for (int i = 0; i < note_column_arr_.size (); i++)
55     dy = dy >? note_column_arr_[i]->extent (Y_AXIS).max ();
56   dy -= h;
57
58   Real gap = num.dim_.x ().length () / 2;
59   Offset off (num.dim_.x ().length () + gap, 
60     (h - num.dim_.y ().length ()) / internote_f - gap);
61   num.translate (off);
62   Real dotheight = dot.dim_.y ().length () / 7;
63   off -= Offset (0, dotheight);
64   dot.translate (off);
65   mol_p->add_atom (volta);
66   mol_p->add_atom (num);
67   mol_p->add_atom (dot);
68   mol_p->translate (Offset (dx, 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       // huh?
80       // array.top () == last element??
81       // list.top () == first element
82       set_bounds (RIGHT, column_arr_[column_arr_.size () - 1]);  
83     }
84   number_p_->style_str_ = "number-1";
85   dot_p_->text_str_ = ".";
86   dot_p_->style_str_ = "bold";
87 }
88   
89 void
90 Volta_spanner::do_post_processing ()
91 {
92   if (column_arr_.size())
93     translate_axis (column_arr_[0]->extent (Y_AXIS)[UP], Y_AXIS);
94 }
95
96 void
97 Volta_spanner::do_substitute_dependency (Score_element* o, Score_element* n)
98 {
99   if (Note_column* c = dynamic_cast <Note_column*> (o))
100     note_column_arr_.substitute (c, dynamic_cast<Note_column*> (n));
101   else if (Bar* c = dynamic_cast <Bar*> (o))
102     column_arr_.substitute (c, dynamic_cast<Bar*> (n));
103 }
104   
105 void
106 Volta_spanner::add_column (Bar* c)
107 {
108   column_arr_.push (c);
109   add_dependency (c);
110 }
111
112 void
113 Volta_spanner::add_column (Note_column* c)
114 {
115   note_column_arr_.push (c);
116   add_dependency (c);
117 }
118