]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-performer.cc
Merge branch 'master' of git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond
[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--2007 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       Pitch transposing;
42       SCM prop = get_property ("instrumentTransposition");
43       if (unsmob_pitch (prop))
44         transposing = *unsmob_pitch (prop);
45
46       while (note_evs_.size ())
47         {
48           Stream_event *n = note_evs_.back ();
49           note_evs_.pop_back ();
50           SCM pit = n->get_property ("pitch");
51
52           if (Pitch *pitp = unsmob_pitch (pit))
53             {
54               SCM articulations = n->get_property ("articulations");
55               Stream_event *tie_event = 0;
56               for (SCM s = articulations;
57                    !tie_event && scm_is_pair (s);
58                    s = scm_cdr (s))
59                 {
60                   Stream_event *ev = unsmob_stream_event (scm_car (s));
61                   if (!ev)
62                     continue;
63           
64                   if (ev->in_event_class ("tie-event"))
65                     tie_event = ev;
66                 }
67
68               Moment len = get_event_length (n);
69               if (now_mom().grace_part_)
70                 {
71                   len.grace_part_ = len.main_part_;
72                   len.main_part_ = Rational (0);
73                 }
74               
75               Audio_note *p = new Audio_note (*pitp, len, 
76                                               tie_event, transposing.negated ());
77               Audio_element_info info (p, n);
78               announce_element (info);
79               notes_.push_back (p);
80             }
81         }
82       note_evs_.clear ();
83     }
84 }
85
86 void
87 Note_performer::stop_translation_timestep ()
88 {
89   // why don't grace notes show up here?
90   // --> grace notes effectively do not get delayed
91   notes_.clear ();
92   note_evs_.clear ();
93 }
94
95 IMPLEMENT_TRANSLATOR_LISTENER (Note_performer, note)
96 void
97 Note_performer::listen_note (Stream_event *ev)
98 {
99   note_evs_.push_back (ev);
100 }
101
102 ADD_TRANSLATOR (Note_performer, "", "",
103                 "", "");
104
105 Note_performer::Note_performer ()
106 {
107 }