]> git.donarmstrong.com Git - lilypond.git/blob - lily/drum-note-performer.cc
* lily/context.cc (where_defined): also assign value in
[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   PRECOMPUTED_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
33 Drum_note_performer::Drum_note_performer ()
34 {
35 }
36
37 void
38 Drum_note_performer::create_audio_elements ()
39 {
40   SCM tab = 0;
41   if (!tab) tab = get_property ("drumPitchTable");
42
43   while (note_evs_.size ())
44     {
45       Music *n = note_evs_.pop ();
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           Audio_note *p = new Audio_note (*pit, n->get_length (), 0);
56           Audio_element_info info (p, n);
57           announce_element (info);
58           notes_.push (p);
59         }
60     }
61
62   note_evs_.clear ();
63 }
64
65 void
66 Drum_note_performer::stop_translation_timestep ()
67 {
68   // why don't grace notes show up here?
69   // --> grace notes effectively do not get delayed
70   Moment now = now_mom ();
71   for (int i = 0; i < notes_.size (); i++)
72     {
73       play_element (notes_[i]);
74     }
75   notes_.clear ();
76   note_evs_.clear ();
77 }
78
79 bool
80 Drum_note_performer::try_music (Music *ev)
81 {
82   if (ev->is_mus_type ("note-event"))
83     {
84       note_evs_.push (ev);
85       return true;
86     }
87   else if (ev->is_mus_type ("busy-playing-event"))
88     return note_evs_.size ();
89
90   return false;
91 }
92
93 #include "translator.icc"
94
95 ADD_TRANSLATOR (Drum_note_performer,
96                 "Play drum notes.", "",
97                 "note-event busy-playing-event", "", "");