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
43 tie_definition_ = SCM_EOL;
47 class Tie_engraver : public Engraver
50 vector<Grob*> now_heads_;
51 vector<Head_event_tuple> heads_to_tie_;
57 void stop_translation_timestep ();
58 virtual void derived_mark () const;
59 void start_translation_timestep ();
60 DECLARE_ACKNOWLEDGER (note_head);
61 virtual bool try_music (Music *);
62 void process_music ();
63 void typeset_tie (Grob *);
65 TRANSLATOR_DECLARATIONS (Tie_engraver);
69 Tie_engraver::derived_mark () const
71 Engraver::derived_mark ();
72 for (vsize i = 0; i < heads_to_tie_.size (); i++)
73 scm_gc_mark (heads_to_tie_[i].tie_definition_);
76 Tie_engraver::Tie_engraver ()
83 Tie_engraver::try_music (Music *mus)
85 if (mus->is_mus_type ("tie-event"))
92 Tie_engraver::process_music ()
95 context ()->set_property ("tieMelismaBusy", SCM_BOOL_T);
99 Tie_engraver::acknowledge_note_head (Grob_info i)
102 now_heads_.push_back (h);
103 for (vsize i = heads_to_tie_.size (); i--;)
105 Grob *th = heads_to_tie_[i].head_;
106 Music *right_mus = unsmob_music (h->get_property ("cause"));
107 Music *left_mus = unsmob_music (th->get_property ("cause"));
110 maybe should check positions too.
112 if (right_mus && left_mus
113 && ly_is_equal (right_mus->get_property ("pitch"),
114 left_mus->get_property ("pitch")))
116 Grob *p = new Spanner (heads_to_tie_[i].tie_definition_,
117 context ()->get_grob_key ("Tie"));
118 announce_grob (p, heads_to_tie_[i].event_->self_scm ());
119 Tie::set_head (p, LEFT, th);
120 Tie::set_head (p, RIGHT, h);
123 heads_to_tie_.erase (heads_to_tie_.begin () + i);
127 if (ties_.size () && ! tie_column_)
128 tie_column_ = make_spanner ("TieColumn", ties_[0]->self_scm ());
131 for (vsize i = ties_.size (); i--;)
132 Tie_column::add_tie (tie_column_, ties_[i]);
136 Tie_engraver::start_translation_timestep ()
138 context ()->set_property ("tieMelismaBusy",
139 ly_bool2scm (heads_to_tie_.size ()));
142 if (!to_boolean (get_property ("tieWaitForNote")))
144 Moment now = now_mom ();
145 for (vsize i = heads_to_tie_.size (); i--; )
147 if (now > heads_to_tie_[i].end_moment_)
148 heads_to_tie_.erase (heads_to_tie_.begin () + i);
154 Tie_engraver::stop_translation_timestep ()
158 if (!to_boolean (get_property ("tieWaitForNote")))
159 heads_to_tie_.clear ();
161 for (vsize i = 0; i < ties_.size (); i++)
162 typeset_tie (ties_[i]);
171 = updated_grob_properties (context (), ly_symbol2scm ("Tie"));
173 if (!to_boolean (get_property ("tieWaitForNote")))
174 heads_to_tie_.clear ();
176 for (vsize i = 0; i < now_heads_.size (); i++)
178 Grob *head = now_heads_[i];
179 Music *left_mus = unsmob_music (head->get_property ("cause"));
182 Head_event_tuple event_tup;
184 event_tup.head_ = head;
185 event_tup.tie_definition_ = start_definition;
186 event_tup.event_ = event_;
188 Moment end = now_mom ();
191 end.grace_part_ += left_mus->get_length ().main_part_;
195 end += left_mus->get_length ();
197 event_tup.end_moment_ = end;
199 heads_to_tie_.push_back (event_tup);
209 Tie_engraver::typeset_tie (Grob *her)
211 if (! (Tie::head (her, LEFT) && Tie::head (her, RIGHT)))
212 warning (_ ("lonely tie"));
215 Drul_array<Grob *> new_head_drul;
216 new_head_drul[LEFT] = Tie::head (her, LEFT);
217 new_head_drul[RIGHT] = Tie::head (her, RIGHT);
220 if (!Tie::head (her, d))
221 new_head_drul[d] = Tie::head (her, (Direction) - d);
223 while (flip (&d) != LEFT);
225 Spanner *sp = dynamic_cast<Spanner*> (her);
226 sp->set_bound (LEFT, new_head_drul[LEFT]);
227 sp->set_bound (RIGHT, new_head_drul[RIGHT]);
230 #include "translator.icc"
232 ADD_ACKNOWLEDGER (Tie_engraver, note_head);
233 ADD_TRANSLATOR (Tie_engraver,
234 /* doc */ "Generate ties between noteheads of equal pitch.",
239 /* accept */ "tie-event",
240 /* read */ "tieWaitForNote",
241 /* write */ "tieMelismaBusy");