]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-performer.cc
* python/midi.c (midi_parse_track): robustness: don't read past
[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               Audio_note *p = new Audio_note (*pitp, get_event_length (n), - transposing);
56               Audio_element_info info (p, n);
57               announce_element (info);
58               notes_.push_back (p);
59             }
60         }
61       note_evs_.clear ();
62     }
63 }
64
65 void
66 Note_performer::stop_translation_timestep ()
67 {
68   // why don't grace notes show up here?
69   // --> grace notes effectively do not get delayed
70   notes_.clear ();
71   note_evs_.clear ();
72 }
73
74 IMPLEMENT_TRANSLATOR_LISTENER (Note_performer, note)
75 void
76 Note_performer::listen_note (Stream_event *ev)
77 {
78   note_evs_.push_back (ev);
79 }
80
81 ADD_TRANSLATOR (Note_performer, "", "",
82                 "note-event ",
83                 "", "");
84
85 Note_performer::Note_performer ()
86 {
87 }