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 "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).
30 class Tie_engraver : public Engraver
34 Link_array<Grob> now_heads_;
35 Link_array<Grob> heads_to_tie_;
36 Link_array<Grob> ties_;
37 SCM tie_start_definition_;
39 Spanner * tie_column_;
42 virtual void stop_translation_timestep ();
43 virtual void derived_mark () const;
44 virtual void start_translation_timestep ();
45 virtual void acknowledge_grob (Grob_info);
46 virtual bool try_music (Music*);
47 virtual void process_music ();
48 void typeset_tie (Grob*);
50 TRANSLATOR_DECLARATIONS (Tie_engraver);
55 Tie_engraver::Tie_engraver ()
60 tie_start_definition_ = SCM_EOL;
64 Tie_engraver::derived_mark () const
66 scm_gc_mark (tie_start_definition_);
71 Tie_engraver::try_music (Music *mus)
73 if (mus->is_mus_type ("tie-event"))
82 Tie_engraver::process_music ()
86 context ()->set_property ("tieMelismaBusy", SCM_BOOL_T);
91 Tie_engraver::acknowledge_grob (Grob_info i)
93 if (Note_head::has_interface (i.grob_))
97 for (int i = heads_to_tie_.size (); i--;)
99 Grob *th = heads_to_tie_[i];
100 Music * right_mus = unsmob_music (h->get_property ("cause"));
101 Music * left_mus = unsmob_music (th->get_property ("cause"));
104 maybe should check positions too.
106 if (right_mus && left_mus
107 && ly_c_equal_p (right_mus->get_property ("pitch"),
108 left_mus->get_property ("pitch")))
110 Grob * p = new Spanner (tie_start_definition_, context()->get_grob_key ("Tie"));
111 announce_grob (p, last_event_->self_scm ());
112 Tie::set_interface (p); // cannot remove yet!
114 Tie::set_head (p, LEFT, th);
115 Tie::set_head (p, RIGHT, h);
121 if (ties_.size () && ! tie_column_)
123 tie_column_ = make_spanner ("TieColumn", SCM_EOL);
128 for (int i = ties_.size (); i--;)
129 Tie_column::add_tie (tie_column_,ties_ [i]);
134 Tie_engraver::start_translation_timestep ()
136 context ()->set_property ("tieMelismaBusy",
137 ly_bool2scm (heads_to_tie_.size ()));
142 Tie_engraver::stop_translation_timestep ()
146 heads_to_tie_.clear ();
147 for (int i = 0; i< ties_.size (); i++)
149 typeset_tie (ties_[i]);
159 tie_start_definition_ = updated_grob_properties (context (), ly_symbol2scm ("Tie"));
160 heads_to_tie_ = now_heads_;
161 last_event_ = event_;
168 Tie_engraver::typeset_tie (Grob *her)
170 if (! (Tie::head (her,LEFT) && Tie::head (her,RIGHT)))
171 warning (_ ("lonely tie"));
174 Drul_array<Grob *> new_head_drul;
175 new_head_drul[LEFT] = Tie::head (her,LEFT);
176 new_head_drul[RIGHT] = Tie::head (her,RIGHT);
178 if (!Tie::head (her,d))
179 new_head_drul[d] = Tie::head (her, (Direction)-d);
180 } while (flip (&d) != LEFT);
182 index_set_cell (her->get_property ("head-pair"), LEFT, new_head_drul[LEFT]->self_scm ());
183 index_set_cell (her->get_property ("head-pair"), RIGHT, new_head_drul[RIGHT]->self_scm ());
188 ADD_TRANSLATOR (Tie_engraver,
189 /* descr */ "Generate ties between noteheads of equal pitch.",
190 /* creats*/ "Tie TieColumn",
191 /* accepts */ "tie-event",
192 /* acks */ "rhythmic-head-interface",
193 /* reads */ "tieMelismaBusy",