]> git.donarmstrong.com Git - lilypond.git/blob - lily/drum-note-performer.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / drum-note-performer.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1996--2015 Jan Nieuwenhuizen <janneke@gnu.org>
5
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.
10
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.
15
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/>.
18 */
19
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"
27
28 using std::vector;
29
30 class Drum_note_performer : public Performer
31 {
32 public:
33   TRANSLATOR_DECLARATIONS (Drum_note_performer);
34
35 protected:
36   void stop_translation_timestep ();
37   void process_music ();
38   DECLARE_TRANSLATOR_LISTENER (note);
39 private:
40   vector<Stream_event *> note_evs_;
41 };
42
43 Drum_note_performer::Drum_note_performer ()
44 {
45 }
46
47 void
48 Drum_note_performer::process_music ()
49 {
50   SCM tab = get_property ("drumPitchTable");
51
52   while (note_evs_.size ())
53     {
54       Stream_event *n = note_evs_.back ();
55       note_evs_.pop_back ();
56       SCM sym = n->get_property ("drum-type");
57       SCM defn = SCM_EOL;
58
59       if (scm_is_symbol (sym)
60           && to_boolean (scm_hash_table_p (tab)))
61         defn = scm_hashq_ref (tab, sym, SCM_EOL);
62
63       if (Pitch *pit = unsmob<Pitch> (defn))
64         {
65           SCM articulations = n->get_property ("articulations");
66           Stream_event *tie_event = 0;
67           Moment len = get_event_length (n, now_mom ());
68           int velocity = 0;
69           for (SCM s = articulations; scm_is_pair (s); s = scm_cdr (s))
70             {
71               Stream_event *ev = unsmob<Stream_event> (scm_car (s));
72               if (!ev)
73                 continue;
74
75               if (ev->in_event_class ("tie-event"))
76                 tie_event = ev;
77               SCM f = ev->get_property ("midi-length");
78               if (ly_is_procedure (f))
79                 len = robust_scm2moment (scm_call_2 (f, len.smobbed_copy (),
80                                                      context ()->self_scm ()),
81                                          len);
82               velocity += robust_scm2int (ev->get_property ("midi-extra-velocity"), 0);
83             }
84
85           Audio_note *p = new Audio_note (*pit, len,
86                                           tie_event, Pitch (0, 0), velocity);
87           Audio_element_info info (p, n);
88           announce_element (info);
89         }
90     }
91
92   note_evs_.clear ();
93 }
94
95 void
96 Drum_note_performer::stop_translation_timestep ()
97 {
98   note_evs_.clear ();
99 }
100
101 IMPLEMENT_TRANSLATOR_LISTENER (Drum_note_performer, note);
102 void
103 Drum_note_performer::listen_note (Stream_event *ev)
104 {
105   note_evs_.push_back (ev);
106 }
107
108 ADD_TRANSLATOR (Drum_note_performer,
109                 /* doc */
110                 "Play drum notes.",
111
112                 /* create */
113                 "",
114
115                 /* read */
116                 "",
117
118                 /* write */
119                 ""
120                );