2 tie-engraver.cc -- implement Tie_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "protected-scm.hh"
13 #include "tie-column.hh"
14 #include "engraver.hh"
16 #include "grob-pitch-tuple.hh"
18 #include "note-head.hh"
19 #include "staff-symbol-referencer.hh"
22 Manufacture ties. Acknowledge noteheads, and put them into a
23 priority queue. If we have a TieEvent, connect the notes that finish
24 just at this time, and note that start at this time.
26 TODO: Remove the dependency on musical info. We should tie on the
27 basis of position and duration-log of the heads (not of the events).
30 struct Head_event_tuple
38 Head_event_tuple (Grob *h, Music *m, SCM def)
42 tie_definition_ = def;
46 class Tie_engraver : public Engraver
49 Link_array<Grob> now_heads_;
50 Array<Head_event_tuple> heads_to_tie_;
51 Link_array<Grob> ties_;
56 void stop_translation_timestep ();
57 virtual void derived_mark () const;
58 void start_translation_timestep ();
59 DECLARE_ACKNOWLEDGER (note_head);
60 virtual bool try_music (Music *);
61 void process_music ();
62 void typeset_tie (Grob *);
64 TRANSLATOR_DECLARATIONS (Tie_engraver);
68 Tie_engraver::derived_mark () const
70 Engraver::derived_mark ();
71 for (int i = 0; i < heads_to_tie_.size (); i++)
72 scm_gc_mark (heads_to_tie_[i].tie_definition_);
75 Tie_engraver::Tie_engraver ()
82 Tie_engraver::try_music (Music *mus)
84 if (mus->is_mus_type ("tie-event"))
93 Tie_engraver::process_music ()
97 context ()->set_property ("tieMelismaBusy", SCM_BOOL_T);
102 Tie_engraver::acknowledge_note_head (Grob_info i)
106 for (int i = heads_to_tie_.size (); i--;)
108 Grob *th = heads_to_tie_[i].head_;
109 Music *right_mus = unsmob_music (h->get_property ("cause"));
110 Music *left_mus = unsmob_music (th->get_property ("cause"));
113 maybe should check positions too.
115 if (right_mus && left_mus
116 && ly_is_equal (right_mus->get_property ("pitch"),
117 left_mus->get_property ("pitch")))
119 Grob *p = new Spanner (heads_to_tie_[i].tie_definition_,
120 context ()->get_grob_key ("Tie"));
121 announce_grob (p, heads_to_tie_[i].event_->self_scm ());
122 Tie::set_interface (p); // cannot remove yet!
124 Tie::set_head (p, LEFT, th);
125 Tie::set_head (p, RIGHT, h);
128 heads_to_tie_.del (i);
132 if (ties_.size () && ! tie_column_)
134 tie_column_ = make_spanner ("TieColumn", ties_[0]->self_scm ());
138 for (int i = ties_.size (); i--;)
139 Tie_column::add_tie (tie_column_, ties_[i]);
143 Tie_engraver::start_translation_timestep ()
145 context ()->set_property ("tieMelismaBusy",
146 ly_bool2scm (heads_to_tie_.size ()));
150 Tie_engraver::stop_translation_timestep ()
154 if (!to_boolean (get_property ("tieWaitForNote")))
156 heads_to_tie_.clear ();
159 for (int i = 0; i < ties_.size (); i++)
161 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 (int i = 0; i < now_heads_.size (); i++)
178 heads_to_tie_.push (Head_event_tuple (now_heads_[i], event_,
188 Tie_engraver::typeset_tie (Grob *her)
190 if (! (Tie::head (her, LEFT) && Tie::head (her, RIGHT)))
191 warning (_ ("lonely tie"));
194 Drul_array<Grob *> new_head_drul;
195 new_head_drul[LEFT] = Tie::head (her, LEFT);
196 new_head_drul[RIGHT] = Tie::head (her, RIGHT);
199 if (!Tie::head (her, d))
200 new_head_drul[d] = Tie::head (her, (Direction) - d);
202 while (flip (&d) != LEFT);
204 index_set_cell (her->get_property ("head-pair"), LEFT, new_head_drul[LEFT]->self_scm ());
205 index_set_cell (her->get_property ("head-pair"), RIGHT, new_head_drul[RIGHT]->self_scm ());
208 #include "translator.icc"
209 ADD_ACKNOWLEDGER (Tie_engraver, note_head);
210 ADD_TRANSLATOR (Tie_engraver,
211 /* descr */ "Generate ties between noteheads of equal pitch.",
212 /* creats*/ "Tie TieColumn",
213 /* accepts */ "tie-event",
214 /* reads */ "tieMelismaBusy",