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