]> git.donarmstrong.com Git - lilypond.git/blob - lily/tuplet-spanner.cc
patch::: 1.3.9.hwn2
[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 "paper-column.hh"
15 #include "paper-def.hh"
16 #include "tuplet-spanner.hh"
17 #include "stem.hh"
18 #include "note-column.hh"
19 #include "dimensions.hh"
20
21
22 Tuplet_spanner::Tuplet_spanner ()
23 {
24   /*
25     -> GUILE
26    */
27   parallel_beam_b_ = false;
28 }
29
30 /*
31   TODO. 
32  */
33 Molecule*
34 Tuplet_spanner::do_brew_molecule_p () const
35 {
36   Molecule* mol_p = new Molecule;
37
38   // Default behaviour: number always, bracket when no beam!
39   bool bracket_visibility = !parallel_beam_b_;
40   bool number_visibility = true;
41   SCM visibility_sym =get_elt_property ("tuplet-visibility");
42   if (visibility_sym != SCM_UNDEFINED)
43     {
44       /*
45         ARG. Fixme.
46        */
47       
48       /* Property values:
49          0       show nothing
50          1       show number
51          2       show (number and bracket)-if-no-beam
52          3       show number, and bracket-if-no-beam
53          4       show number, and bracket
54       */
55       int value = gh_scm2int ((visibility_sym));
56       bracket_visibility = (value == 4 || (value > 1 && !parallel_beam_b_));
57       number_visibility = (value > 2 || value == 1 || 
58                            (value == 2 && !parallel_beam_b_));
59     }
60   
61   if (column_arr_.size ()){
62     Real ncw = column_arr_.top ()->extent (X_AXIS).length ();
63     Real w = extent (X_AXIS).length () + ncw;
64     Molecule num (lookup_l ()->text ("italic",
65                                      number_str_, paper_l ()));
66     num.align_to (X_AXIS, CENTER);
67     num.translate_axis (w/2, X_AXIS);
68     Real interline = paper_l ()->get_var ("interline");
69     Real dy = column_arr_.top ()->extent (Y_AXIS) [get_direction ()]
70       - column_arr_[0]->extent (Y_AXIS) [get_direction ()];
71     num.align_to (Y_AXIS, CENTER);
72     num.translate_axis (get_direction () * interline, Y_AXIS);
73         
74     num.translate_axis (dy/2, Y_AXIS);
75     
76     Real thick = paper_l ()->get_var ("tuplet_thick");
77     if (bracket_visibility)      
78       {
79         Real gap = paper_l () -> get_var ("tuplet_spanner_gap");
80         
81         mol_p->add_molecule (lookup_l ()->tuplet_bracket (dy, w, thick, gap, interline, get_direction ()));
82       }
83
84     if (number_visibility)
85       {
86         mol_p->add_molecule (num);
87       }
88     mol_p->translate_axis (get_direction () * interline, Y_AXIS);
89   }
90   return mol_p;
91 }
92   
93 void
94 Tuplet_spanner::do_add_processing ()
95 {
96   if (column_arr_.size ())
97     {
98       set_bounds (LEFT, column_arr_[0]);
99       set_bounds (RIGHT, column_arr_.top ());  
100     }
101 }
102   
103 void
104 Tuplet_spanner::do_post_processing ()
105 {
106   if (column_arr_.size())
107     translate_axis (column_arr_[0]->extent (Y_AXIS)[get_direction ()], Y_AXIS);
108
109   if (beam_l_arr_.size () == 1)
110     {
111       Beam * beam_l = beam_l_arr_[0];
112       if (!broken_b () 
113           && spanned_drul_[LEFT]->column_l () == beam_l->spanned_drul_[LEFT]->column_l ()
114           && spanned_drul_[RIGHT]->column_l () == beam_l->spanned_drul_[RIGHT]->column_l ())
115         parallel_beam_b_ = true;
116     }
117
118   //  if (column_arr_.size () == 1)
119   //    bracket_visibility_b_ = false;
120 }
121
122 void
123 Tuplet_spanner::do_substitute_element_pointer (Score_element* o, Score_element* n)
124 {
125   if (Note_column *onc = dynamic_cast <Note_column *> (o))
126     column_arr_.substitute (onc, dynamic_cast<Note_column*> (n));
127   else if (Beam * b = dynamic_cast<Beam* > (o))
128     {
129       beam_l_arr_.substitute (b,  dynamic_cast<Beam*> (n));
130     }
131 }
132
133 Direction
134 Tuplet_spanner::get_default_dir () const
135 {
136   Direction d = UP;
137   SCM dir_sym =get_elt_property ("dir-forced");
138   if (dir_sym != SCM_UNDEFINED) {
139     d= (Direction) gh_scm2int (dir_sym);
140     if (d != CENTER)
141       return d;
142   }
143
144   for (int i=0; i < column_arr_.size (); i ++) 
145     {
146       if (column_arr_[i]->dir () < 0) 
147         {
148           d = DOWN;
149           break;
150         }
151     }
152   return d;
153 }
154
155 void
156 Tuplet_spanner::add_beam (Beam *b)
157 {
158   add_dependency (b);
159   beam_l_arr_.push (b);
160 }
161
162 void
163 Tuplet_spanner::add_column (Note_column*n)
164 {
165   column_arr_.push (n);
166   add_dependency (n);
167 }
168
169