]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-performer.cc
435575da604b1b66eecf109cc0df4cf452c9e221
[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 class Note_performer : public Performer
19 {
20 public:
21   TRANSLATOR_DECLARATIONS (Note_performer);
22
23 protected:
24   void stop_translation_timestep ();
25   void process_music ();
26
27   DECLARE_TRANSLATOR_LISTENER (note);
28 private:
29   vector<Stream_event*> note_evs_;
30   vector<Audio_note*> notes_;
31
32
33   vector<Audio_note*> last_notes_;
34   Moment last_start_;
35   
36 };
37
38 void
39 Note_performer::process_music ()
40 {
41   if (!note_evs_.size ())
42     return;
43
44   Pitch transposing;
45   SCM prop = get_property ("instrumentTransposition");
46   if (unsmob_pitch (prop))
47     transposing = *unsmob_pitch (prop);
48
49   for (vsize i = 0; i < note_evs_.size (); i ++)
50     {
51       Stream_event *n = note_evs_[i];
52       SCM pit = n->get_property ("pitch");
53
54       if (Pitch *pitp = unsmob_pitch (pit))
55         {
56           SCM articulations = n->get_property ("articulations");
57           Stream_event *tie_event = 0;
58           for (SCM s = articulations;
59                !tie_event && scm_is_pair (s);
60                s = scm_cdr (s))
61             {
62               Stream_event *ev = unsmob_stream_event (scm_car (s));
63               if (!ev)
64                 continue;
65           
66               if (ev->in_event_class ("tie-event"))
67                 tie_event = ev;
68             }
69
70           Moment len = get_event_length (n, now_mom ());
71           
72           Audio_note *p = new Audio_note (*pitp, len, 
73                                           tie_event, transposing.negated ());
74           Audio_element_info info (p, n);
75           announce_element (info);
76           notes_.push_back (p);
77
78           /*
79             shorten previous note.
80            */
81           if (now_mom ().grace_part_)
82             {
83               if (last_start_.grace_part_ == Rational (0))
84                 {
85                   for (vsize i = 0; i < last_notes_.size (); i++)
86                     last_notes_[i]->length_mom_ += Moment (0,
87                                                            now_mom().grace_part_);
88                 }
89             }
90         }
91     }
92 }
93
94 void
95 Note_performer::stop_translation_timestep ()
96 {
97   if (note_evs_.size ())
98     {
99       last_notes_ = notes_;
100       last_start_ = now_mom ();
101     }
102
103   notes_.clear ();
104   note_evs_.clear ();
105 }
106
107 IMPLEMENT_TRANSLATOR_LISTENER (Note_performer, note)
108 void
109 Note_performer::listen_note (Stream_event *ev)
110 {
111   note_evs_.push_back (ev);
112 }
113
114 ADD_TRANSLATOR (Note_performer,
115                 /* doc */
116                 "",
117
118                 /* create */
119                 "",
120
121                 /* read */
122                 "",
123
124                 /* write */
125                 ""
126                 );
127
128 Note_performer::Note_performer ()
129 {
130 }