2 slur-engraver.cc -- implement Slur_engraver
4 (c) 1997--2001 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 create_grobs ();
34 VIRTUAL_COPY_CONS (Translator
);
38 Slur_engraver::Slur_engraver ()
40 last_start_
= Moment (-1);
44 Slur_engraver::try_music (Music
*req_l
)
46 if (Span_req
*sl
= dynamic_cast <Span_req
*> (req_l
))
48 String t
= ly_scm2string (sl
->get_mus_property ("span-type"));
51 for (int i
= 0; i
< slur_l_stack_
.size (); i
++)
53 slur_l_stack_
[i
]->suicide ();
55 slur_l_stack_
.clear ();
56 for (int i
= 0; i
< end_slur_l_arr_
.size (); i
++)
58 end_slur_l_arr_
[i
]->suicide ();
60 end_slur_l_arr_
.clear ();
61 requests_arr_
.clear ();
62 new_slur_req_l_arr_
.clear ();
67 Let's not start more than one slur per moment.
69 if (sl
->get_span_dir () == START
)
71 if (now_mom () > last_start_
)
73 new_slur_req_l_arr_
.push (sl
);
74 last_start_
= now_mom ();
80 new_slur_req_l_arr_
.push (sl
);
89 Slur_engraver::set_melisma (bool m
)
91 daddy_trans_l_
->set_property ("slurMelismaBusy", m
? SCM_BOOL_T
:SCM_BOOL_F
);
95 Slur_engraver::acknowledge_grob (Grob_info info
)
97 if (Note_column::has_interface (info
.elem_l_
))
99 Grob
*e
=info
.elem_l_
;
100 for (int i
= 0; i
< slur_l_stack_
.size (); i
++)
101 Slur::add_column (slur_l_stack_
[i
], e
);
102 for (int i
= 0; i
< end_slur_l_arr_
.size (); i
++)
103 Slur::add_column (end_slur_l_arr_
[i
], e
);
108 Slur_engraver::finalize ()
110 for (int i
= 0; i
< slur_l_stack_
.size (); i
++)
113 typeset_grob (slur_l_stack_
[i
]);
116 Let's not typeset unterminated stuff
118 slur_l_stack_
[i
]->suicide ();
121 slur_l_stack_
.clear ();
123 for (int i
=0; i
< requests_arr_
.size (); i
++)
125 requests_arr_
[i
]->origin ()->warning (_ ("unterminated slur"));
130 Slur_engraver::create_grobs ()
132 Link_array
<Grob
> start_slur_l_arr
;
133 for (int i
=0; i
< new_slur_req_l_arr_
.size (); i
++)
135 Span_req
* slur_req_l
= new_slur_req_l_arr_
[i
];
136 // end slur: move the slur to other array
137 if (slur_req_l
->get_span_dir () == STOP
)
139 if (slur_l_stack_
.empty ())
140 /* How to shut up this warning, when Voice_devnull_engraver has
141 eaten start request? */
142 slur_req_l
->origin ()->warning (_f ("can't find start of slur"));
145 Grob
* slur
= slur_l_stack_
.pop ();
146 SCM s
= get_property ("slurEndAttachment");
149 index_set_cell (slur
->get_grob_property ("attachment"), STOP
, s
);
151 end_slur_l_arr_
.push (slur
);
152 requests_arr_
.pop ();
155 else if (slur_req_l
->get_span_dir () == START
)
157 // push a new slur onto stack.
158 // (use temp. array to wait for all slur STOPs)
159 Grob
* slur
= new Spanner (get_property ("Slur"));
160 Slur::set_interface (slur
);
161 SCM s
= get_property ("slurBeginAttachment");
164 index_set_cell (slur
->get_grob_property ("attachment"), START
, s
);
166 start_slur_l_arr
.push (slur
);
167 requests_arr_
.push (slur_req_l
);
168 announce_grob (slur
, slur_req_l
);
171 for (int i
=0; i
< start_slur_l_arr
.size (); i
++)
172 slur_l_stack_
.push (start_slur_l_arr
[i
]);
173 new_slur_req_l_arr_
.clear ();
177 Slur_engraver::stop_translation_timestep ()
179 for (int i
= 0; i
< end_slur_l_arr_
.size (); i
++)
181 typeset_grob (end_slur_l_arr_
[i
]);
183 end_slur_l_arr_
.clear ();
187 Slur_engraver::start_translation_timestep ()
189 new_slur_req_l_arr_
.clear ();
190 SCM m
= get_property ("automaticMelismata");
193 set_melisma (slur_l_stack_
.size ());
198 ADD_THIS_TRANSLATOR (Slur_engraver
);