Merge branch 'master' of git.sv.gnu.org:/srv/git/lilypond
[lilypond/mpolesky.git] / lily / drum-note-performer.cc
blobcda5f12d674d871d900a0d90e22106241f1a2b58
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1996--2010 Jan Nieuwenhuizen <janneke@gnu.org>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "performer.hh"
21 #include "audio-item.hh"
22 #include "audio-column.hh"
23 #include "global-context.hh"
24 #include "stream-event.hh"
25 #include "translator.icc"
26 #include "warn.hh"
28 class Drum_note_performer : public Performer
30 public:
31 TRANSLATOR_DECLARATIONS (Drum_note_performer);
33 protected:
34 void stop_translation_timestep ();
35 void process_music ();
36 DECLARE_TRANSLATOR_LISTENER (note);
37 private:
38 vector<Stream_event*> note_evs_;
39 vector<Audio_note*> notes_;
42 Drum_note_performer::Drum_note_performer ()
46 void
47 Drum_note_performer::process_music ()
49 SCM tab = get_property ("drumPitchTable");
51 while (note_evs_.size ())
53 Stream_event *n = note_evs_.back ();
54 note_evs_.pop_back ();
55 SCM sym = n->get_property ("drum-type");
56 SCM defn = SCM_EOL;
58 if (scm_is_symbol (sym)
59 && (scm_hash_table_p (tab) == SCM_BOOL_T))
60 defn = scm_hashq_ref (tab, sym, SCM_EOL);
62 if (Pitch *pit = unsmob_pitch (defn))
64 SCM articulations = n->get_property ("articulations");
65 Stream_event *tie_event = 0;
66 for (SCM s = articulations;
67 !tie_event && scm_is_pair (s);
68 s = scm_cdr (s))
70 Stream_event *ev = unsmob_stream_event (scm_car (s));
71 if (!ev)
72 continue;
74 if (ev->in_event_class ("tie-event"))
75 tie_event = ev;
78 Moment len = get_event_length (n, now_mom ());
80 Audio_note *p = new Audio_note (*pit, len,
81 tie_event, Pitch (0, 0, 0));
82 Audio_element_info info (p, n);
83 announce_element (info);
84 notes_.push_back (p);
88 note_evs_.clear ();
91 void
92 Drum_note_performer::stop_translation_timestep ()
94 notes_.clear ();
95 note_evs_.clear ();
98 IMPLEMENT_TRANSLATOR_LISTENER (Drum_note_performer, note);
99 void
100 Drum_note_performer::listen_note (Stream_event *ev)
102 note_evs_.push_back (ev);
105 ADD_TRANSLATOR (Drum_note_performer,
106 /* doc */
107 "Play drum notes.",
109 /* create */
112 /* read */
115 /* write */