]> git.donarmstrong.com Git - lilypond.git/blob - lily/tuplet-spanner.cc
release: 1.1.38
[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
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
31 Molecule*
32 Tuplet_spanner::do_brew_molecule_p () const
33 {
34   Molecule* mol_p = new Molecule;
35
36   if (column_arr_.size ()){
37     Real ncw = column_arr_.top ()->extent (X_AXIS).length ();
38     Molecule num (lookup_l ()->text ("italic",
39                                      number_str_));
40
41     if (beam_l_ && !bracket_visibility_b_)
42       {
43         Directional_spanner* ds = dynamic_cast<Directional_spanner*>(beam_l_);
44         num.translate (ds->center ());
45         num.translate_axis (ncw, X_AXIS);
46       }
47     
48     if (bracket_visibility_b_)      
49       {
50         Real dy = column_arr_.top ()->extent (Y_AXIS) [dir_]
51           - column_arr_[0]->extent (Y_AXIS) [dir_];
52         Real w = extent (X_AXIS).length () + ncw;
53
54         num.translate (Offset (w/2, dy/2));
55         mol_p->add_molecule (lookup_l ()->plet (dy, w, dir_));
56       }
57
58     if (num_visibility_b_)
59       mol_p->add_molecule (num);
60   }
61   return mol_p;
62 }
63   
64 void
65 Tuplet_spanner::do_add_processing ()
66 {
67   if (column_arr_.size ())
68     {
69       set_bounds (LEFT, column_arr_[0]);
70       set_bounds (RIGHT, column_arr_.top ());  
71     }
72 }
73   
74 void
75 Tuplet_spanner::do_post_processing ()
76 {
77   if (column_arr_.size())
78     translate_axis (column_arr_[0]->extent (Y_AXIS)[dir_], Y_AXIS);
79
80   if (!broken_b () && beam_l_
81       && spanned_drul_[LEFT]->column_l () == beam_l_->spanned_drul_[LEFT]->column_l ()
82       && spanned_drul_[RIGHT]->column_l () == beam_l_->spanned_drul_[RIGHT]->column_l ())
83     bracket_visibility_b_ = false;
84
85   if (column_arr_.size () == 1)
86     bracket_visibility_b_ = false;
87 }
88
89 void
90 Tuplet_spanner::do_substitute_element_pointer (Score_element* o, Score_element* n)
91 {
92   if (Note_column *onc = dynamic_cast <Note_column *> (o))
93     column_arr_.substitute (onc, dynamic_cast<Note_column*> (n));
94   else if (o == beam_l_)
95     {
96       beam_l_ = dynamic_cast<Beam*> (n);
97     }
98 }
99
100 void
101 Tuplet_spanner::set_default_dir ()
102 {
103   dir_ = UP;
104   for (int i=0; i < column_arr_.size (); i ++) 
105     {
106       if (column_arr_[i]->dir () < 0) 
107         {
108           dir_ = DOWN;
109           break;
110         }
111     }
112 }
113
114 void
115 Tuplet_spanner::set_beam (Beam *b)
116 {
117   assert(!beam_l_);
118   beam_l_ = b;
119   add_dependency (b);
120 }
121
122 void
123 Tuplet_spanner::add_column (Note_column*n)
124 {
125   column_arr_.push (n);
126   add_dependency (n);
127 }
128