]> git.donarmstrong.com Git - lilypond.git/blob - lily/drum-note-performer.cc
Patch for auto-beam; Fix issue 511
[lilypond.git] / lily / drum-note-performer.cc
1 /*
2   note-performer.cc -- implement Drum_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 "translator.icc"
15 #include "warn.hh"
16
17 class Drum_note_performer : public Performer
18 {
19 public:
20   TRANSLATOR_DECLARATIONS (Drum_note_performer);
21
22 protected:
23   void stop_translation_timestep ();
24   void process_music ();
25   DECLARE_TRANSLATOR_LISTENER (note);
26 private:
27   vector<Stream_event*> note_evs_;
28   vector<Audio_note*> notes_;
29 };
30
31 Drum_note_performer::Drum_note_performer ()
32 {
33 }
34
35 void
36 Drum_note_performer::process_music ()
37 {
38   SCM tab = get_property ("drumPitchTable");
39
40   while (note_evs_.size ())
41     {
42       Stream_event *n = note_evs_.back ();
43       note_evs_.pop_back ();
44       SCM sym = n->get_property ("drum-type");
45       SCM defn = SCM_EOL;
46
47       if (scm_is_symbol (sym)
48           && (scm_hash_table_p (tab) == SCM_BOOL_T))
49         defn = scm_hashq_ref (tab, sym, SCM_EOL);
50
51       if (Pitch *pit = unsmob_pitch (defn))
52         {
53           SCM articulations = n->get_property ("articulations");
54           Stream_event *tie_event = 0;
55           for (SCM s = articulations;
56                !tie_event && scm_is_pair (s);
57                s = scm_cdr (s))
58             {
59               Stream_event *ev = unsmob_stream_event (scm_car (s));
60               if (!ev)
61                 continue;
62           
63               if (ev->in_event_class ("tie-event"))
64                 tie_event = ev;
65             }
66
67           Moment len = get_event_length (n, now_mom ());
68
69           Audio_note *p = new Audio_note (*pit, len,
70                                           tie_event, Pitch (0, 0, 0));
71           Audio_element_info info (p, n);
72           announce_element (info);
73           notes_.push_back (p);
74         }
75     }
76
77   note_evs_.clear ();
78 }
79
80 void
81 Drum_note_performer::stop_translation_timestep ()
82 {
83   notes_.clear ();
84   note_evs_.clear ();
85 }
86
87 IMPLEMENT_TRANSLATOR_LISTENER (Drum_note_performer, note);
88 void
89 Drum_note_performer::listen_note (Stream_event *ev)
90 {
91   note_evs_.push_back (ev);
92 }
93
94 ADD_TRANSLATOR (Drum_note_performer,
95                 /* doc */
96                 "Play drum notes.",
97
98                 /* create */
99                 "",
100
101                 /* read */
102                 "",
103
104                 /* write */
105                 ""
106                 );