2 grace-position-performer.cc -- implement Grace_position_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "performer.hh"
11 #include "audio-item.hh"
12 #include "global-translator.hh"
14 class Grace_position_performer
: public Performer
17 Grace_position_performer ();
20 Link_array
<Audio_note
> graces_
;
21 Link_array
<Audio_note
> notes_
;
23 VIRTUAL_COPY_CONS (Translator
);
24 virtual void acknowledge_element (Audio_element_info
);
25 virtual void process_acknowledged ();
26 virtual void do_post_move_processing ();
27 Global_translator
* global_translator_l ();
30 ADD_THIS_TRANSLATOR (Grace_position_performer
);
32 Grace_position_performer::Grace_position_performer ()
37 Grace_position_performer::acknowledge_element (Audio_element_info i
)
39 if (Audio_note
* n
= dynamic_cast <Audio_note
*> (i
.elem_l_
))
41 if (i
.elem_l_
->grace_b_
)
49 Grace_position_performer::process_acknowledged ()
53 // we're above grace-engraver-group, so we cannot tell
54 // grace-iterator. note-performer should add moments.
55 //Global_translator* global_l = global_translator_l ();
56 Moment delay_mom
= Moment (1, 8);
59 Moment shortest_mom
= notes_
[0]->length_mom_
;
60 for (int i
=1; i
< notes_
.size (); i
++)
61 shortest_mom
= shortest_mom
<? notes_
[i
]->length_mom_
;
63 Rational
grace_fraction_rat (1, 2);
64 SCM prop
= get_property ("graceFraction", 0);
65 if (SMOB_IS_TYPE_B(Moment
, prop
))
66 grace_fraction_rat
= *SMOB_TO_TYPE (Moment
,prop
);
68 delay_mom
= shortest_mom
* grace_fraction_rat
;
69 for (int i
=0; i
< notes_
.size (); i
++)
71 Audio_note
* n
= notes_
[i
];
72 n
->length_mom_
-= delay_mom
;
73 n
->delayed_mom_
= delay_mom
;
74 n
->delayed_until_mom_
= now_mom () + delay_mom
;
75 //global_l->add_moment_to_process (n->delayed_until_mom_);
80 Moment grace_length_mom
;
81 for (int i
=0; i
< graces_
.size (); i
++)
82 grace_length_mom
+= graces_
[i
]->length_mom_
;
84 Rational grace_factor_rat
= delay_mom
/ grace_length_mom
;
86 for (int i
=0; i
< graces_
.size (); i
++)
88 Audio_note
* n
= graces_
[i
];
89 n
->length_mom_
*= grace_factor_rat
;
92 Audio_note
* p
= graces_
[i
-1];
93 n
->delayed_mom_
= p
->delayed_mom_
+ p
->length_mom_
;
94 n
->delayed_until_mom_
= now_mom () + n
->delayed_mom_
;
95 //global_l->add_moment_to_process (n->delayed_until_mom_);
103 Grace_position_performer::global_translator_l ()
105 Translator
*t
= this;
106 Global_translator
*global_l
=0;
109 t
= t
->daddy_trans_l_
;
110 global_l
= dynamic_cast<Global_translator
*> (t
);
119 Grace_position_performer::do_post_move_processing ()