2 new-tie-engraver.cc -- implement Tie_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "translator-group.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 TODO: support sparseTies.
32 TODO: melismata will fuck up now:
37 melisma is after the 2nd 8th note, but will now be signaled as
38 lasting till the 3rd 16th.
40 class Tie_engraver : public Engraver
44 Link_array<Grob> now_heads_;
45 Link_array<Grob> heads_to_tie_;
46 Link_array<Grob> ties_;
48 Spanner * tie_column_;
52 virtual void stop_translation_timestep ();
53 virtual void start_translation_timestep ();
54 virtual void acknowledge_grob (Grob_info);
55 virtual bool try_music (Music*);
56 virtual void process_acknowledged_grobs ();
57 void typeset_tie (Grob*);
59 TRANSLATOR_DECLARATIONS(Tie_engraver);
64 Tie_engraver::Tie_engraver ()
73 Tie_engraver::try_music (Music *mus)
75 if (mus->is_mus_type ("tie-event"))
84 Tie_engraver::acknowledge_grob (Grob_info i)
86 if (Note_head::has_interface (i.grob_))
90 for (int i = heads_to_tie_.size (); i--;)
92 Grob *th = heads_to_tie_[i];
93 int staff_pos = int (Staff_symbol_referencer::get_position (h));
94 int left_staff_pos = int (Staff_symbol_referencer::get_position (th));
96 if (staff_pos == left_staff_pos)
98 Grob * p = new Spanner (get_property ("Tie"));
99 Tie::set_interface (p); // cannot remove yet!
101 Tie::set_head (p, LEFT, th);
102 Tie::set_head (p, RIGHT, h);
105 announce_grob(p, last_event_->self_scm());
112 Tie_engraver::process_acknowledged_grobs ()
114 if (ties_.size () > 1 && !tie_column_)
116 tie_column_ = new Spanner (get_property ("TieColumn"));
118 for (int i = ties_.size (); i--;)
119 Tie_column::add_tie (tie_column_,ties_ [i]);
121 announce_grob(tie_column_, SCM_EOL);
126 Tie_engraver::start_translation_timestep ()
128 if (to_boolean (get_property ("automaticMelismata")))
129 daddy_trans_->set_property ("tieMelismaBusy",
130 gh_bool2scm (heads_to_tie_.size ()));
135 Tie_engraver::stop_translation_timestep ()
139 heads_to_tie_.clear ();
140 for (int i=0; i< ties_.size (); i++)
142 typeset_tie (ties_[i]);
149 typeset_grob (tie_column_);
156 heads_to_tie_ = now_heads_;
157 last_event_ = event_;
164 Tie_engraver::typeset_tie (Grob *her)
166 if (! (Tie::head (her,LEFT) && Tie::head (her,RIGHT)))
167 warning (_ ("lonely tie"));
170 Drul_array<Grob *> new_head_drul;
171 new_head_drul[LEFT] = Tie::head (her,LEFT);
172 new_head_drul[RIGHT] = Tie::head (her,RIGHT);
174 if (!Tie::head (her,d))
175 new_head_drul[d] = Tie::head (her, (Direction)-d);
176 } while (flip (&d) != LEFT);
178 index_set_cell (her->get_grob_property ("heads"), LEFT, new_head_drul[LEFT]->self_scm ());
179 index_set_cell (her->get_grob_property ("heads"), RIGHT, new_head_drul[RIGHT]->self_scm ());
185 ENTER_DESCRIPTION(Tie_engraver,
186 /* descr */ "Generate ties between noteheads of equal pitch.",
187 /* creats*/ "Tie TieColumn",
188 /* accepts */ "tie-event",
189 /* acks */ "rhythmic-head-interface",
190 /* reads */ "tieMelismaBusy",