]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-performer.cc
3bdbcb0df33d4396c6e86dc0c92ca4d672b8801a
[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 {
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 };
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 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 }