2 plet-spanner.cc -- implement Tuplet_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Jan Nieuwenhuizen <janneke@gnu.org>
13 #include "molecule.hh"
15 #include "paper-def.hh"
16 #include "tuplet-spanner.hh"
18 #include "note-column.hh"
19 #include "dimensions.hh"
22 Tuplet_spanner::Tuplet_spanner ()
24 parallel_beam_b_
= false;
28 TODO. We should control the gap for lookup from here.
31 Tuplet_spanner::do_brew_molecule_p () const
33 Molecule
* mol_p
= new Molecule
;
35 // Default behaviour: number always, bracket when no beam!
36 bool bracket_visibility
= !parallel_beam_b_
;
37 bool number_visibility
= true;
38 SCM visibility_sym
=get_elt_property (tuplet_visibility_scm_sym
);
39 if (visibility_sym
!= SCM_BOOL_F
)
44 2 show (number and bracket)-if-no-beam
45 3 show number, and bracket-if-no-beam
46 4 show number, and bracket
48 int value
= gh_scm2int (SCM_CDR(visibility_sym
));
49 bracket_visibility
= (value
== 4 || (value
> 1 && !parallel_beam_b_
));
50 number_visibility
= (value
> 2 || value
== 1 ||
51 (value
== 2 && !parallel_beam_b_
));
54 if (column_arr_
.size ()){
55 Real ncw
= column_arr_
.top ()->extent (X_AXIS
).length ();
56 Real w
= extent (X_AXIS
).length () + ncw
;
57 Molecule
num (lookup_l ()->text ("italic",
58 number_str_
, paper_l ()));
59 num
.align_to (X_AXIS
, CENTER
);
60 num
.translate_axis (w
/2, X_AXIS
);
61 Real interline
= paper_l ()->get_realvar (interline_scm_sym
);
62 Real dy
= column_arr_
.top ()->extent (Y_AXIS
) [dir_
]
63 - column_arr_
[0]->extent (Y_AXIS
) [dir_
];
64 num
.align_to (Y_AXIS
, CENTER
);
65 num
.translate_axis (dir_
* interline
, Y_AXIS
);
67 num
.translate_axis (dy
/2, Y_AXIS
);
69 Real thick
= paper_l ()->get_realvar (tuplet_thick_scm_sym
);
70 if (bracket_visibility
)
72 mol_p
->add_molecule (lookup_l ()->tuplet_bracket (dy
, w
, thick
, interline
, dir_
));
75 if (number_visibility
)
77 mol_p
->add_molecule (num
);
79 mol_p
->translate_axis (dir_
* interline
, Y_AXIS
);
85 Tuplet_spanner::do_add_processing ()
87 if (column_arr_
.size ())
89 set_bounds (LEFT
, column_arr_
[0]);
90 set_bounds (RIGHT
, column_arr_
.top ());
95 Tuplet_spanner::do_post_processing ()
97 if (column_arr_
.size())
98 translate_axis (column_arr_
[0]->extent (Y_AXIS
)[dir_
], Y_AXIS
);
100 if (beam_l_arr_
.size () == 1)
102 Beam
* beam_l
= beam_l_arr_
[0];
104 && spanned_drul_
[LEFT
]->column_l () == beam_l
->spanned_drul_
[LEFT
]->column_l ()
105 && spanned_drul_
[RIGHT
]->column_l () == beam_l
->spanned_drul_
[RIGHT
]->column_l ())
106 parallel_beam_b_
= true;
109 // if (column_arr_.size () == 1)
110 // bracket_visibility_b_ = false;
114 Tuplet_spanner::do_substitute_element_pointer (Score_element
* o
, Score_element
* n
)
116 if (Note_column
*onc
= dynamic_cast <Note_column
*> (o
))
117 column_arr_
.substitute (onc
, dynamic_cast<Note_column
*> (n
));
118 else if (Beam
* b
= dynamic_cast<Beam
* > (o
))
120 beam_l_arr_
.substitute (b
, dynamic_cast<Beam
*> (n
));
125 Tuplet_spanner::get_default_dir () const
128 SCM dir_sym
=get_elt_property (dir_forced_scm_sym
);
129 if (dir_sym
!= SCM_BOOL_F
) {
130 d
= (Direction
) gh_scm2int (SCM_CDR(dir_sym
));
135 for (int i
=0; i
< column_arr_
.size (); i
++)
137 if (column_arr_
[i
]->dir () < 0)
147 Tuplet_spanner::add_beam (Beam
*b
)
150 beam_l_arr_
.push (b
);
154 Tuplet_spanner::add_column (Note_column
*n
)
156 column_arr_
.push (n
);