2 tie-engraver.cc -- implement Tie_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
12 #include "grob-pitch-tuple.hh"
13 #include "international.hh"
15 #include "note-head.hh"
16 #include "protected-scm.hh"
18 #include "staff-symbol-referencer.hh"
19 #include "tie-column.hh"
24 Manufacture ties. Acknowledge noteheads, and put them into a
25 priority queue. If we have a TieEvent, connect the notes that finish
26 just at this time, and note that start at this time.
28 TODO: Remove the dependency on musical info. We should tie on the
29 basis of position and duration-log of the heads (not of the events).
32 struct Head_event_tuple
40 Head_event_tuple (Grob *h, Music *m, SCM def)
44 tie_definition_ = def;
48 class Tie_engraver : public Engraver
51 vector<Grob*> now_heads_;
52 vector<Head_event_tuple> heads_to_tie_;
58 void stop_translation_timestep ();
59 virtual void derived_mark () const;
60 void start_translation_timestep ();
61 DECLARE_ACKNOWLEDGER (note_head);
62 virtual bool try_music (Music *);
63 void process_music ();
64 void typeset_tie (Grob *);
66 TRANSLATOR_DECLARATIONS (Tie_engraver);
70 Tie_engraver::derived_mark () const
72 Engraver::derived_mark ();
73 for (vsize i = 0; i < heads_to_tie_.size (); i++)
74 scm_gc_mark (heads_to_tie_[i].tie_definition_);
77 Tie_engraver::Tie_engraver ()
84 Tie_engraver::try_music (Music *mus)
86 if (mus->is_mus_type ("tie-event"))
93 Tie_engraver::process_music ()
96 context ()->set_property ("tieMelismaBusy", SCM_BOOL_T);
100 Tie_engraver::acknowledge_note_head (Grob_info i)
103 now_heads_.push_back (h);
104 for (vsize i = heads_to_tie_.size (); i--;)
106 Grob *th = heads_to_tie_[i].head_;
107 Music *right_mus = unsmob_music (h->get_property ("cause"));
108 Music *left_mus = unsmob_music (th->get_property ("cause"));
111 maybe should check positions too.
113 if (right_mus && left_mus
114 && ly_is_equal (right_mus->get_property ("pitch"),
115 left_mus->get_property ("pitch")))
117 Grob *p = new Spanner (heads_to_tie_[i].tie_definition_,
118 context ()->get_grob_key ("Tie"));
119 announce_grob (p, heads_to_tie_[i].event_->self_scm ());
120 Tie::set_head (p, LEFT, th);
121 Tie::set_head (p, RIGHT, h);
124 heads_to_tie_.erase (heads_to_tie_.begin () + i);
128 if (ties_.size () && ! tie_column_)
129 tie_column_ = make_spanner ("TieColumn", ties_[0]->self_scm ());
132 for (vsize i = ties_.size (); i--;)
133 Tie_column::add_tie (tie_column_, ties_[i]);
137 Tie_engraver::start_translation_timestep ()
139 context ()->set_property ("tieMelismaBusy",
140 ly_bool2scm (heads_to_tie_.size ()));
144 Tie_engraver::stop_translation_timestep ()
148 if (!to_boolean (get_property ("tieWaitForNote")))
149 heads_to_tie_.clear ();
151 for (vsize i = 0; i < ties_.size (); i++)
152 typeset_tie (ties_[i]);
161 = updated_grob_properties (context (), ly_symbol2scm ("Tie"));
163 if (!to_boolean (get_property ("tieWaitForNote")))
164 heads_to_tie_.clear ();
166 for (vsize i = 0; i < now_heads_.size (); i++)
168 heads_to_tie_.push_back (Head_event_tuple (now_heads_[i], event_,
178 Tie_engraver::typeset_tie (Grob *her)
180 if (! (Tie::head (her, LEFT) && Tie::head (her, RIGHT)))
181 warning (_ ("lonely tie"));
184 Drul_array<Grob *> new_head_drul;
185 new_head_drul[LEFT] = Tie::head (her, LEFT);
186 new_head_drul[RIGHT] = Tie::head (her, RIGHT);
189 if (!Tie::head (her, d))
190 new_head_drul[d] = Tie::head (her, (Direction) - d);
192 while (flip (&d) != LEFT);
194 Spanner *sp = dynamic_cast<Spanner*> (her);
195 sp->set_bound (LEFT, new_head_drul[LEFT]);
196 sp->set_bound (RIGHT, new_head_drul[RIGHT]);
199 #include "translator.icc"
201 ADD_ACKNOWLEDGER (Tie_engraver, note_head);
202 ADD_TRANSLATOR (Tie_engraver,
203 /* doc */ "Generate ties between noteheads of equal pitch.",
208 /* accept */ "tie-event",
209 /* read */ "tieWaitForNote",
210 /* write */ "tieMelismaBusy");