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 class Tie_engraver : public Engraver
35 Link_array<Grob> now_heads_;
36 Link_array<Grob> heads_to_tie_;
37 Link_array<Grob> ties_;
39 Spanner * tie_column_;
42 virtual void stop_translation_timestep ();
43 virtual void start_translation_timestep ();
44 virtual void acknowledge_grob (Grob_info);
45 virtual bool try_music (Music*);
46 virtual void process_music ();
47 void typeset_tie (Grob*);
49 TRANSLATOR_DECLARATIONS (Tie_engraver);
54 Tie_engraver::Tie_engraver ()
63 Tie_engraver::try_music (Music *mus)
65 if (mus->is_mus_type ("tie-event"))
74 Tie_engraver::process_music ()
77 context ()->set_property ("tieMelismaBusy", SCM_BOOL_T);
81 Tie_engraver::acknowledge_grob (Grob_info i)
83 if (Note_head::has_interface (i.grob_))
87 for (int i = heads_to_tie_.size (); i--;)
89 Grob *th = heads_to_tie_[i];
90 Music * right_mus = unsmob_music (h->get_property ("cause"));
91 Music * left_mus = unsmob_music (th->get_property ("cause"));
94 maybe should check positions too.
96 if (right_mus && left_mus
97 && ly_c_equal_p (right_mus->get_property ("pitch"),
98 left_mus->get_property ("pitch")))
100 Grob * p = make_spanner ("Tie", last_event_->self_scm ());
101 Tie::set_interface (p); // cannot remove yet!
103 Tie::set_head (p, LEFT, th);
104 Tie::set_head (p, RIGHT, h);
110 if (ties_.size () && ! tie_column_)
112 tie_column_ = make_spanner ("TieColumn", SCM_EOL);
117 for (int i = ties_.size (); i--;)
118 Tie_column::add_tie (tie_column_,ties_ [i]);
123 Tie_engraver::start_translation_timestep ()
125 context ()->set_property ("tieMelismaBusy",
126 ly_bool2scm (heads_to_tie_.size ()));
131 Tie_engraver::stop_translation_timestep ()
135 heads_to_tie_.clear ();
136 for (int i=0; i< ties_.size (); i++)
138 typeset_tie (ties_[i]);
145 typeset_grob (tie_column_);
152 heads_to_tie_ = now_heads_;
153 last_event_ = event_;
160 Tie_engraver::typeset_tie (Grob *her)
162 if (! (Tie::head (her,LEFT) && Tie::head (her,RIGHT)))
163 warning (_ ("lonely tie"));
166 Drul_array<Grob *> new_head_drul;
167 new_head_drul[LEFT] = Tie::head (her,LEFT);
168 new_head_drul[RIGHT] = Tie::head (her,RIGHT);
170 if (!Tie::head (her,d))
171 new_head_drul[d] = Tie::head (her, (Direction)-d);
172 } while (flip (&d) != LEFT);
174 index_set_cell (her->get_property ("head-pair"), LEFT, new_head_drul[LEFT]->self_scm ());
175 index_set_cell (her->get_property ("head-pair"), RIGHT, new_head_drul[RIGHT]->self_scm ());
181 ENTER_DESCRIPTION (Tie_engraver,
182 /* descr */ "Generate ties between noteheads of equal pitch.",
183 /* creats*/ "Tie TieColumn",
184 /* accepts */ "tie-event",
185 /* acks */ "rhythmic-head-interface",
186 /* reads */ "tieMelismaBusy",