]> git.donarmstrong.com Git - lilypond.git/blob - lily/tuplet-spanner.cc
release: 1.1.46
[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     Real interline = paper_l ()->get_realvar (interline_scm_sym);
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         
46         num.translate_axis (dir_ * interline,  Y_AXIS);
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         num.align_to (Y_AXIS, CENTER);
57         num.translate_axis (dir_ * interline, Y_AXIS);
58         
59         num.translate (Offset (w/2, dy/2));
60         mol_p->add_molecule (lookup_l ()->plet (dy, w, dir_));
61       }
62
63     if (num_visibility_b_)
64       {
65         mol_p->add_molecule (num);
66       }
67     mol_p->translate_axis (dir_ * interline, Y_AXIS);
68   }
69   return mol_p;
70 }
71   
72 void
73 Tuplet_spanner::do_add_processing ()
74 {
75   if (column_arr_.size ())
76     {
77       set_bounds (LEFT, column_arr_[0]);
78       set_bounds (RIGHT, column_arr_.top ());  
79     }
80 }
81   
82 void
83 Tuplet_spanner::do_post_processing ()
84 {
85   if (column_arr_.size())
86     translate_axis (column_arr_[0]->extent (Y_AXIS)[dir_], Y_AXIS);
87
88   if (beam_l_arr_.size () == 1)
89     {
90       Beam * beam_l = beam_l_arr_[0];
91       if (!broken_b () 
92           && spanned_drul_[LEFT]->column_l () == beam_l->spanned_drul_[LEFT]->column_l ()
93           && spanned_drul_[RIGHT]->column_l () == beam_l->spanned_drul_[RIGHT]->column_l ())
94         bracket_visibility_b_ = false;
95     }
96
97   if (column_arr_.size () == 1)
98     bracket_visibility_b_ = false;
99 }
100
101 void
102 Tuplet_spanner::do_substitute_element_pointer (Score_element* o, Score_element* n)
103 {
104   if (Note_column *onc = dynamic_cast <Note_column *> (o))
105     column_arr_.substitute (onc, dynamic_cast<Note_column*> (n));
106   else if (Beam * b = dynamic_cast<Beam* > (o))
107     {
108       beam_l_arr_.substitute (b,  dynamic_cast<Beam*> (n));
109     }
110 }
111
112 Direction
113 Tuplet_spanner::get_default_dir () const
114 {
115   Direction d = UP;
116   for (int i=0; i < column_arr_.size (); i ++) 
117     {
118       if (column_arr_[i]->dir () < 0) 
119         {
120           d = DOWN;
121           break;
122         }
123     }
124   return d;
125 }
126
127 void
128 Tuplet_spanner::add_beam (Beam *b)
129 {
130   add_dependency (b);
131   beam_l_arr_.push (b);
132 }
133
134 void
135 Tuplet_spanner::add_column (Note_column*n)
136 {
137   column_arr_.push (n);
138   add_dependency (n);
139 }
140