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 SCM tie_start_definition_;
41 Spanner * tie_column_;
44 virtual void stop_translation_timestep ();
45 virtual void derived_mark () const;
46 virtual void start_translation_timestep ();
47 virtual void acknowledge_grob (Grob_info);
48 virtual bool try_music (Music*);
49 virtual void process_music ();
50 void typeset_tie (Grob*);
52 TRANSLATOR_DECLARATIONS (Tie_engraver);
57 Tie_engraver::Tie_engraver ()
62 tie_start_definition_ = SCM_EOL;
66 Tie_engraver::derived_mark () const
68 scm_gc_mark (tie_start_definition_);
73 Tie_engraver::try_music (Music *mus)
75 if (mus->is_mus_type ("tie-event"))
84 Tie_engraver::process_music ()
88 context ()->set_property ("tieMelismaBusy", SCM_BOOL_T);
93 Tie_engraver::acknowledge_grob (Grob_info i)
95 if (Note_head::has_interface (i.grob_))
99 for (int i = heads_to_tie_.size (); i--;)
101 Grob *th = heads_to_tie_[i];
102 Music * right_mus = unsmob_music (h->get_property ("cause"));
103 Music * left_mus = unsmob_music (th->get_property ("cause"));
106 maybe should check positions too.
108 if (right_mus && left_mus
109 && ly_c_equal_p (right_mus->get_property ("pitch"),
110 left_mus->get_property ("pitch")))
112 Grob * p = new Spanner (tie_start_definition_, context()->get_grob_key ("Tie"));
113 announce_grob (p, last_event_->self_scm ());
114 Tie::set_interface (p); // cannot remove yet!
116 Tie::set_head (p, LEFT, th);
117 Tie::set_head (p, RIGHT, h);
123 if (ties_.size () && ! tie_column_)
125 tie_column_ = make_spanner ("TieColumn", SCM_EOL);
130 for (int i = ties_.size (); i--;)
131 Tie_column::add_tie (tie_column_,ties_ [i]);
136 Tie_engraver::start_translation_timestep ()
138 context ()->set_property ("tieMelismaBusy",
139 ly_bool2scm (heads_to_tie_.size ()));
144 Tie_engraver::stop_translation_timestep ()
148 heads_to_tie_.clear ();
149 for (int i=0; i< ties_.size (); i++)
151 typeset_tie (ties_[i]);
161 tie_start_definition_ = updated_grob_properties (context (), ly_symbol2scm ("Tie"));
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_property ("head-pair"), LEFT, new_head_drul[LEFT]->self_scm ());
185 index_set_cell (her->get_property ("head-pair"), RIGHT, new_head_drul[RIGHT]->self_scm ());
190 ENTER_DESCRIPTION (Tie_engraver,
191 /* descr */ "Generate ties between noteheads of equal pitch.",
192 /* creats*/ "Tie TieColumn",
193 /* accepts */ "tie-event",
194 /* acks */ "rhythmic-head-interface",
195 /* reads */ "tieMelismaBusy",