]> git.donarmstrong.com Git - lilypond.git/blob - lily/drum-note-engraver.cc
Issue 4550 (2/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / drum-note-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
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 <cctype>
21
22 #include "item.hh"
23 #include "duration.hh"
24 #include "engraver.hh"
25 #include "note-column.hh"
26 #include "rhythmic-head.hh"
27 #include "side-position-interface.hh"
28 #include "script-interface.hh"
29 #include "stem.hh"
30 #include "stream-event.hh"
31 #include "warn.hh"
32
33 #include "translator.icc"
34
35 using std::vector;
36
37 class Drum_notes_engraver : public Engraver
38 {
39   vector<Item *> scripts_;
40   vector<Stream_event *> events_;
41
42 public:
43   TRANSLATOR_DECLARATIONS (Drum_notes_engraver);
44
45 protected:
46   void process_music ();
47   DECLARE_ACKNOWLEDGER (stem);
48   DECLARE_ACKNOWLEDGER (note_column);
49   DECLARE_TRANSLATOR_LISTENER (note);
50   void stop_translation_timestep ();
51 };
52
53 Drum_notes_engraver::Drum_notes_engraver ()
54 {
55 }
56
57 IMPLEMENT_TRANSLATOR_LISTENER (Drum_notes_engraver, note);
58 void
59 Drum_notes_engraver::listen_note (Stream_event *ev)
60 {
61   events_.push_back (ev);
62 }
63
64 void
65 Drum_notes_engraver::process_music ()
66 {
67   SCM tab = 0;
68   for (vsize i = 0; i < events_.size (); i++)
69     {
70       if (!tab)
71         tab = get_property ("drumStyleTable");
72
73       Stream_event *ev = events_[i];
74       Item *note = make_item ("NoteHead", ev->self_scm ());
75
76       SCM drum_type = ev->get_property ("drum-type");
77
78       SCM defn = SCM_EOL;
79
80       if (to_boolean (scm_hash_table_p (tab)))
81         defn = scm_hashq_ref (tab, drum_type, SCM_EOL);
82
83       if (scm_is_pair (defn))
84         {
85           SCM pos = scm_caddr (defn);
86           SCM style = scm_car (defn);
87           SCM script = scm_cadr (defn);
88
89           if (scm_is_integer (pos))
90             note->set_property ("staff-position", pos);
91           if (scm_is_symbol (style))
92             note->set_property ("style", style);
93
94           if (scm_is_string (script))
95             {
96               Item *p = make_item ("Script", ev->self_scm ());
97               make_script_from_event (p, context (), script,
98                                       0);
99
100               p->set_parent (note, Y_AXIS);
101               Side_position_interface::add_support (p, note);
102               scripts_.push_back (p);
103             }
104         }
105     }
106 }
107
108 void
109 Drum_notes_engraver::acknowledge_stem (Grob_info inf)
110 {
111   for (vsize i = 0; i < scripts_.size (); i++)
112     {
113       Grob *e = scripts_[i];
114
115       if (to_dir (e->get_property ("side-relative-direction")))
116         e->set_object ("direction-source", inf.grob ()->self_scm ());
117
118       Side_position_interface::add_support (e, inf.grob ());
119     }
120 }
121
122 void
123 Drum_notes_engraver::acknowledge_note_column (Grob_info inf)
124 {
125   for (vsize i = 0; i < scripts_.size (); i++)
126     {
127       Grob *e = scripts_[i];
128
129       if (!e->get_parent (X_AXIS)
130           && Side_position_interface::get_axis (e) == Y_AXIS)
131         e->set_parent (inf.grob (), X_AXIS);
132
133       Side_position_interface::add_support (e, inf.grob ());
134     }
135 }
136
137 void
138 Drum_notes_engraver::stop_translation_timestep ()
139 {
140   scripts_.clear ();
141   events_.clear ();
142 }
143
144 ADD_ACKNOWLEDGER (Drum_notes_engraver, stem);
145 ADD_ACKNOWLEDGER (Drum_notes_engraver, note_column);
146
147 ADD_TRANSLATOR (Drum_notes_engraver,
148                 /* doc */
149                 "Generate drum note heads.",
150
151                 /* create */
152                 "NoteHead "
153                 "Script ",
154
155                 /* read */
156                 "drumStyleTable ",
157
158                 /* write */
159                 ""
160                );