]> git.donarmstrong.com Git - lilypond.git/blob - lily/tuplet-spanner.cc
release: 1.1.8
[lilypond.git] / lily / tuplet-spanner.cc
1 /*
2   plet-spanner.cc -- implement Plet_spanner
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8 /*
9   todo: handle breaking elegantly.
10  */
11 #include "beam.hh"
12 #include "atom.hh"
13 #include "box.hh"
14 #include "debug.hh"
15 #include "lookup.hh"
16 #include "molecule.hh"
17 #include "p-col.hh"
18 #include "paper-def.hh"
19 #include "tuplet-spanner.hh"
20 #include "stem.hh"
21 #include "text-def.hh"
22 #include "note-column.hh"
23
24 Plet_spanner::Plet_spanner ()
25 {
26   bracket_visibility_b_ = true;
27   num_visibility_b_ = true;
28   
29   tdef_p_.set_p(new Text_def);
30   tdef_p_->align_dir_ = CENTER;
31   tdef_p_->style_str_ = "italic";
32 }
33
34 Molecule*
35 Plet_spanner::brew_molecule_p () const
36 {
37   Molecule* mol_p = new Molecule;
38
39   if (column_arr_.size ()){
40     Real ncw = column_arr_.top ()->extent (X_AXIS).length ();
41     Atom num (tdef_p_->get_atom (paper (), CENTER));
42
43     if (beam_l_ && !bracket_visibility_b_)
44       {
45         num.translate (((Directional_spanner*)beam_l_)->center ());
46         num.translate_axis (ncw, X_AXIS);
47       }
48     
49     if (bracket_visibility_b_)      
50       {
51         Real dy = column_arr_.top ()->extent (Y_AXIS) [dir_]
52           - column_arr_[0]->extent (Y_AXIS) [dir_];
53         Real w = width ().length () + ncw;
54
55         num.translate (Offset (w/2, dy/2));
56         mol_p->add_atom (lookup_l ()->plet (dy, w, dir_));
57       }
58
59     if (num_visibility_b_)
60       mol_p->add_atom (num);
61   }
62   return mol_p;
63 }
64   
65 void
66 Plet_spanner::do_add_processing ()
67 {
68   if (column_arr_.size ())
69     {
70       set_bounds (LEFT, column_arr_[0]);
71       set_bounds (RIGHT, column_arr_.top ());  
72     }
73 }
74   
75 void
76 Plet_spanner::do_post_processing ()
77 {
78   if (column_arr_.size())
79     translate_axis (column_arr_[0]->extent (Y_AXIS)[dir_], Y_AXIS);
80
81   if (!broken_into_l_arr_.size () && beam_l_
82       && spanned_drul_[LEFT]->column_l () == beam_l_->spanned_drul_[LEFT]->column_l ()
83       && spanned_drul_[RIGHT]->column_l () == beam_l_->spanned_drul_[RIGHT]->column_l ())
84     bracket_visibility_b_ = false;
85
86   if (column_arr_.size () == 1)
87     bracket_visibility_b_ = false;
88 }
89
90 void
91 Plet_spanner::do_substitute_dependency (Score_element* o, Score_element* n)
92 {
93   if (Note_column *onc = dynamic_cast <Note_column *> (o))
94     column_arr_.substitute (onc, dynamic_cast<Note_column*> (n));
95   else if (Beam *b = dynamic_cast<Beam *> (o))
96     {
97       if (b == beam_l_) 
98         beam_l_ = dynamic_cast<Beam*> (n);
99     }
100 }
101   
102 void
103 Plet_spanner::set_default_dir ()
104 {
105   dir_ = UP;
106   for (int i=0; i < column_arr_.size (); i ++) 
107     {
108       if (column_arr_[i]->dir_ < 0) 
109         {
110           dir_ = DOWN;
111           break;
112         }
113     }
114 }
115
116 void
117 Plet_spanner::set_beam (Beam *b)
118 {
119   beam_l_ = b;
120   add_dependency (b);
121 }
122
123 void
124 Plet_spanner::add_column (Note_column*n)
125 {
126   column_arr_.push (n);
127   add_dependency (n);
128 }
129