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>
14 #include "protected-scm.hh"
16 #include "tie-column.hh"
17 #include "engraver.hh"
19 #include "grob-pitch-tuple.hh"
21 #include "note-head.hh"
22 #include "staff-symbol-referencer.hh"
25 Manufacture ties. Acknowledge noteheads, and put them into a
26 priority queue. If we have a TieEvent, connect the notes that finish
27 just at this time, and note that start at this time.
29 TODO: Remove the dependency on musical info. We should tie on the
30 basis of position and duration-log of the heads (not of the events).
32 class Tie_engraver : public Engraver
36 Link_array<Grob> now_heads_;
37 Link_array<Grob> heads_to_tie_;
38 Link_array<Grob> ties_;
39 Protected_scm tie_start_definition_;
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 ()
80 context ()->set_property ("tieMelismaBusy", SCM_BOOL_T);
85 Tie_engraver::acknowledge_grob (Grob_info i)
87 if (Note_head::has_interface (i.grob_))
91 for (int i = heads_to_tie_.size (); i--;)
93 Grob *th = heads_to_tie_[i];
94 Music * right_mus = unsmob_music (h->get_property ("cause"));
95 Music * left_mus = unsmob_music (th->get_property ("cause"));
98 maybe should check positions too.
100 if (right_mus && left_mus
101 && ly_c_equal_p (right_mus->get_property ("pitch"),
102 left_mus->get_property ("pitch")))
104 Grob * p = new Spanner (tie_start_definition_);
105 announce_grob (p, last_event_->self_scm ());
106 Tie::set_interface (p); // cannot remove yet!
108 Tie::set_head (p, LEFT, th);
109 Tie::set_head (p, RIGHT, h);
115 if (ties_.size () && ! tie_column_)
117 tie_column_ = make_spanner ("TieColumn", SCM_EOL);
122 for (int i = ties_.size (); i--;)
123 Tie_column::add_tie (tie_column_,ties_ [i]);
128 Tie_engraver::start_translation_timestep ()
130 context ()->set_property ("tieMelismaBusy",
131 ly_bool2scm (heads_to_tie_.size ()));
136 Tie_engraver::stop_translation_timestep ()
140 heads_to_tie_.clear ();
141 for (int i=0; i< ties_.size (); i++)
143 typeset_tie (ties_[i]);
153 tie_start_definition_ = updated_grob_properties (context (), ly_symbol2scm ("Tie"));
154 heads_to_tie_ = now_heads_;
155 last_event_ = event_;
162 Tie_engraver::typeset_tie (Grob *her)
164 if (! (Tie::head (her,LEFT) && Tie::head (her,RIGHT)))
165 warning (_ ("lonely tie"));
168 Drul_array<Grob *> new_head_drul;
169 new_head_drul[LEFT] = Tie::head (her,LEFT);
170 new_head_drul[RIGHT] = Tie::head (her,RIGHT);
172 if (!Tie::head (her,d))
173 new_head_drul[d] = Tie::head (her, (Direction)-d);
174 } while (flip (&d) != LEFT);
176 index_set_cell (her->get_property ("head-pair"), LEFT, new_head_drul[LEFT]->self_scm ());
177 index_set_cell (her->get_property ("head-pair"), RIGHT, new_head_drul[RIGHT]->self_scm ());
182 ENTER_DESCRIPTION (Tie_engraver,
183 /* descr */ "Generate ties between noteheads of equal pitch.",
184 /* creats*/ "Tie TieColumn",
185 /* accepts */ "tie-event",
186 /* acks */ "rhythmic-head-interface",
187 /* reads */ "tieMelismaBusy",