*** empty log message ***
[lilypond.git] / lily / note-performer.cc
blob99d172f8eaf32ecc2b02b00333860d2d396af75a
1 /*
2 note-performer.cc -- implement Note_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2003 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include "performer.hh"
10 #include "event.hh"
11 #include "audio-item.hh"
12 #include "audio-column.hh"
13 #include "global-translator.hh"
14 #include "warn.hh"
16 /**
17 Convert reqs to audio notes.
19 class Note_performer : public Performer {
20 public:
21 TRANSLATOR_DECLARATIONS(Note_performer);
23 protected:
24 virtual bool try_music (Music *req) ;
26 virtual void stop_translation_timestep ();
27 virtual void create_audio_elements ();
28 Global_translator* get_global_translator ();
30 private:
31 Link_array<Music> note_reqs_;
32 Link_array<Audio_note> notes_;
33 Link_array<Audio_note> delayeds_;
36 void
37 Note_performer::create_audio_elements ()
39 if (note_reqs_.size ())
41 int transposing_i = 0;
42 //urg
43 SCM prop = get_property ("transposing");
44 if (gh_number_p (prop))
45 transposing_i = gh_scm2int (prop);
47 while (note_reqs_.size ())
49 Music* n = note_reqs_.pop ();
50 Pitch pit = * unsmob_pitch (n->get_mus_property ("pitch"));
51 Audio_note* p = new Audio_note (pit, n->get_length (), transposing_i);
52 Audio_element_info info (p, n);
53 announce_element (info);
54 notes_.push (p);
56 note_reqs_.clear ();
60 Global_translator*
61 Note_performer::get_global_translator ()
63 Translator *t = this;
64 Global_translator *global =0;
67 t = t->daddy_trans_ ;
68 global = dynamic_cast<Global_translator*> (t);
70 while (!global);
72 return global;
76 void
77 Note_performer::stop_translation_timestep ()
80 // why don't grace notes show up here?
81 // --> grace notes effectively do not get delayed
82 Global_translator* global = get_global_translator ();
83 for (int i=0; i < notes_.size (); i++)
85 Audio_note* n = notes_[i];
86 Moment m= n->delayed_until_mom_;
87 if (m.to_bool ())
89 global->add_moment_to_process (m);
90 delayeds_.push (n);
91 notes_[i] = 0;
92 notes_.del (i);
93 i--;
97 Moment now = now_mom ();
98 for (int i=0; i < notes_.size (); i++)
100 play_element (notes_[i]);
102 notes_.clear ();
103 note_reqs_.clear ();
104 for (int i=0; i < delayeds_.size (); i++)
106 Audio_note* n = delayeds_[i];
107 if (n->delayed_until_mom_ <= now)
109 play_element (n);
110 delayeds_[i] = 0;
111 delayeds_.del (i);
112 i--;
117 bool
118 Note_performer::try_music (Music* req)
120 if (req->is_mus_type ("note-event"))
122 note_reqs_.push (req);
123 return true;
125 return false;
128 ENTER_DESCRIPTION(Note_performer,"","","note-event","","","");
130 Note_performer::Note_performer()