lilypond-1.3.118
[lilypond.git] / lily / grace-position-performer.cc
blob168bbd3a0f9e1989b10e677a48f4d881809dad9d
1 /*
2 grace-position-performer.cc -- implement Grace_position_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2000 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
10 #include "performer.hh"
11 #include "audio-item.hh"
12 #include "global-translator.hh"
14 class Grace_position_performer : public Performer
16 public:
17 Grace_position_performer ();
19 protected:
20 Link_array<Audio_note> graces_;
21 Link_array<Audio_note> notes_;
23 VIRTUAL_COPY_CONS (Translator);
24 virtual void acknowledge_audio_element (Audio_element_info);
25 virtual void create_audio_elements ();
26 virtual void start_translation_timestep ();
27 Global_translator* global_translator_l ();
30 ADD_THIS_TRANSLATOR (Grace_position_performer);
32 Grace_position_performer::Grace_position_performer ()
36 void
37 Grace_position_performer::acknowledge_audio_element (Audio_element_info i)
39 if (Audio_note * n = dynamic_cast <Audio_note*> (i.elem_l_))
41 if (i.elem_l_->grace_b_)
42 graces_.push (n);
43 else
44 notes_.push (n);
48 void
49 Grace_position_performer::create_audio_elements ()
51 if (graces_.size ())
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);
57 if (notes_.size ())
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");
65 if (unsmob_moment (prop))
66 grace_fraction_rat = *unsmob_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_);
77 notes_.clear ();
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;
90 if (i)
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_);
98 graces_.clear ();
102 Global_translator*
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);
112 while (!global_l);
114 return global_l;
118 void
119 Grace_position_performer::start_translation_timestep ()
121 graces_.clear ();
122 notes_.clear ();