]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-performer.cc
* The grand 2005-2006 replace.
[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--2006 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 #include "music.hh"
15
16 /**
17    Convert evs to audio notes.
18 */
19 class Note_performer : public Performer
20 {
21 public:
22   TRANSLATOR_DECLARATIONS (Note_performer);
23
24 protected:
25   virtual bool try_music (Music *ev);
26
27   void stop_translation_timestep ();
28   void process_music ();
29
30 private:
31   Link_array<Music> note_evs_;
32   Link_array<Audio_note> notes_;
33 };
34
35 void
36 Note_performer::process_music ()
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 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   Moment now = now_mom ();
69   for (int i = 0; i < notes_.size (); i++)
70     play_element (notes_[i]);
71   notes_.clear ();
72   note_evs_.clear ();
73 }
74
75 bool
76 Note_performer::try_music (Music *ev)
77 {
78   if (ev->is_mus_type ("note-event"))
79     {
80       note_evs_.push (ev);
81       return true;
82     }
83   else if (ev->is_mus_type ("busy-playing-event"))
84     return note_evs_.size ();
85
86   return false;
87 }
88
89 #include "translator.icc"
90
91 ADD_TRANSLATOR (Note_performer, "", "",
92                 "note-event "
93                 "busy-playing-event",
94                 "", "");
95
96 Note_performer::Note_performer ()
97 {
98 }