2 ligature-engraver.cc -- implement Ligature_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2002--2003 Juergen Reuter <reuter@ipd.uka.de>
9 #include "ligature-engraver.hh"
10 #include "ligature-head.hh"
12 #include "score-engraver.hh"
13 #include "note-head.hh"
18 * TODO: lyrics/melisma/syllables: there should be at most one
19 * syllable of lyrics per ligature (i.e. for the lyrics context, a
20 * ligature should count as a single note, regardless of how many
21 * heads the ligature consists of).
23 * TODO: currently, you have to add/remove the proper
24 * Ligature_engraver (Ligature_bracket_engraver,
25 * Mensural_ligature_engraver) to the proper translator
26 * (e.g. VoiceContext) to choose between various representations.
27 * Since adding/removing an engraver to a translator is a global
28 * action in the paper block, you can not mix various representations
29 * _within_ the same score. Hence, for selecting a representation,
30 * one would rather like to have a property that can be set e.g. for
31 * several staves individually. However, it seems that this approach
32 * would require to have a single, complicated Ligature_engraver that
33 * consists of all the code... This needs further thoughts.
35 Ligature_engraver::Ligature_engraver ()
38 finished_ligature_ = 0;
39 reqs_drul_[LEFT] = reqs_drul_[RIGHT] = 0;
42 brew_ligature_primitive_proc = SCM_EOL;
46 Ligature_engraver::try_music (Music *m)
48 if (m->is_mus_type ("abort-event"))
50 reqs_drul_[START] = 0;
53 ligature_->suicide ();
56 else if (m->is_mus_type ("ligature-event"))
58 Direction d = to_dir (m->get_mus_property ("span-direction"));
66 Ligature_engraver::create_ligature_spanner ()
68 programming_error ("Ligature_engraver::create_ligature_spanner (): "
69 "this is an abstract method that should not be called, "
70 "but overridden by a subclass");
75 Ligature_engraver::process_music ()
80 reqs_drul_[STOP]->origin ()->warning (_ ("can't find start of ligature"));
85 reqs_drul_[STOP]->origin ()->warning (_ ("no right bound"));
89 ligature_->set_bound (RIGHT, last_bound_);
93 finished_primitives_ = primitives_;
94 finished_ligature_ = ligature_;
98 last_bound_ = unsmob_grob (get_property ("currentMusicalColumn"));
102 // TODO: maybe forbid breaks only if not transcribing
103 top_engraver ()->forbid_breaks ();
105 if (reqs_drul_[START])
109 reqs_drul_[START]->origin ()->warning (_ ("already have a ligature"));
113 prev_start_req_ = reqs_drul_[START];
114 ligature_ = create_ligature_spanner ();
115 brew_ligature_primitive_proc =
116 ligature_->get_grob_property ("ligature-primitive-callback");
117 if (brew_ligature_primitive_proc == SCM_EOL)
119 warning ("Ligature_engraver: ligature-primitive-callback undefined");
122 Grob *bound = unsmob_grob (get_property ("currentMusicalColumn"));
125 reqs_drul_[START]->origin ()->warning (_ ("no left bound"));
129 ligature_->set_bound (LEFT, bound);
132 ligature_start_mom_ = now_mom ();
134 announce_grob(ligature_, reqs_drul_[START]->self_scm());
139 Ligature_engraver::start_translation_timestep ()
141 reqs_drul_[START] = 0;
142 reqs_drul_[STOP] = 0;
146 Ligature_engraver::typeset_ligature (Spanner *, Array<Grob_info>)
148 programming_error ("Ligature_engraver::typeset_ligature (): "
149 "this is an abstract method that should not be called, "
150 "but overridden by a subclass");
154 Ligature_engraver::stop_translation_timestep ()
156 if (finished_ligature_)
158 typeset_ligature (finished_ligature_, finished_primitives_);
159 finished_primitives_.clear ();
160 finished_ligature_ = 0;
165 Ligature_engraver::finalize ()
167 if (finished_ligature_)
169 typeset_ligature (finished_ligature_, finished_primitives_);
170 finished_primitives_.clear ();
171 finished_ligature_ = 0;
175 prev_start_req_->origin ()->warning (_ ("unterminated ligature"));
176 ligature_->suicide ();
181 Ligature_engraver::current_ligature ()
187 Ligature_engraver::acknowledge_grob (Grob_info info)
191 if (Note_head::has_interface (info.grob_))
193 primitives_.push (info);
195 if (Ligature_head::has_interface (info.grob_))
197 info.grob_->set_grob_property ("ligature-primitive-callback",
198 brew_ligature_primitive_proc);
200 else if (Rest::has_interface (info.grob_))
202 info.music_cause ()->origin ()->warning (_ ("ligature may not contain rest; ignoring rest"));
203 prev_start_req_->origin ()->warning (_ ("ligature was started here"));
204 // TODO: maybe better should stop ligature here rather than
205 // ignoring the rest?
210 ENTER_DESCRIPTION (Ligature_engraver,
211 /* descr */ "Abstract class; a concrete subclass handles Ligature_events by engraving Ligatures in a concrete style.",
213 /* accepts */ "ligature-event abort-event",
214 /* acks */ "ligature-head-interface rest-interface",