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"
22 Manufacture ties. Acknowledge noteheads, and put them into a
23 priority queue. If we have a TieEvent, 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 events).
29 TODO: support sparseTies.
31 TODO: melismata will fuck up now:
36 melisma is after the 2nd 8th note, but will now be signaled as
37 lasting till the 3rd 16th.
39 class Tie_engraver
: public Engraver
43 Link_array
<Grob
> now_heads_
;
44 Link_array
<Grob
> heads_to_tie_
;
45 Link_array
<Grob
> ties_
;
47 Spanner
* tie_column_
;
51 virtual void stop_translation_timestep ();
52 virtual void acknowledge_grob (Grob_info
);
53 virtual bool try_music (Music
*);
54 virtual void process_acknowledged_grobs ();
55 void typeset_tie (Grob
*);
57 TRANSLATOR_DECLARATIONS(Tie_engraver
);
62 Tie_engraver::Tie_engraver ()
71 Tie_engraver::try_music (Music
*mus
)
73 if (mus
->is_mus_type ("tie-event"))
80 SCM m
= get_property ("automaticMelismata");
81 bool am
= gh_boolean_p (m
) &&gh_scm2bool (m
);
84 daddy_trans_
->set_property ("tieMelismaBusy", m
? SCM_BOOL_T
: SCM_BOOL_F
);
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 int staff_pos
= gh_scm2int (h
->get_grob_property ("staff-position"));
101 int left_staff_pos
= gh_scm2int (th
->get_grob_property ("staff-position"));
102 if (staff_pos
== left_staff_pos
)
104 Grob
* p
= new Spanner (get_property ("Tie"));
105 Tie::set_interface (p
); // cannot remove yet!
107 Tie::set_head (p
, LEFT
, th
);
108 Tie::set_head (p
, RIGHT
, h
);
111 announce_grob(p
, last_event_
->self_scm());
118 Tie_engraver::process_acknowledged_grobs ()
120 if (ties_
.size () > 1 && !tie_column_
)
122 tie_column_
= new Spanner (get_property ("TieColumn"));
124 for (int i
= ties_
.size (); i
--;)
125 Tie_column::add_tie (tie_column_
,ties_
[i
]);
127 announce_grob(tie_column_
, SCM_EOL
);
133 Tie_engraver::stop_translation_timestep ()
137 heads_to_tie_
.clear ();
138 for (int i
=0; i
< ties_
.size (); i
++)
140 typeset_tie (ties_
[i
]);
147 typeset_grob (tie_column_
);
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_grob_property ("heads"), LEFT
, new_head_drul
[LEFT
]->self_scm ());
177 index_set_cell (her
->get_grob_property ("heads"), RIGHT
, new_head_drul
[RIGHT
]->self_scm ());
183 ENTER_DESCRIPTION(Tie_engraver
,
184 /* descr */ "Generate ties between noteheads of equal pitch.",
185 /* creats*/ "Tie TieColumn",
186 /* accepts */ "tie-event",
187 /* acks */ "rhythmic-head-interface",
188 /* reads */ "tieMelismaBusy",