lilypond-1.4.4
[lilypond.git] / lily / note-performer.cc
blobc2665f5495b8fc680e5e25a74114eebf0edef2ea
1 /*
2 note-performer.cc -- implement Note_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2001 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include "performer.hh"
10 #include "musical-request.hh"
11 #include "audio-item.hh"
12 #include "audio-column.hh"
13 #include "global-translator.hh"
14 #include "debug.hh"
16 /**
17 Convert reqs to audio notes.
19 class Note_performer : public Performer {
20 public:
21 VIRTUAL_COPY_CONS (Translator);
23 protected:
24 virtual bool try_music (Music *req_l) ;
26 virtual void stop_translation_timestep ();
27 virtual void create_audio_elements ();
28 Global_translator* global_translator_l ();
30 private:
31 Array<Note_req*> note_req_l_arr_;
32 Array<Audio_note*> note_p_arr_;
33 Array<Audio_note*> delayed_p_arr_;
36 ADD_THIS_TRANSLATOR (Note_performer);
38 void
39 Note_performer::create_audio_elements ()
41 if (note_req_l_arr_.size ())
43 int transposing_i = 0;
44 //urg
45 SCM prop = get_property ("transposing");
46 if (gh_number_p (prop))
47 transposing_i = gh_scm2int (prop);
49 while (note_req_l_arr_.size ())
51 Note_req* n = note_req_l_arr_.pop ();
52 Pitch pit = * unsmob_pitch (n->get_mus_property ("pitch"));
53 Audio_note* p = new Audio_note (pit, n->length_mom (), transposing_i);
54 Audio_element_info info (p, n);
55 announce_element (info);
56 note_p_arr_.push (p);
58 note_req_l_arr_.clear ();
62 Global_translator*
63 Note_performer::global_translator_l ()
65 Translator *t = this;
66 Global_translator *global_l =0;
69 t = t->daddy_trans_l_ ;
70 global_l = dynamic_cast<Global_translator*> (t);
72 while (!global_l);
74 return global_l;
78 void
79 Note_performer::stop_translation_timestep ()
82 // why don't grace notes show up here?
83 // --> grace notes effectively do not get delayed
84 Global_translator* global_l = global_translator_l ();
85 for (int i=0; i < note_p_arr_.size (); i++)
87 Audio_note* n = note_p_arr_[i];
88 if (Moment m= n->delayed_until_mom_)
90 global_l->add_moment_to_process (m);
91 delayed_p_arr_.push (n);
92 note_p_arr_[i] = 0;
93 note_p_arr_.del (i);
94 i--;
98 Moment now = now_mom ();
99 for (int i=0; i < note_p_arr_.size (); i++)
101 play_element (note_p_arr_[i]);
103 note_p_arr_.clear ();
104 note_req_l_arr_.clear ();
105 for (int i=0; i < delayed_p_arr_.size (); i++)
107 Audio_note* n = delayed_p_arr_[i];
108 if (n->delayed_until_mom_ <= now)
110 play_element (n);
111 delayed_p_arr_[i] = 0;
112 delayed_p_arr_.del (i);
113 i--;
118 bool
119 Note_performer::try_music (Music* req_l)
121 if (Note_req *nr = dynamic_cast <Note_req *> (req_l))
123 note_req_l_arr_.push (nr);
124 return true;
126 return false;