]> git.donarmstrong.com Git - lilypond.git/blob - lily/drum-note-performer.cc
Fix some bugs in the dynamic engraver and PostScript backend
[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--2006 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   void stop_translation_timestep ();
25   void process_music ();
26
27 private:
28   vector<Music*> note_evs_;
29   vector<Audio_note*> notes_;
30 };
31
32 Drum_note_performer::Drum_note_performer ()
33 {
34 }
35
36 void
37 Drum_note_performer::process_music ()
38 {
39   SCM tab = get_property ("drumPitchTable");
40
41   while (note_evs_.size ())
42     {
43       Music *n = note_evs_.back ();
44       note_evs_.pop_back ();
45       SCM sym = n->get_property ("drum-type");
46       SCM defn = SCM_EOL;
47
48       if (scm_is_symbol (sym)
49           && (scm_hash_table_p (tab) == SCM_BOOL_T))
50         defn = scm_hashq_ref (tab, sym, SCM_EOL);
51
52       if (Pitch *pit = unsmob_pitch (defn))
53         {
54           Audio_note *p = new Audio_note (*pit, n->get_length (), 0);
55           Audio_element_info info (p, n);
56           announce_element (info);
57           notes_.push_back (p);
58         }
59     }
60
61   note_evs_.clear ();
62 }
63
64 void
65 Drum_note_performer::stop_translation_timestep ()
66 {
67   // why don't grace notes show up here?
68   // --> grace notes effectively do not get delayed
69   Moment now = now_mom ();
70   for (vsize i = 0; i < notes_.size (); i++)
71     play_element (notes_[i]);
72   notes_.clear ();
73   note_evs_.clear ();
74 }
75
76 bool
77 Drum_note_performer::try_music (Music *ev)
78 {
79   if (ev->is_mus_type ("note-event"))
80     {
81       note_evs_.push_back (ev);
82       return true;
83     }
84   else if (ev->is_mus_type ("busy-playing-event"))
85     return note_evs_.size ();
86
87   return false;
88 }
89
90 #include "translator.icc"
91
92 ADD_TRANSLATOR (Drum_note_performer,
93                 "Play drum notes.", "",
94                 "note-event busy-playing-event", "", "");