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