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