]> git.donarmstrong.com Git - lilypond.git/blob - lily/drum-note-performer.cc
* lily/include/event.hh: remove file.
[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--2005 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 "warn.hh"
14 #include "pitch.hh"
15 #include "music.hh"
16
17 class Drum_note_performer : public Performer
18 {
19 public:
20   TRANSLATOR_DECLARATIONS (Drum_note_performer);
21
22 protected:
23   virtual bool try_music (Music *ev);
24   virtual void stop_translation_timestep ();
25   virtual void create_audio_elements ();
26
27 private:
28   Link_array<Music> note_evs_;
29   Link_array<Audio_note> notes_;
30 };
31
32 void
33 Drum_note_performer::create_audio_elements ()
34 {
35   SCM tab = 0;
36   if (!tab) tab = get_property ("drumPitchTable");
37
38   while (note_evs_.size ())
39     {
40       Music *n = note_evs_.pop ();
41       SCM sym = n->get_property ("drum-type");
42       SCM defn = SCM_EOL;
43
44       if (scm_is_symbol (sym)
45           && (scm_hash_table_p (tab) == SCM_BOOL_T))
46         defn = scm_hashq_ref (tab, sym, SCM_EOL);
47
48       if (Pitch *pit = unsmob_pitch (defn))
49         {
50           Audio_note *p = new Audio_note (*pit, n->get_length (), 0);
51           Audio_element_info info (p, n);
52           announce_element (info);
53           notes_.push (p);
54         }
55     }
56
57   note_evs_.clear ();
58 }
59
60 void
61 Drum_note_performer::stop_translation_timestep ()
62 {
63   // why don't grace notes show up here?
64   // --> grace notes effectively do not get delayed
65   Moment now = now_mom ();
66   for (int i = 0; i < notes_.size (); i++)
67     {
68       play_element (notes_[i]);
69     }
70   notes_.clear ();
71   note_evs_.clear ();
72 }
73
74 bool
75 Drum_note_performer::try_music (Music *ev)
76 {
77   if (ev->is_mus_type ("note-event"))
78     {
79       note_evs_.push (ev);
80       return true;
81     }
82   else if (ev->is_mus_type ("busy-playing-event"))
83     return note_evs_.size ();
84
85   return false;
86 }
87
88 ADD_TRANSLATOR (Drum_note_performer,
89                 "Play drum notes.", "",
90                 "note-event busy-playing-event", "", "", "");
91
92 Drum_note_performer::Drum_note_performer ()
93 {
94 }