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>
12 #include "translator-group.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).
30 TODO: support sparseTies.
32 TODO: melismata will fuck up now:
37 melisma is after the 2nd 8th note, but will now be signaled as
38 lasting till the 3rd 16th.
40 class Tie_engraver : public Engraver
44 Link_array<Grob> now_heads_;
45 Link_array<Grob> heads_to_tie_;
46 Link_array<Grob> ties_;
48 Spanner * tie_column_;
51 virtual void stop_translation_timestep ();
52 virtual void start_translation_timestep ();
53 virtual void acknowledge_grob (Grob_info);
54 virtual bool try_music (Music*);
55 virtual void process_music ();
56 void typeset_tie (Grob*);
58 TRANSLATOR_DECLARATIONS(Tie_engraver);
63 Tie_engraver::Tie_engraver ()
72 Tie_engraver::try_music (Music *mus)
74 if (mus->is_mus_type ("tie-event"))
83 Tie_engraver::process_music ()
86 daddy_trans_->set_property ("tieMelismaBusy", SCM_BOOL_T);
90 Tie_engraver::acknowledge_grob (Grob_info i)
92 if (Note_head::has_interface (i.grob_))
96 for (int i = heads_to_tie_.size (); i--;)
98 Grob *th = heads_to_tie_[i];
99 Music * right_mus = unsmob_music (h->get_grob_property ("cause"));
100 Music * left_mus = unsmob_music (th->get_grob_property ("cause"));
103 maybe should check positions too.
105 if (right_mus && left_mus
106 && gh_equal_p (right_mus->get_mus_property ("pitch"),
107 left_mus->get_mus_property ("pitch")))
109 Grob * p = make_spanner ("Tie");
110 Tie::set_interface (p); // cannot remove yet!
112 Tie::set_head (p, LEFT, th);
113 Tie::set_head (p, RIGHT, h);
116 announce_grob(p, last_event_->self_scm());
120 if (ties_.size () && ! tie_column_)
122 tie_column_ = make_spanner ("TieColumn");
123 announce_grob(tie_column_, SCM_EOL);
127 for (int i = ties_.size (); i--;)
128 Tie_column::add_tie (tie_column_,ties_ [i]);
133 Tie_engraver::start_translation_timestep ()
135 daddy_trans_->set_property ("tieMelismaBusy",
136 gh_bool2scm (heads_to_tie_.size ()));
141 Tie_engraver::stop_translation_timestep ()
145 heads_to_tie_.clear ();
146 for (int i=0; i< ties_.size (); i++)
148 typeset_tie (ties_[i]);
155 typeset_grob (tie_column_);
162 heads_to_tie_ = now_heads_;
163 last_event_ = event_;
170 Tie_engraver::typeset_tie (Grob *her)
172 if (! (Tie::head (her,LEFT) && Tie::head (her,RIGHT)))
173 warning (_ ("lonely tie"));
176 Drul_array<Grob *> new_head_drul;
177 new_head_drul[LEFT] = Tie::head (her,LEFT);
178 new_head_drul[RIGHT] = Tie::head (her,RIGHT);
180 if (!Tie::head (her,d))
181 new_head_drul[d] = Tie::head (her, (Direction)-d);
182 } while (flip (&d) != LEFT);
184 index_set_cell (her->get_grob_property ("head-pair"), LEFT, new_head_drul[LEFT]->self_scm ());
185 index_set_cell (her->get_grob_property ("head-pair"), RIGHT, new_head_drul[RIGHT]->self_scm ());
191 ENTER_DESCRIPTION(Tie_engraver,
192 /* descr */ "Generate ties between noteheads of equal pitch.",
193 /* creats*/ "Tie TieColumn",
194 /* accepts */ "tie-event",
195 /* acks */ "rhythmic-head-interface",
196 /* reads */ "tieMelismaBusy",