]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-performer.cc
release: 1.5.29
[lilypond.git] / lily / note-performer.cc
1 /*
2   note-performer.cc -- implement Note_performer
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996--2002 Jan Nieuwenhuizen <janneke@gnu.org>
7  */
8
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"
15
16 /**
17 Convert reqs to audio notes.
18 */
19 class Note_performer : public Performer {
20 public:
21   TRANSLATOR_DECLARATIONS(Note_performer);
22   
23 protected:
24   virtual bool try_music (Music *req_l) ;
25
26   virtual void stop_translation_timestep ();
27   virtual void create_audio_elements ();
28   Global_translator* global_translator_l ();
29
30 private:
31   Array<Note_req*> note_req_l_arr_;
32   Array<Audio_note*> note_p_arr_;
33   Array<Audio_note*> delayed_p_arr_;
34 };
35
36 void 
37 Note_performer::create_audio_elements ()
38 {
39   if (note_req_l_arr_.size ())
40     {
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);
46
47       while (note_req_l_arr_.size ())
48         {
49           Note_req* n = note_req_l_arr_.pop ();
50           Pitch pit =  * unsmob_pitch (n->get_mus_property ("pitch"));
51           Audio_note* p = new Audio_note (pit,  n->length_mom (), transposing_i);
52           Audio_element_info info (p, n);
53           announce_element (info);
54           note_p_arr_.push (p);
55         }
56       note_req_l_arr_.clear ();
57     }
58 }
59
60 Global_translator*
61 Note_performer::global_translator_l ()
62 {
63   Translator *t = this;
64   Global_translator *global_l =0;
65   do
66     {
67       t = t->daddy_trans_l_ ;
68       global_l = dynamic_cast<Global_translator*> (t);
69     }
70   while (!global_l);
71
72   return global_l;
73 }
74
75
76 void
77 Note_performer::stop_translation_timestep ()
78 {
79
80   // why don't grace notes show up here?
81   // --> grace notes effectively do not get delayed
82   Global_translator* global_l = global_translator_l ();
83   for (int i=0; i < note_p_arr_.size (); i++)
84     {
85       Audio_note* n = note_p_arr_[i];
86       Moment m= n->delayed_until_mom_;
87       if (m.to_bool ())
88         {
89           global_l->add_moment_to_process (m);
90           delayed_p_arr_.push (n);
91           note_p_arr_[i] = 0;
92           note_p_arr_.del (i);
93           i--;
94         }
95     }
96
97   Moment now = now_mom ();
98   for (int i=0; i < note_p_arr_.size (); i++)
99     {
100       play_element (note_p_arr_[i]);
101     }
102   note_p_arr_.clear ();
103   note_req_l_arr_.clear ();
104   for (int i=0; i < delayed_p_arr_.size (); i++)
105     {
106       Audio_note* n = delayed_p_arr_[i];
107       if (n->delayed_until_mom_ <= now)
108         {
109           play_element (n);
110           delayed_p_arr_[i] = 0;
111           delayed_p_arr_.del (i);
112           i--;
113         }
114     }
115 }
116  
117 bool
118 Note_performer::try_music (Music* req_l)
119 {
120   if (Note_req *nr = dynamic_cast <Note_req *> (req_l))
121     {
122       note_req_l_arr_.push (nr);
123       return true;
124     }
125   return false;
126 }
127
128 ENTER_DESCRIPTION(Note_performer,"","","","","");
129
130 Note_performer::Note_performer()
131 {
132 }