2 slur-engraver.cc -- implement Slur_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
12 #include "directional-element-interface.hh"
13 #include "international.hh"
14 #include "note-column.hh"
17 #include "stream-event.hh"
20 #include "translator.icc"
26 This is largely similar to Phrasing_slur_engraver. Check if fixes
29 (on principle, engravers don't use inheritance for code sharing)
34 It is possible that a slur starts and ends on the same note. At
35 least, it is for phrasing slurs: a note can be both beginning and
38 class Slur_engraver
: public Engraver
40 Drul_array
<Stream_event
*> events_
;
41 Stream_event
*running_slur_start_
;
43 vector
<Grob
*> end_slurs_
;
45 void set_melisma (bool);
48 DECLARE_TRANSLATOR_LISTENER (slur
);
49 DECLARE_ACKNOWLEDGER (accidental
);
50 DECLARE_ACKNOWLEDGER (fingering
);
51 DECLARE_ACKNOWLEDGER (note_column
);
52 DECLARE_ACKNOWLEDGER (script
);
53 DECLARE_ACKNOWLEDGER (text_script
);
54 DECLARE_ACKNOWLEDGER (tie
);
55 DECLARE_ACKNOWLEDGER (tuplet_number
);
57 void acknowledge_extra_object (Grob_info
);
58 void stop_translation_timestep ();
59 void process_music ();
61 virtual void finalize ();
65 TRANSLATOR_DECLARATIONS (Slur_engraver
);
68 Slur_engraver::Slur_engraver ()
70 events_
[START
] = events_
[STOP
] = 0;
73 IMPLEMENT_TRANSLATOR_LISTENER (Slur_engraver
, slur
);
75 Slur_engraver::listen_slur (Stream_event
*ev
)
77 Direction d
= to_dir (ev
->get_property ("span-direction"));
79 ASSIGN_EVENT_ONCE (events_
[START
], ev
);
81 ASSIGN_EVENT_ONCE (events_
[STOP
], ev
);
82 else ev
->origin ()->warning (_f ("direction of %s invalid: %d",
83 "slur-event", int (d
)));
87 Slur_engraver::set_melisma (bool m
)
89 context ()->set_property ("slurMelismaBusy", m
? SCM_BOOL_T
: SCM_BOOL_F
);
93 Slur_engraver::acknowledge_note_column (Grob_info info
)
95 Grob
*e
= info
.grob ();
96 for (vsize i
= slurs_
.size (); i
--;)
97 Slur::add_column (slurs_
[i
], e
);
98 for (vsize i
= end_slurs_
.size (); i
--;)
99 Slur::add_column (end_slurs_
[i
], e
);
103 Slur_engraver::acknowledge_extra_object (Grob_info info
)
105 Slur::auxiliary_acknowledge_extra_object (info
, slurs_
, end_slurs_
);
109 Slur_engraver::acknowledge_accidental (Grob_info info
)
111 acknowledge_extra_object (info
);
115 Slur_engraver::acknowledge_fingering (Grob_info info
)
117 acknowledge_extra_object (info
);
121 Slur_engraver::acknowledge_tuplet_number (Grob_info info
)
123 acknowledge_extra_object (info
);
128 Slur_engraver::acknowledge_script (Grob_info info
)
130 if (!info
.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface")))
131 acknowledge_extra_object (info
);
135 Slur_engraver::acknowledge_text_script (Grob_info info
)
137 acknowledge_extra_object (info
);
141 Slur_engraver::acknowledge_tie (Grob_info info
)
143 acknowledge_extra_object (info
);
147 Slur_engraver::finalize ()
151 slurs_
[0]->warning (_ ("unterminated slur"));
152 for (vsize i
= 0; i
< slurs_
.size (); i
++)
153 slurs_
[i
]->suicide ();
158 Slur_engraver::process_music ()
162 if (slurs_
.size () == 0)
163 events_
[STOP
]->origin ()->warning (_ ("cannot end slur"));
170 if (events_
[START
] && slurs_
.empty ())
172 Stream_event
*ev
= events_
[START
];
174 bool double_slurs
= to_boolean (get_property ("doubleSlurs"));
176 Grob
*slur
= make_spanner ("Slur", events_
[START
]->self_scm ());
177 Direction updown
= to_dir (ev
->get_property ("direction"));
178 if (updown
&& !double_slurs
)
179 set_grob_direction (slur
, updown
);
181 slurs_
.push_back (slur
);
185 set_grob_direction (slur
, DOWN
);
186 slur
= make_spanner ("Slur", events_
[START
]->self_scm ());
187 set_grob_direction (slur
, UP
);
188 slurs_
.push_back (slur
);
191 set_melisma (slurs_
.size ());
195 Slur_engraver::stop_translation_timestep ()
197 if (Grob
*g
= unsmob_grob (get_property ("currentCommandColumn")))
199 for (vsize i
= 0; i
< end_slurs_
.size (); i
++)
200 Slur::add_extra_encompass (end_slurs_
[i
], g
);
203 for (vsize i
= 0; i
< slurs_
.size (); i
++)
204 Slur::add_extra_encompass (slurs_
[i
], g
);
208 for (vsize i
= 0; i
< end_slurs_
.size (); i
++)
210 Spanner
* s
= dynamic_cast<Spanner
*> (end_slurs_
[i
]);
211 if (!s
->get_bound (RIGHT
))
212 s
->set_bound (RIGHT
, unsmob_grob (get_property ("currentMusicalColumn")));
213 announce_end_grob (s
, SCM_EOL
);
216 events_
[START
] = events_
[STOP
] = 0;
219 ADD_ACKNOWLEDGER (Slur_engraver
, accidental
);
220 ADD_ACKNOWLEDGER (Slur_engraver
, fingering
);
221 ADD_ACKNOWLEDGER (Slur_engraver
, note_column
);
222 ADD_ACKNOWLEDGER (Slur_engraver
, script
);
223 ADD_ACKNOWLEDGER (Slur_engraver
, text_script
);
224 ADD_ACKNOWLEDGER (Slur_engraver
, tie
);
225 ADD_ACKNOWLEDGER (Slur_engraver
, tuplet_number
);
226 ADD_TRANSLATOR (Slur_engraver
,
227 /* doc */ "Build slur grobs from slur events",