2 new-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>
12 #include "protected-scm.hh"
14 #include "tie-column.hh"
15 #include "engraver.hh"
17 #include "grob-pitch-tuple.hh"
19 #include "note-head.hh"
20 #include "staff-symbol-referencer.hh"
23 Manufacture ties. Acknowledge noteheads, and put them into a
24 priority queue. If we have a TieEvent, connect the notes that finish
25 just at this time, and note that start at this time.
27 TODO: Remove the dependency on musical info. We should tie on the
28 basis of position and duration-log of the heads (not of the events).
31 struct Head_event_tuple
39 Head_event_tuple(Grob *h, Music *m, SCM def)
43 tie_definition_ = def;
47 class Tie_engraver : public Engraver
50 Link_array<Grob> now_heads_;
51 Array<Head_event_tuple> heads_to_tie_;
52 Link_array<Grob> ties_;
54 Spanner * tie_column_;
57 virtual void stop_translation_timestep ();
58 virtual void derived_mark () const;
59 virtual void start_translation_timestep ();
60 virtual void acknowledge_grob (Grob_info);
61 virtual bool try_music (Music*);
62 virtual void process_music ();
63 void typeset_tie (Grob*);
65 TRANSLATOR_DECLARATIONS (Tie_engraver);
70 Tie_engraver::derived_mark () const
72 Engraver::derived_mark ();
73 for (int i = 0; i < heads_to_tie_.size(); i++)
74 scm_gc_mark (heads_to_tie_[i].tie_definition_);
77 Tie_engraver::Tie_engraver ()
85 Tie_engraver::try_music (Music *mus)
87 if (mus->is_mus_type ("tie-event"))
96 Tie_engraver::process_music ()
100 context ()->set_property ("tieMelismaBusy", SCM_BOOL_T);
105 Tie_engraver::acknowledge_grob (Grob_info i)
107 if (Note_head::has_interface (i.grob_))
111 for (int i = heads_to_tie_.size (); i--;)
113 Grob *th = heads_to_tie_[i].head_;
114 Music * right_mus = unsmob_music (h->get_property ("cause"));
115 Music * left_mus = unsmob_music (th->get_property ("cause"));
118 maybe should check positions too.
120 if (right_mus && left_mus
121 && ly_c_equal_p (right_mus->get_property ("pitch"),
122 left_mus->get_property ("pitch")))
124 Grob * p = new Spanner (heads_to_tie_[i].tie_definition_,
125 context()->get_grob_key ("Tie"));
126 announce_grob (p, heads_to_tie_[i].event_->self_scm ());
127 Tie::set_interface (p); // cannot remove yet!
129 Tie::set_head (p, LEFT, th);
130 Tie::set_head (p, RIGHT, h);
133 heads_to_tie_.del (i);
137 if (ties_.size () && ! tie_column_)
139 tie_column_ = make_spanner ("TieColumn", ties_[0]->self_scm ());
143 for (int i = ties_.size (); i--;)
144 Tie_column::add_tie (tie_column_, ties_[i]);
149 Tie_engraver::start_translation_timestep ()
151 context ()->set_property ("tieMelismaBusy",
152 ly_bool2scm (heads_to_tie_.size ()));
157 Tie_engraver::stop_translation_timestep ()
161 if (!to_boolean (get_property ("tieWaitForNote")))
163 heads_to_tie_.clear ();
166 for (int i = 0; i< ties_.size (); i++)
168 typeset_tie (ties_[i]);
178 = updated_grob_properties (context (), ly_symbol2scm ("Tie"));
180 if (!to_boolean (get_property ("tieWaitForNote")))
181 heads_to_tie_.clear();
183 for (int i = 0; i < now_heads_.size(); i++)
185 heads_to_tie_.push (Head_event_tuple (now_heads_[i], event_,
196 Tie_engraver::typeset_tie (Grob *her)
198 if (! (Tie::head (her, LEFT) && Tie::head (her, RIGHT)))
199 warning (_ ("lonely tie"));
202 Drul_array<Grob *> new_head_drul;
203 new_head_drul[LEFT] = Tie::head (her, LEFT);
204 new_head_drul[RIGHT] = Tie::head (her, RIGHT);
206 if (!Tie::head (her, d))
207 new_head_drul[d] = Tie::head (her, (Direction)-d);
208 } while (flip (&d) != LEFT);
210 index_set_cell (her->get_property ("head-pair"), LEFT, new_head_drul[LEFT]->self_scm ());
211 index_set_cell (her->get_property ("head-pair"), RIGHT, new_head_drul[RIGHT]->self_scm ());
216 ADD_TRANSLATOR (Tie_engraver,
217 /* descr */ "Generate ties between noteheads of equal pitch.",
218 /* creats*/ "Tie TieColumn",
219 /* accepts */ "tie-event",
220 /* acks */ "rhythmic-head-interface",
221 /* reads */ "tieMelismaBusy",