]> git.donarmstrong.com Git - lilypond.git/blob - lily/drum-note-performer.cc
*** empty log message ***
[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--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 "music.hh"
14 #include "pitch.hh"
15 #include "stream-event.hh"
16 #include "translator.icc"
17 #include "warn.hh"
18
19 class Drum_note_performer : public Performer
20 {
21 public:
22   TRANSLATOR_DECLARATIONS (Drum_note_performer);
23
24 protected:
25   void stop_translation_timestep ();
26   void process_music ();
27   DECLARE_TRANSLATOR_LISTENER (note);
28 private:
29   vector<Stream_event*> note_evs_;
30   vector<Audio_note*> notes_;
31 };
32
33 Drum_note_performer::Drum_note_performer ()
34 {
35 }
36
37 void
38 Drum_note_performer::process_music ()
39 {
40   SCM tab = get_property ("drumPitchTable");
41
42   while (note_evs_.size ())
43     {
44       Stream_event *n = note_evs_.back ();
45       note_evs_.pop_back ();
46       SCM sym = n->get_property ("drum-type");
47       SCM defn = SCM_EOL;
48
49       if (scm_is_symbol (sym)
50           && (scm_hash_table_p (tab) == SCM_BOOL_T))
51         defn = scm_hashq_ref (tab, sym, SCM_EOL);
52
53       if (Pitch *pit = unsmob_pitch (defn))
54         {
55           SCM articulations = n->get_property ("articulations");
56           Music *tie_event = 0;
57           for (SCM s = articulations;
58                !tie_event && scm_is_pair (s);
59                s = scm_cdr (s))
60             {
61               Music *m = unsmob_music (scm_car (s));
62               if (!m)
63                 continue;
64           
65               if (m->is_mus_type ("tie-event"))
66                 tie_event = m;
67             }
68
69           Audio_note *p = new Audio_note (*pit, get_event_length (n), 
70                                           tie_event, 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                 "Play drum notes.", "",
96                 "note-event", "", "");