2 new-tie-engraver.cc -- implement Tie_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
15 #include "tie-column.hh"
16 #include "engraver.hh"
18 #include "grob-pitch-tuple.hh"
20 #include "note-head.hh"
21 #include "staff-symbol-referencer.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).
31 TODO: support sparseTies.
33 class Tie_engraver : public Engraver
37 Link_array<Grob> now_heads_;
38 Link_array<Grob> heads_to_tie_;
39 Link_array<Grob> ties_;
41 Spanner * tie_column_;
44 virtual void stop_translation_timestep ();
45 virtual void start_translation_timestep ();
46 virtual void acknowledge_grob (Grob_info);
47 virtual bool try_music (Music*);
48 virtual void process_music ();
49 void typeset_tie (Grob*);
51 TRANSLATOR_DECLARATIONS(Tie_engraver);
56 Tie_engraver::Tie_engraver ()
65 Tie_engraver::try_music (Music *mus)
67 if (mus->is_mus_type ("tie-event"))
76 Tie_engraver::process_music ()
79 daddy_context_->set_property ("tieMelismaBusy", SCM_BOOL_T);
83 Tie_engraver::acknowledge_grob (Grob_info i)
85 if (Note_head::has_interface (i.grob_))
89 for (int i = heads_to_tie_.size (); i--;)
91 Grob *th = heads_to_tie_[i];
92 Music * right_mus = unsmob_music (h->get_property ("cause"));
93 Music * left_mus = unsmob_music (th->get_property ("cause"));
96 maybe should check positions too.
98 if (right_mus && left_mus
99 && gh_equal_p (right_mus->get_property ("pitch"),
100 left_mus->get_property ("pitch")))
102 Grob * p = make_spanner ("Tie");
103 Tie::set_interface (p); // cannot remove yet!
105 Tie::set_head (p, LEFT, th);
106 Tie::set_head (p, RIGHT, h);
109 announce_grob(p, last_event_->self_scm());
113 if (ties_.size () && ! tie_column_)
115 tie_column_ = make_spanner ("TieColumn");
116 announce_grob(tie_column_, SCM_EOL);
120 for (int i = ties_.size (); i--;)
121 Tie_column::add_tie (tie_column_,ties_ [i]);
126 Tie_engraver::start_translation_timestep ()
128 daddy_context_->set_property ("tieMelismaBusy",
129 gh_bool2scm (heads_to_tie_.size ()));
134 Tie_engraver::stop_translation_timestep ()
138 heads_to_tie_.clear ();
139 for (int i=0; i< ties_.size (); i++)
141 typeset_tie (ties_[i]);
148 typeset_grob (tie_column_);
155 heads_to_tie_ = now_heads_;
156 last_event_ = event_;
163 Tie_engraver::typeset_tie (Grob *her)
165 if (! (Tie::head (her,LEFT) && Tie::head (her,RIGHT)))
166 warning (_ ("lonely tie"));
169 Drul_array<Grob *> new_head_drul;
170 new_head_drul[LEFT] = Tie::head (her,LEFT);
171 new_head_drul[RIGHT] = Tie::head (her,RIGHT);
173 if (!Tie::head (her,d))
174 new_head_drul[d] = Tie::head (her, (Direction)-d);
175 } while (flip (&d) != LEFT);
177 index_set_cell (her->get_property ("head-pair"), LEFT, new_head_drul[LEFT]->self_scm ());
178 index_set_cell (her->get_property ("head-pair"), RIGHT, new_head_drul[RIGHT]->self_scm ());
184 ENTER_DESCRIPTION(Tie_engraver,
185 /* descr */ "Generate ties between noteheads of equal pitch.",
186 /* creats*/ "Tie TieColumn",
187 /* accepts */ "tie-event",
188 /* acks */ "rhythmic-head-interface",
189 /* reads */ "tieMelismaBusy",