2 tie-engraver.cc -- implement Tie_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "command-request.hh"
11 #include "musical-request.hh"
13 #include "translator-group.hh"
15 #include "tie-column.hh"
16 #include "engraver.hh"
18 #include "grob-pitch-tuple.hh"
19 #include "note-head.hh"
22 Manufacture ties. Acknowledge noteheads, and put them into a
23 priority queue. If we have a Tie_req, connect the notes that finish
24 just at this time, and note that start at this time.
26 TODO: Remove the dependency on musical info. We should tie on the
27 basis of position and duration-log of the heads (not of the reqs).
30 TODO: figure this out: currently, this engravers ties note heads
31 that have the same Y-position (and does not look at pitch). This
32 means that we will fuck up with a clef-change. How should
33 clef-changes during ties be handled, or should they not?
37 class Tie_engraver : public Engraver
43 Link_array<Grob> now_heads_;
44 Link_array<Grob> stopped_heads_;
45 Link_array<Grob> tie_p_arr_;
47 Spanner * tie_column_p_;
49 void set_melisma (bool);
52 virtual void start_translation_timestep ();
53 virtual void stop_translation_timestep ();
54 virtual void acknowledge_grob (Grob_info);
55 virtual bool try_music (Music*);
56 virtual void create_grobs ();
57 void typeset_tie (Grob*);
59 TRANSLATOR_DECLARATIONS(Tie_engraver);
64 Tie_engraver::Tie_engraver ()
72 Tie_engraver::try_music (Music *m)
74 if (Tie_req * c = dynamic_cast<Tie_req*> (m))
76 /* if (end_mom_ > now_mom ())
80 SCM m = get_property ("automaticMelismata");
81 bool am = gh_boolean_p (m) &&gh_scm2bool (m);
92 Tie_engraver::set_melisma (bool m)
94 daddy_trans_l_->set_property ("tieMelismaBusy", m ? SCM_BOOL_T : SCM_BOOL_F);
98 Tie_engraver::acknowledge_grob (Grob_info i)
100 if (Note_head::has_interface (i.grob_l_))
102 now_heads_.push (i.grob_l_);
107 head_position_compare (Grob *const&a,Grob *const&b)
109 return sign (gh_scm2double (a->get_grob_property ("staff-position"))
110 - gh_scm2double (b->get_grob_property ("staff-position")));
114 Tie_engraver::create_grobs ()
118 now_heads_.sort (&head_position_compare);
119 stopped_heads_.sort (&head_position_compare);
121 SCM head_list = SCM_EOL;
123 int j = stopped_heads_.size ()-1;
124 int i = now_heads_.size ()-1;
126 while (i >= 0 && j >=0)
129 = head_position_compare (now_heads_[i], stopped_heads_[j]);
133 (comp < 0) ? j -- : i--;
138 head_list = gh_cons (gh_cons (stopped_heads_[j]->self_scm (),
139 now_heads_[i]->self_scm ()),
143 stopped_heads_.del (j);
149 SCM basic = get_property ("Tie");
150 SCM sparse = get_property ("sparseTies");
151 if (to_boolean (sparse))
153 int i = scm_ilength (head_list);
158 SCM pair = scm_list_ref (head_list, gh_int2scm (i/2));
160 Spanner * p = new Spanner (basic);
162 Tie::set_interface (p);
163 Tie::set_head (p,LEFT, dynamic_cast<Item*> (unsmob_grob (ly_car (pair))));
164 Tie::set_head (p,RIGHT, dynamic_cast<Item*> (unsmob_grob (ly_cdr (pair))));
167 announce_grob (p, req_l_);
169 else for (SCM s = head_list; gh_pair_p (s); s = ly_cdr (s))
171 Grob * p = new Spanner (basic);
172 Tie::set_interface (p);
174 Tie::set_head (p, LEFT, dynamic_cast<Item*> (unsmob_grob (ly_caar (s))));
175 Tie::set_head (p, RIGHT, dynamic_cast<Item*> (unsmob_grob (ly_cdar (s))));
178 announce_grob (p, req_l_);
181 if (tie_p_arr_.size () > 1 && !tie_column_p_)
183 tie_column_p_ = new Spanner (get_property ("TieColumn"));
184 Tie_column::set_interface (tie_column_p_);
185 for (int i = tie_p_arr_.size (); i--;)
186 Tie_column::add_tie (tie_column_p_,tie_p_arr_ [i]);
187 announce_grob (tie_column_p_, 0);
194 Tie_engraver::stop_translation_timestep ()
201 we don't warn for no ties, since this happens naturally when you
202 use skipTypesetting. */
204 for (int i=0; i< tie_p_arr_.size (); i++)
206 typeset_tie (tie_p_arr_[i]);
211 typeset_grob (tie_column_p_);
217 Tie_engraver::typeset_tie (Grob *her)
219 if (! (Tie::head (her,LEFT) && Tie::head (her,RIGHT)))
220 warning (_ ("lonely tie"));
223 Drul_array<Grob *> new_head_drul;
224 new_head_drul[LEFT] = Tie::head (her,LEFT);
225 new_head_drul[RIGHT] = Tie::head (her,RIGHT);
227 if (!Tie::head (her,d))
228 new_head_drul[d] = Tie::head (her, (Direction)-d);
229 } while (flip (&d) != LEFT);
231 index_set_cell (her->get_grob_property ("heads"), LEFT, new_head_drul[LEFT]->self_scm ());
232 index_set_cell (her->get_grob_property ("heads"), RIGHT, new_head_drul[RIGHT]->self_scm ());
238 Tie_engraver::start_translation_timestep ()
240 SCM m = get_property ("automaticMelismata");
246 SCM grobs = get_property ("busyGrobs");
247 Moment now = now_mom();
248 stopped_heads_.clear ();
250 for (; gh_pair_p (grobs); grobs = gh_cdr (grobs))
252 Grob * grob = unsmob_grob (gh_cdar (grobs));
253 Moment end =*unsmob_moment (gh_caar (grobs));
256 This is slightly ugh: we are now confunding the frontend
257 (iterators) and the backend (note heads) */
261 && Note_head::has_interface (grob))
262 stopped_heads_.push (grob);
267 ENTER_DESCRIPTION(Tie_engraver,
268 /* descr */ "Generate ties between noteheads of equal pitch.",
269 /* creats*/ "Tie TieColumn",
270 /* acks */ "rhythmic-head-interface",
271 /* reads */ "sparseTies tieMelismaBusy",