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