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