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