]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-performer.cc
*** empty log message ***
[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--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7  */
8
9 #include "performer.hh"
10 #include "audio-item.hh"
11 #include "audio-column.hh"
12 #include "global-context.hh"
13 #include "warn.hh"
14
15 /**
16 Convert evs to audio notes.
17 */
18 class Note_performer : public Performer {
19 public:
20   TRANSLATOR_DECLARATIONS (Note_performer);
21   
22 protected:
23   virtual bool try_music (Music *ev) ;
24
25   virtual void stop_translation_timestep ();
26   virtual void create_audio_elements ();
27  
28 private:
29   Link_array<Music> note_evs_;
30   Link_array<Audio_note> notes_;
31   Link_array<Audio_note> delayeds_;
32 };
33
34 void 
35 Note_performer::create_audio_elements ()
36 {
37   if (note_evs_.size ())
38     {
39       int transposing = 0;
40
41       SCM prop = get_property ("instrumentTransposition");
42       if (unsmob_pitch (prop)) 
43         transposing = unsmob_pitch (prop)->semitone_pitch ();
44
45       while (note_evs_.size ())
46         {
47           Music* n = note_evs_.pop ();
48           SCM pit =  n->get_property ("pitch");
49
50           if (Pitch * pitp = unsmob_pitch (pit))
51             {
52               Audio_note* p = new Audio_note (*pitp,  n->get_length (),  - transposing);
53               Audio_element_info info (p, n);
54               announce_element (info);
55               notes_.push (p);
56             }
57         }
58       note_evs_.clear ();
59     }
60 }
61
62
63 void
64 Note_performer::stop_translation_timestep ()
65 {
66   // why don't grace notes show up here?
67   // --> grace notes effectively do not get delayed
68   Global_context * global = get_global_context ();
69   for (int i = 0; i < notes_.size (); i++)
70     {
71       Audio_note* n = notes_[i];
72       Moment m = n->delayed_until_mom_;
73       if (m.to_bool ())
74         {
75           global->add_moment_to_process (m);
76           delayeds_.push (n);
77           notes_[i] = 0;
78           notes_.del (i);
79           i--;
80         }
81     }
82
83   Moment now = now_mom ();
84   for (int i = 0; i < notes_.size (); i++)
85     {
86       play_element (notes_[i]);
87     }
88   notes_.clear ();
89   note_evs_.clear ();
90   for (int i = 0; i < delayeds_.size (); i++)
91     {
92       Audio_note* n = delayeds_[i];
93       if (n->delayed_until_mom_ <= now)
94         {
95           play_element (n);
96           delayeds_[i] = 0;
97           delayeds_.del (i);
98           i--;
99         }
100     }
101 }
102  
103 bool
104 Note_performer::try_music (Music* ev)
105 {
106   if (ev->is_mus_type ("note-event"))
107     {
108       note_evs_.push (ev);
109       return true;
110     }
111   else if (ev->is_mus_type ("busy-playing-event"))
112     return note_evs_.size ();
113   
114   return false;
115 }
116
117 ADD_TRANSLATOR (Note_performer,"","",
118                   "note-event busy-playing-event","","","");
119
120 Note_performer::Note_performer ()
121 {
122 }