Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / drum-note-engraver.cc
blob1309f448d3c18cc7e806f0c6b4d3df3e709021c4
1 /*
2 drum-note-engraver.cc
4 (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 */
7 #include <cctype>
8 using namespace std;
10 #include "item.hh"
11 #include "duration.hh"
12 #include "engraver.hh"
13 #include "note-column.hh"
14 #include "rhythmic-head.hh"
15 #include "side-position-interface.hh"
16 #include "script-interface.hh"
17 #include "stem.hh"
18 #include "stream-event.hh"
19 #include "warn.hh"
21 #include "translator.icc"
23 class Drum_notes_engraver : public Engraver
25 vector<Item*> notes_;
26 vector<Item*> scripts_;
27 vector<Stream_event*> events_;
29 public:
30 TRANSLATOR_DECLARATIONS (Drum_notes_engraver);
32 protected:
33 void process_music ();
34 DECLARE_ACKNOWLEDGER (stem);
35 DECLARE_ACKNOWLEDGER (note_column);
36 DECLARE_TRANSLATOR_LISTENER (note);
37 void stop_translation_timestep ();
40 Drum_notes_engraver::Drum_notes_engraver ()
44 IMPLEMENT_TRANSLATOR_LISTENER (Drum_notes_engraver, note);
45 void
46 Drum_notes_engraver::listen_note (Stream_event *ev)
48 events_.push_back (ev);
51 void
52 Drum_notes_engraver::process_music ()
54 SCM tab = 0;
55 for (vsize i = 0; i < events_.size (); i++)
57 if (!tab)
58 tab = get_property ("drumStyleTable");
60 Stream_event *ev = events_[i];
61 Item *note = make_item ("NoteHead", ev->self_scm ());
63 SCM drum_type = ev->get_property ("drum-type");
65 SCM defn = SCM_EOL;
67 if (scm_hash_table_p (tab) == SCM_BOOL_T)
68 defn = scm_hashq_ref (tab, drum_type, SCM_EOL);
70 if (scm_is_pair (defn))
72 SCM pos = scm_caddr (defn);
73 SCM style = scm_car (defn);
74 SCM script = scm_cadr (defn);
76 if (scm_integer_p (pos) == SCM_BOOL_T)
77 note->set_property ("staff-position", pos);
78 if (scm_is_symbol (style))
79 note->set_property ("style", style);
81 if (scm_is_string (script))
83 Item *p = make_item ("Script", ev->self_scm ());
84 make_script_from_event (p, context (), script,
85 0);
87 p->set_parent (note, Y_AXIS);
88 Side_position_interface::add_support (p, note);
89 scripts_.push_back (p);
93 notes_.push_back (note);
97 void
98 Drum_notes_engraver::acknowledge_stem (Grob_info inf)
100 for (vsize i = 0; i < scripts_.size (); i++)
102 Grob *e = scripts_[i];
104 if (to_dir (e->get_property ("side-relative-direction")))
105 e->set_object ("direction-source", inf.grob ()->self_scm ());
107 Side_position_interface::add_support (e, inf.grob ());
111 void
112 Drum_notes_engraver::acknowledge_note_column (Grob_info inf)
114 for (vsize i = 0; i < scripts_.size (); i++)
116 Grob *e = scripts_[i];
118 if (!e->get_parent (X_AXIS)
119 && Side_position_interface::get_axis (e) == Y_AXIS)
120 e->set_parent (inf.grob (), X_AXIS);
124 void
125 Drum_notes_engraver::stop_translation_timestep ()
127 notes_.clear ();
128 scripts_.clear ();
130 events_.clear ();
133 ADD_ACKNOWLEDGER (Drum_notes_engraver, stem);
134 ADD_ACKNOWLEDGER (Drum_notes_engraver, note_column);
137 ADD_TRANSLATOR (Drum_notes_engraver,
138 /* doc */
139 "Generate drum note heads.",
141 /* create */
142 "NoteHead "
143 "Script ",
145 /* read */
146 "drumStyleTable ",
148 /* write */