]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-performer.cc
Merge branch 'master' of ssh+git://gpercival@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 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);
71           if (now_mom ().grace_part_)
72             {
73               len.grace_part_ = len.main_part_;
74               len.main_part_ = Rational (0);
75             }
76           
77           Audio_note *p = new Audio_note (*pitp, len, 
78                                           tie_event, transposing.negated ());
79           Audio_element_info info (p, n);
80           announce_element (info);
81           notes_.push_back (p);
82
83           /*
84             shorten previous note.
85            */
86           if (now_mom ().grace_part_)
87             {
88               if (last_start_.grace_part_ == Rational (0))
89                 {
90                   for (vsize i = 0; i < last_notes_.size (); i++)
91                     last_notes_[i]->length_mom_ += Moment (0,
92                                                            now_mom().grace_part_);
93                 }
94             }
95         }
96     }
97 }
98
99 void
100 Note_performer::stop_translation_timestep ()
101 {
102   if (note_evs_.size ())
103     {
104       last_notes_ = notes_;
105       last_start_ = now_mom ();
106     }
107
108   notes_.clear ();
109   note_evs_.clear ();
110 }
111
112 IMPLEMENT_TRANSLATOR_LISTENER (Note_performer, note)
113 void
114 Note_performer::listen_note (Stream_event *ev)
115 {
116   note_evs_.push_back (ev);
117 }
118
119 ADD_TRANSLATOR (Note_performer, "", "",
120                 "", "");
121
122 Note_performer::Note_performer ()
123 {
124 }