]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-performer.cc
531b4788d6fd801390a0cefe54d180054f3ae191
[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 };
32
33 void 
34 Note_performer::create_audio_elements ()
35 {
36   if (note_evs_.size ())
37     {
38       int transposing = 0;
39
40       SCM prop = get_property ("instrumentTransposition");
41       if (unsmob_pitch (prop)) 
42         transposing = unsmob_pitch (prop)->semitone_pitch ();
43
44       while (note_evs_.size ())
45         {
46           Music* n = note_evs_.pop ();
47           SCM pit =  n->get_property ("pitch");
48
49           if (Pitch * pitp = unsmob_pitch (pit))
50             {
51               Audio_note* p = new Audio_note (*pitp,  n->get_length (),  - transposing);
52               Audio_element_info info (p, n);
53               announce_element (info);
54               notes_.push (p);
55             }
56         }
57       note_evs_.clear ();
58     }
59 }
60
61
62 void
63 Note_performer::stop_translation_timestep ()
64 {
65   // why don't grace notes show up here?
66   // --> grace notes effectively do not get delayed
67   Moment now = now_mom ();
68   for (int i = 0; i < notes_.size (); i++)
69     {
70       play_element (notes_[i]);
71     }
72   notes_.clear ();
73   note_evs_.clear ();
74 }
75  
76 bool
77 Note_performer::try_music (Music* ev)
78 {
79   if (ev->is_mus_type ("note-event"))
80     {
81       note_evs_.push (ev);
82       return true;
83     }
84   else if (ev->is_mus_type ("busy-playing-event"))
85     return note_evs_.size ();
86   
87   return false;
88 }
89
90 ADD_TRANSLATOR (Note_performer, "", "",
91                   "note-event busy-playing-event", "", "", "");
92
93 Note_performer::Note_performer ()
94 {
95 }