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