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"
19 class Tuplet_engraver
: public Engraver
22 VIRTUAL_COPY_CONS(Translator
);
25 Link_array
<Time_scaled_music
> time_scaled_music_arr_
;
26 /// when does the scaled music stop? Array order is synced with time_scaled_music_arr_
27 Array
<Moment
> stop_moments_
;
28 /// when does the current spanner stop? Array order is synced with time_scaled_music_arr_
29 Array
<Moment
> span_stop_moments_
;
31 /// The spanners. Array order is synced with time_scaled_music_arr_
32 Link_array
<Tuplet_spanner
> started_span_p_arr_
;
34 virtual void do_removal_processing ();
35 virtual void acknowledge_element (Score_element_info
);
36 virtual bool do_try_music (Music
*r
);
37 virtual void do_process_music ();
38 virtual void do_post_move_processing ();
42 Tuplet_engraver::do_try_music (Music
*r
)
44 if (Time_scaled_music
* c
= dynamic_cast<Time_scaled_music
*> (r
))
46 Music
*el
= c
->element_l ();
47 if (!dynamic_cast<Request_chord
*> (el
))
49 time_scaled_music_arr_
.push (c
);
50 Moment m
= now_mom () + c
->length_mom ();
51 stop_moments_
.push (m
);
53 SCM s
= get_property ("tupletSpannerDuration");
55 m
= m
<? (now_mom () + *unsmob_moment (s
));
57 span_stop_moments_
.push (m
);
65 Tuplet_engraver::do_process_music ()
67 SCM v
= get_property ("tupletInvisible");
71 for (int i
= 0; i
< time_scaled_music_arr_
.size (); i
++)
73 if (i
< started_span_p_arr_
.size () && started_span_p_arr_
[i
])
76 Tuplet_spanner
* glep
= new Tuplet_spanner (get_property ("basicTupletSpannerProperties"));
77 if (i
>= started_span_p_arr_
.size ())
78 started_span_p_arr_
.push (glep
);
80 started_span_p_arr_
[i
] = glep
;
82 glep
->set_elt_property ("text",
83 ly_str02scm (to_str (time_scaled_music_arr_
[i
]->den_i_
).ch_C()));
85 announce_element (Score_element_info (glep
, time_scaled_music_arr_
[i
]));
90 Tuplet_engraver::acknowledge_element (Score_element_info i
)
92 bool grace
= to_boolean (i
.elem_l_
->get_elt_property ("grace"));
93 SCM wg
= get_property ("weAreGraceContext");
94 bool wgb
= to_boolean (wg
);
98 if (Note_column
*nc
= dynamic_cast<Note_column
*> (i
.elem_l_
))
100 for (int j
=0; j
<started_span_p_arr_
.size (); j
++)
101 if (started_span_p_arr_
[j
])
102 started_span_p_arr_
[j
]->add_column (nc
);
104 else if (Beam
*b
= dynamic_cast<Beam
*> (i
.elem_l_
))
106 for (int j
= 0; j
< started_span_p_arr_
.size (); j
++)
107 if (started_span_p_arr_
[j
])
108 started_span_p_arr_
[j
]->add_beam (b
);
113 Tuplet_engraver::do_post_move_processing ()
115 Moment now
= now_mom ();
118 SCM s
= get_property ("tupletSpannerDuration");
119 if (unsmob_moment (s
))
120 tsd
= *unsmob_moment (s
);
122 for (int i
= started_span_p_arr_
.size (); i
--; )
124 if (now
>= span_stop_moments_
[i
])
126 if (started_span_p_arr_
[i
])
128 typeset_element (started_span_p_arr_
[i
]);
129 started_span_p_arr_
[i
] =0;
133 span_stop_moments_
[i
] += tsd
;
136 if (now
>= stop_moments_
[i
])
138 started_span_p_arr_
.del (i
);
139 stop_moments_
.del(i
);
140 span_stop_moments_
.del (i
);
141 time_scaled_music_arr_
.del(i
);
147 Tuplet_engraver::do_removal_processing ()
149 for (int i
=0; i
< started_span_p_arr_
.size (); i
++)
151 if (started_span_p_arr_
[i
])
152 typeset_element (started_span_p_arr_
[i
]);
156 ADD_THIS_TRANSLATOR(Tuplet_engraver
);