2 ctie-engraver.cc -- implement Tie_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "tie-engraver.hh"
11 #include "command-request.hh"
12 #include "note-head.hh"
13 #include "musical-request.hh"
15 #include "translator-group.hh"
17 Tie_engraver::Tie_engraver()
24 Tie_engraver::do_try_music (Music
*m
)
26 if (Tie_req
* c
= dynamic_cast<Tie_req
*> (m
))
29 SCM m
= get_property ("automaticMelismata",0);
30 bool am
= gh_boolean_p (m
) &&gh_scm2bool (m
);
41 Tie_engraver::set_melisma (bool m
)
43 Translator_group
*where
= daddy_trans_l_
;
44 get_property ("tieMelismaBusy", &where
);
46 where
= daddy_trans_l_
;
48 daddy_trans_l_
->set_property ("tieMelismaBusy", m
? SCM_BOOL_T
: SCM_BOOL_F
);
52 Tie_engraver::acknowledge_element (Score_element_info i
)
54 if (Note_head
*nh
= dynamic_cast<Note_head
*> (i
.elem_l_
))
56 Note_req
* m
= dynamic_cast<Note_req
* > (i
.req_l_
);
59 now_heads_
.push (CHead_melodic_tuple (nh
, m
, now_mom()+ m
->length_mom ()));
64 Tie_engraver::do_process_requests ()
68 Moment now
= now_mom ();
69 Link_array
<Note_head
> nharr
;
71 stopped_heads_
.clear ();
72 while (past_notes_pq_
.size ()
73 && past_notes_pq_
.front ().end_
== now
)
74 stopped_heads_
.push (past_notes_pq_
.get ());
79 Tie_engraver::process_acknowledged ()
83 now_heads_
.sort (CHead_melodic_tuple::pitch_compare
);
84 stopped_heads_
.sort(CHead_melodic_tuple::pitch_compare
);
88 while ( i
< now_heads_
.size () && j
< stopped_heads_
.size ())
91 = Musical_pitch::compare (now_heads_
[i
].req_l_
->pitch_
,
92 stopped_heads_
[j
].req_l_
->pitch_
);
96 (comp
< 0) ? i
++ : j
++;
103 /* don't go around recreating ties that were already
104 made. Not infallible. Due to reordering in sort (),
105 we will make the wrong ties when noteheads are
107 if (tie_count
> tie_p_arr_
.size ())
110 p
->set_head (LEFT
, stopped_heads_
[j
].head_l_
);
111 p
->set_head (RIGHT
, now_heads_
[i
].head_l_
);
113 announce_element (Score_element_info (p
, req_l_
));
121 if (!tie_p_arr_
.size ())
123 req_l_
->warning (_ ("No ties were created!"));
131 Tie_engraver::do_pre_move_processing ()
133 for (int i
=0; i
< now_heads_
.size (); i
++)
135 past_notes_pq_
.insert (now_heads_
[i
]);
139 for (int i
=0; i
< tie_p_arr_
.size (); i
++)
141 typeset_element (tie_p_arr_
[i
]);
147 Tie_engraver::do_post_move_processing ()
149 SCM m
= get_property ("automaticMelismata",0);
150 if (gh_boolean_p (m
) && gh_scm2bool (m
))
155 Moment now
= now_mom ();
156 while (past_notes_pq_
.size () && past_notes_pq_
.front ().end_
< now
)
157 past_notes_pq_
.delmin ();
160 ADD_THIS_TRANSLATOR(Tie_engraver
);
163 CHead_melodic_tuple::CHead_melodic_tuple ()
170 CHead_melodic_tuple::CHead_melodic_tuple (Note_head
*h
, Melodic_req
*m
, Moment mom
)
178 CHead_melodic_tuple::pitch_compare (CHead_melodic_tuple
const&h1
,
179 CHead_melodic_tuple
const &h2
)
181 return Melodic_req::compare (*h1
.req_l_
, *h2
.req_l_
);
185 CHead_melodic_tuple::time_compare (CHead_melodic_tuple
const&h1
,
186 CHead_melodic_tuple
const &h2
)
188 return (h1
.end_
- h2
.end_
).sign ();