2 slur-engraver.cc -- implement Slur_engraver
4 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 #include "musical-request.hh"
10 #include "note-column.hh"
11 #include "translator-group.hh"
12 #include "engraver.hh"
15 class Slur_engraver
: public Engraver
17 Link_array
<Span_req
> requests_arr_
;
18 Link_array
<Span_req
> new_slur_req_l_arr_
;
19 Link_array
<Grob
> slur_l_stack_
;
20 Link_array
<Grob
> end_slur_l_arr_
;
23 void set_melisma (bool);
26 virtual bool try_music (Music
*);
27 virtual void acknowledge_grob (Grob_info
);
28 virtual void stop_translation_timestep ();
29 virtual void start_translation_timestep ();
30 virtual void finalize ();
31 virtual void process_acknowledged_grobs ();
34 TRANSLATOR_DECLARATIONS (Slur_engraver
);
37 Slur_engraver::Slur_engraver ()
39 last_start_
= Moment (-1);
43 Slur_engraver::try_music (Music
*req_l
)
45 if (Span_req
*sl
= dynamic_cast <Span_req
*> (req_l
))
47 String t
= ly_scm2string (sl
->get_mus_property ("span-type"));
50 for (int i
= 0; i
< slur_l_stack_
.size (); i
++)
52 slur_l_stack_
[i
]->suicide ();
54 slur_l_stack_
.clear ();
55 for (int i
= 0; i
< end_slur_l_arr_
.size (); i
++)
57 end_slur_l_arr_
[i
]->suicide ();
59 end_slur_l_arr_
.clear ();
60 requests_arr_
.clear ();
61 new_slur_req_l_arr_
.clear ();
66 Let's not start more than one slur per moment.
68 if (sl
->get_span_dir () == START
)
70 if (now_mom () > last_start_
)
72 new_slur_req_l_arr_
.push (sl
);
73 last_start_
= now_mom ();
79 new_slur_req_l_arr_
.push (sl
);
88 Slur_engraver::set_melisma (bool m
)
90 daddy_trans_l_
->set_property ("slurMelismaBusy", m
? SCM_BOOL_T
:SCM_BOOL_F
);
94 Slur_engraver::acknowledge_grob (Grob_info info
)
96 if (Note_column::has_interface (info
.grob_l_
))
98 Grob
*e
=info
.grob_l_
;
99 for (int i
= 0; i
< slur_l_stack_
.size (); i
++)
100 Slur::add_column (slur_l_stack_
[i
], e
);
101 for (int i
= 0; i
< end_slur_l_arr_
.size (); i
++)
102 Slur::add_column (end_slur_l_arr_
[i
], e
);
107 Slur_engraver::finalize ()
109 for (int i
= 0; i
< slur_l_stack_
.size (); i
++)
112 typeset_grob (slur_l_stack_
[i
]);
115 Let's not typeset unterminated stuff
117 slur_l_stack_
[i
]->suicide ();
120 slur_l_stack_
.clear ();
122 for (int i
=0; i
< requests_arr_
.size (); i
++)
124 requests_arr_
[i
]->origin ()->warning (_ ("unterminated slur"));
129 Slur_engraver::process_acknowledged_grobs ()
131 Link_array
<Grob
> start_slur_l_arr
;
132 for (int i
=0; i
< new_slur_req_l_arr_
.size (); i
++)
134 Span_req
* slur_req_l
= new_slur_req_l_arr_
[i
];
135 // end slur: move the slur to other array
136 if (slur_req_l
->get_span_dir () == STOP
)
138 if (slur_l_stack_
.empty ())
139 /* How to shut up this warning, when Voice_devnull_engraver has
140 eaten start request? */
141 slur_req_l
->origin ()->warning (_f ("can't find start of slur"));
144 Grob
* slur
= slur_l_stack_
.pop ();
146 end_slur_l_arr_
.push (slur
);
147 requests_arr_
.pop ();
150 else if (slur_req_l
->get_span_dir () == START
)
152 // push a new slur onto stack.
153 // (use temp. array to wait for all slur STOPs)
154 Grob
* slur
= new Spanner (get_property ("Slur"));
155 Slur::set_interface (slur
); // cannot remove yet!
156 start_slur_l_arr
.push (slur
);
157 requests_arr_
.push (slur_req_l
);
158 announce_grob (slur
, slur_req_l
->self_scm ());
161 for (int i
=0; i
< start_slur_l_arr
.size (); i
++)
162 slur_l_stack_
.push (start_slur_l_arr
[i
]);
163 new_slur_req_l_arr_
.clear ();
167 Slur_engraver::stop_translation_timestep ()
169 for (int i
= 0; i
< end_slur_l_arr_
.size (); i
++)
171 typeset_grob (end_slur_l_arr_
[i
]);
173 end_slur_l_arr_
.clear ();
177 Slur_engraver::start_translation_timestep ()
179 new_slur_req_l_arr_
.clear ();
180 SCM m
= get_property ("automaticMelismata");
183 set_melisma (slur_l_stack_
.size ());
189 ENTER_DESCRIPTION (Slur_engraver
,
190 /* descr */ "Build slurs from Slur_reqs",
192 /* acks */ "note-column-interface",
193 /* reads */ "slurMelismaBusy",