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