]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-performer.cc
release: 1.3.109
[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--2000 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   VIRTUAL_COPY_CONS(Translator);
22   
23 protected:
24   virtual bool try_music (Music *req_l) ;
25
26   virtual void stop_translation_timestep ();
27   virtual void create_grobs ();
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 ADD_THIS_TRANSLATOR (Note_performer);
37
38 void 
39 Note_performer::create_grobs ()
40 {
41   if (note_req_l_arr_.size ())
42     {
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);
48
49       while (note_req_l_arr_.size ())
50         {
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);
57         }
58       note_req_l_arr_.clear ();
59     }
60 }
61
62 Global_translator*
63 Note_performer::global_translator_l ()
64 {
65   Translator *t = this;
66   Global_translator *global_l =0;
67   do
68     {
69       t = t->daddy_trans_l_ ;
70       global_l = dynamic_cast<Global_translator*> (t);
71     }
72   while (!global_l);
73
74   return global_l;
75 }
76
77
78 void
79 Note_performer::stop_translation_timestep ()
80 {
81
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++)
86     {
87       Audio_note* n = note_p_arr_[i];
88       if (Moment m= n->delayed_until_mom_)
89         {
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--;
95         }
96     }
97
98   Moment now = now_mom ();
99   for (int i=0; i < note_p_arr_.size (); i++)
100     {
101       play_element (note_p_arr_[i]);
102     }
103   note_p_arr_.clear ();
104   note_req_l_arr_.clear ();
105   for (int i=0; i < delayed_p_arr_.size (); i++)
106     {
107       Audio_note* n = delayed_p_arr_[i];
108       if (n->delayed_until_mom_ <= now)
109         {
110           play_element (n);
111           delayed_p_arr_[i] = 0;
112           delayed_p_arr_.del (i);
113           i--;
114         }
115     }
116 }
117  
118 bool
119 Note_performer::try_music (Music* req_l)
120 {
121   if (Note_req *nr = dynamic_cast <Note_req *> (req_l))
122     {
123       note_req_l_arr_.push (nr);
124       return true;
125     }
126   return false;
127 }