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