4 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "duration.hh"
11 #include "engraver.hh"
12 #include "note-column.hh"
13 #include "rhythmic-head.hh"
14 #include "side-position-interface.hh"
15 #include "script-interface.hh"
17 #include "stream-event.hh"
20 #include "translator.icc"
22 class Drum_notes_engraver
: public Engraver
25 vector
<Item
*> scripts_
;
26 vector
<Stream_event
*> events_
;
29 TRANSLATOR_DECLARATIONS (Drum_notes_engraver
);
32 void process_music ();
33 DECLARE_ACKNOWLEDGER (stem
);
34 DECLARE_ACKNOWLEDGER (note_column
);
35 DECLARE_TRANSLATOR_LISTENER (note
);
36 void stop_translation_timestep ();
39 Drum_notes_engraver::Drum_notes_engraver ()
43 IMPLEMENT_TRANSLATOR_LISTENER (Drum_notes_engraver
, note
);
45 Drum_notes_engraver::listen_note (Stream_event
*ev
)
47 events_
.push_back (ev
);
51 Drum_notes_engraver::process_music ()
54 for (vsize i
= 0; i
< events_
.size (); i
++)
57 tab
= get_property ("drumStyleTable");
59 Stream_event
*ev
= events_
[i
];
60 Item
*note
= make_item ("NoteHead", ev
->self_scm ());
62 SCM drum_type
= ev
->get_property ("drum-type");
66 if (scm_hash_table_p (tab
) == SCM_BOOL_T
)
67 defn
= scm_hashq_ref (tab
, drum_type
, SCM_EOL
);
69 if (scm_is_pair (defn
))
71 SCM pos
= scm_caddr (defn
);
72 SCM style
= scm_car (defn
);
73 SCM script
= scm_cadr (defn
);
75 if (scm_integer_p (pos
) == SCM_BOOL_T
)
76 note
->set_property ("staff-position", pos
);
77 if (scm_is_symbol (style
))
78 note
->set_property ("style", style
);
80 if (scm_is_string (script
))
82 Item
*p
= make_item ("Script", ev
->self_scm ());
83 make_script_from_event (p
, context (), script
,
86 p
->set_parent (note
, Y_AXIS
);
87 Side_position_interface::add_support (p
, note
);
88 scripts_
.push_back (p
);
92 notes_
.push_back (note
);
97 Drum_notes_engraver::acknowledge_stem (Grob_info inf
)
99 for (vsize i
= 0; i
< scripts_
.size (); i
++)
101 Grob
*e
= scripts_
[i
];
103 if (to_dir (e
->get_property ("side-relative-direction")))
104 e
->set_object ("direction-source", inf
.grob ()->self_scm ());
106 Side_position_interface::add_support (e
, inf
.grob ());
111 Drum_notes_engraver::acknowledge_note_column (Grob_info inf
)
113 for (vsize i
= 0; i
< scripts_
.size (); i
++)
115 Grob
*e
= scripts_
[i
];
117 if (!e
->get_parent (X_AXIS
)
118 && Side_position_interface::get_axis (e
) == Y_AXIS
)
119 e
->set_parent (inf
.grob (), X_AXIS
);
124 Drum_notes_engraver::stop_translation_timestep ()
132 ADD_ACKNOWLEDGER (Drum_notes_engraver
, stem
);
133 ADD_ACKNOWLEDGER (Drum_notes_engraver
, note_column
);
134 ADD_TRANSLATOR (Drum_notes_engraver
,
135 /* doc */ "Generate noteheads.",
140 /* accept */ "note-event",
141 /* read */ "drumStyleTable",