2 plet-engraver.cc -- implement Tuplet_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "command-request.hh"
12 #include "tuplet-spanner.hh"
13 #include "note-column.hh"
14 #include "time-scaled-music.hh"
16 #include "music-list.hh"
17 #include "engraver.hh"
20 class Tuplet_engraver
: public Engraver
23 VIRTUAL_COPY_CONS(Translator
);
26 Link_array
<Time_scaled_music
> time_scaled_music_arr_
;
27 /// when does the scaled music stop? Array order is synced with time_scaled_music_arr_
28 Array
<Moment
> stop_moments_
;
29 /// when does the current spanner stop? Array order is synced with time_scaled_music_arr_
30 Array
<Moment
> span_stop_moments_
;
32 /// The spanners. Array order is synced with time_scaled_music_arr_
33 Link_array
<Spanner
> started_span_p_arr_
;
35 virtual void finalize ();
36 virtual void acknowledge_grob (Grob_info
);
37 virtual bool try_music (Music
*r
);
38 virtual void start_translation_timestep ();
39 virtual void create_grobs ();
43 Tuplet_engraver::try_music (Music
*r
)
45 if (Time_scaled_music
* c
= dynamic_cast<Time_scaled_music
*> (r
))
47 Music
*el
= c
->element ();
48 if (!dynamic_cast<Request_chord
*> (el
))
50 time_scaled_music_arr_
.push (c
);
51 Moment m
= now_mom () + c
->length_mom ();
52 stop_moments_
.push (m
);
54 SCM s
= get_property ("tupletSpannerDuration");
56 m
= m
<? (now_mom () + *unsmob_moment (s
));
58 span_stop_moments_
.push (m
);
66 Tuplet_engraver::create_grobs ()
68 SCM v
= get_property ("tupletInvisible");
72 for (int i
= 0; i
< time_scaled_music_arr_
.size (); i
++)
74 if (i
< started_span_p_arr_
.size () && started_span_p_arr_
[i
])
77 Spanner
* glep
= new Spanner (get_property ("TupletBracket"));
78 Tuplet_spanner::set_interface (glep
);
79 if (i
>= started_span_p_arr_
.size ())
80 started_span_p_arr_
.push (glep
);
82 started_span_p_arr_
[i
] = glep
;
85 int d
= gh_scm2int (time_scaled_music_arr_
[i
]->get_mus_property ("denominator"));
86 glep
->set_grob_property ("text", ly_str02scm (to_str (d
).ch_C()));
88 announce_grob (glep
, time_scaled_music_arr_
[i
]);
93 Tuplet_engraver::acknowledge_grob (Grob_info i
)
95 bool grace
= to_boolean (i
.elem_l_
->get_grob_property ("grace"));
96 SCM wg
= get_property ("weAreGraceContext");
97 bool wgb
= to_boolean (wg
);
101 if (Note_column::has_interface(i
.elem_l_
))
103 for (int j
=0; j
<started_span_p_arr_
.size (); j
++)
104 if (started_span_p_arr_
[j
])
105 Tuplet_spanner::add_column (started_span_p_arr_
[j
], dynamic_cast<Item
*>(i
.elem_l_
));
107 else if (Beam::has_interface (i
.elem_l_
))
109 for (int j
= 0; j
< started_span_p_arr_
.size (); j
++)
110 if (started_span_p_arr_
[j
])
111 Tuplet_spanner::add_beam (started_span_p_arr_
[j
],i
.elem_l_
);
116 Tuplet_engraver::start_translation_timestep ()
118 Moment now
= now_mom ();
121 SCM s
= get_property ("tupletSpannerDuration");
122 if (unsmob_moment (s
))
123 tsd
= *unsmob_moment (s
);
125 for (int i
= started_span_p_arr_
.size (); i
--; )
127 if (now
>= span_stop_moments_
[i
])
129 if (started_span_p_arr_
[i
])
131 typeset_grob (started_span_p_arr_
[i
]);
132 started_span_p_arr_
[i
] =0;
136 span_stop_moments_
[i
] += tsd
;
139 if (now
>= stop_moments_
[i
])
141 started_span_p_arr_
.del (i
);
142 stop_moments_
.del(i
);
143 span_stop_moments_
.del (i
);
144 time_scaled_music_arr_
.del(i
);
150 Tuplet_engraver::finalize ()
152 for (int i
=0; i
< started_span_p_arr_
.size (); i
++)
154 if (started_span_p_arr_
[i
])
155 typeset_grob (started_span_p_arr_
[i
]);
159 ADD_THIS_TRANSLATOR(Tuplet_engraver
);