]> git.donarmstrong.com Git - lilypond.git/blob - lily/drum-note-performer.cc
3bb56ccabaf0d0c6f8d80ef6933314bf456083ba
[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--2004 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   Link_array<Audio_note> delayeds_;
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   Global_context * global = get_global_context ();
64   for (int i = 0; i < notes_.size (); i++)
65     {
66       Audio_note* n = notes_[i];
67       Moment m = n->delayed_until_mom_;
68       if (m.to_bool ())
69         {
70           global->add_moment_to_process (m);
71           delayeds_.push (n);
72           notes_[i] = 0;
73           notes_.del (i);
74           i--;
75         }
76     }
77
78   Moment now = now_mom ();
79   for (int i = 0; i < notes_.size (); i++)
80     {
81       play_element (notes_[i]);
82     }
83   notes_.clear ();
84   note_evs_.clear ();
85   for (int i = 0; i < delayeds_.size (); i++)
86     {
87       Audio_note* n = delayeds_[i];
88       if (n->delayed_until_mom_ <= now)
89         {
90           play_element (n);
91           delayeds_[i] = 0;
92           delayeds_.del (i);
93           i--;
94         }
95     }
96 }
97  
98 bool
99 Drum_note_performer::try_music (Music* ev)
100 {
101   if (ev->is_mus_type ("note-event"))
102     {
103       note_evs_.push (ev);
104       return true;
105     }
106   else if (ev->is_mus_type ("busy-playing-event"))
107     return note_evs_.size ();
108   
109   return false;
110 }
111
112 ADD_TRANSLATOR (Drum_note_performer,
113                   "Play drum notes.","",
114                   "note-event busy-playing-event","","","");
115
116 Drum_note_performer::Drum_note_performer ()
117 {
118 }