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