]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-performer.cc
4aecc396067c9524a73767261d5bf9cdc0150909
[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 "stream-event.hh"
14 #include "warn.hh"
15
16 #include "translator.icc"
17
18 /**
19    Convert evs to audio notes.
20 */
21 class Note_performer : public Performer
22 {
23 public:
24   TRANSLATOR_DECLARATIONS (Note_performer);
25
26 protected:
27   void stop_translation_timestep ();
28   void process_music ();
29
30   DECLARE_TRANSLATOR_LISTENER (note);
31 private:
32   vector<Stream_event*> note_evs_;
33   vector<Audio_note*> notes_;
34 };
35
36 void
37 Note_performer::process_music ()
38 {
39   if (note_evs_.size ())
40     {
41       int transposing = 0;
42
43       SCM prop = get_property ("instrumentTransposition");
44       if (unsmob_pitch (prop))
45         transposing = unsmob_pitch (prop)->semitone_pitch ();
46
47       while (note_evs_.size ())
48         {
49           Stream_event *n = note_evs_.back ();
50           note_evs_.pop_back ();
51           SCM pit = n->get_property ("pitch");
52
53           if (Pitch *pitp = unsmob_pitch (pit))
54             {
55               SCM articulations = n->get_property ("articulations");
56               Stream_event *tie_event = 0;
57               for (SCM s = articulations;
58                    !tie_event && scm_is_pair (s);
59                    s = scm_cdr (s))
60                 {
61                   Stream_event *ev = unsmob_stream_event (scm_car (s));
62                   if (!ev)
63                     continue;
64           
65                   if (ev->in_event_class ("tie-event"))
66                     tie_event = ev;
67                 }
68
69               Audio_note *p = new Audio_note (*pitp, get_event_length (n), 
70                                               tie_event, - transposing);
71               Audio_element_info info (p, n);
72               announce_element (info);
73               notes_.push_back (p);
74             }
75         }
76       note_evs_.clear ();
77     }
78 }
79
80 void
81 Note_performer::stop_translation_timestep ()
82 {
83   // why don't grace notes show up here?
84   // --> grace notes effectively do not get delayed
85   notes_.clear ();
86   note_evs_.clear ();
87 }
88
89 IMPLEMENT_TRANSLATOR_LISTENER (Note_performer, note)
90 void
91 Note_performer::listen_note (Stream_event *ev)
92 {
93   note_evs_.push_back (ev);
94 }
95
96 ADD_TRANSLATOR (Note_performer, "", "",
97                 "note-event ",
98                 "", "");
99
100 Note_performer::Note_performer ()
101 {
102 }