]> git.donarmstrong.com Git - lilypond.git/blob - lily/tuplet-spanner.cc
release: 1.1.39
[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 #include "beam.hh"
10 #include "box.hh"
11 #include "debug.hh"
12 #include "lookup.hh"
13 #include "molecule.hh"
14 #include "p-col.hh"
15 #include "paper-def.hh"
16 #include "tuplet-spanner.hh"
17 #include "stem.hh"
18 #include "note-column.hh"
19
20 Tuplet_spanner::Tuplet_spanner ()
21 {
22   bracket_visibility_b_ = true;
23   num_visibility_b_ = true;
24 }
25
26 /*
27   TODO.  We should control the gap for lookup from here.
28  */
29 Molecule*
30 Tuplet_spanner::do_brew_molecule_p () const
31 {
32   Molecule* mol_p = new Molecule;
33
34   if (column_arr_.size ()){
35     Real ncw = column_arr_.top ()->extent (X_AXIS).length ();
36     Molecule num (lookup_l ()->text ("italic",
37                                      number_str_));
38     num.align_to (X_AXIS, CENTER);
39     num.translate_axis (dir_ * paper_l ()->get_realvar (interline_scm_sym),  Y_AXIS);
40
41     if (beam_l_arr_.size () == 1 && !bracket_visibility_b_)
42       {
43         Beam *beam_l = beam_l_arr_[0];
44         Directional_spanner* ds = dynamic_cast<Directional_spanner*>(beam_l);
45         num.translate (ds->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 = extent (X_AXIS).length () + ncw;
54         //      num.align_to (Y_AXIS, CENTER);
55         num.translate (Offset (w/2, dy/2));
56         mol_p->add_molecule (lookup_l ()->plet (dy, w, dir_));
57       }
58
59     if (num_visibility_b_)
60       {
61         mol_p->add_molecule (num);
62       }
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 (beam_l_arr_.size () == 1)
84     {
85       Beam * beam_l = beam_l_arr_[0];
86       if (!broken_b () 
87           && spanned_drul_[LEFT]->column_l () == beam_l->spanned_drul_[LEFT]->column_l ()
88           && spanned_drul_[RIGHT]->column_l () == beam_l->spanned_drul_[RIGHT]->column_l ())
89         bracket_visibility_b_ = false;
90     }
91
92   if (column_arr_.size () == 1)
93     bracket_visibility_b_ = false;
94 }
95
96 void
97 Tuplet_spanner::do_substitute_element_pointer (Score_element* o, Score_element* n)
98 {
99   if (Note_column *onc = dynamic_cast <Note_column *> (o))
100     column_arr_.substitute (onc, dynamic_cast<Note_column*> (n));
101   else if (Beam * b = dynamic_cast<Beam* > (o))
102     {
103       beam_l_arr_.substitute (b,  dynamic_cast<Beam*> (n));
104     }
105 }
106
107 Direction
108 Tuplet_spanner::get_default_dir () const
109 {
110   Direction d = UP;
111   for (int i=0; i < column_arr_.size (); i ++) 
112     {
113       if (column_arr_[i]->dir () < 0) 
114         {
115           d = DOWN;
116           break;
117         }
118     }
119   return d;
120 }
121
122 void
123 Tuplet_spanner::add_beam (Beam *b)
124 {
125   add_dependency (b);
126   beam_l_arr_.push (b);
127 }
128
129 void
130 Tuplet_spanner::add_column (Note_column*n)
131 {
132   column_arr_.push (n);
133   add_dependency (n);
134 }
135