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