4 (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
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"
18 #include "stream-event.hh"
21 #include "translator.icc"
23 class Drum_notes_engraver
: public Engraver
26 vector
<Item
*> scripts_
;
27 vector
<Stream_event
*> events_
;
30 TRANSLATOR_DECLARATIONS (Drum_notes_engraver
);
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
);
46 Drum_notes_engraver::listen_note (Stream_event
*ev
)
48 events_
.push_back (ev
);
52 Drum_notes_engraver::process_music ()
55 for (vsize i
= 0; i
< events_
.size (); i
++)
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");
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
,
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
);
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 ());
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
);
125 Drum_notes_engraver::stop_translation_timestep ()
133 ADD_ACKNOWLEDGER (Drum_notes_engraver
, stem
);
134 ADD_ACKNOWLEDGER (Drum_notes_engraver
, note_column
);
137 ADD_TRANSLATOR (Drum_notes_engraver
,
139 "Generate drum note heads.",