* lexer-gcc-3.1.sh: Remove.
[lilypond/patrick.git] / lily / drum-note-engraver.cc
blobc9dd52b8e6220bf41f8a21909d685c258769cae4
1 /*
2 drum-note-engraver.cc
4 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 */
7 #include <cctype>
8 using namespace std;
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"
16 #include "stem.hh"
17 #include "stream-event.hh"
18 #include "warn.hh"
20 #include "translator.icc"
22 class Drum_notes_engraver : public Engraver
24 vector<Item*> notes_;
25 vector<Item*> scripts_;
26 vector<Stream_event*> events_;
28 public:
29 TRANSLATOR_DECLARATIONS (Drum_notes_engraver);
31 protected:
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);
44 void
45 Drum_notes_engraver::listen_note (Stream_event *ev)
47 events_.push_back (ev);
50 void
51 Drum_notes_engraver::process_music ()
53 SCM tab = 0;
54 for (vsize i = 0; i < events_.size (); i++)
56 if (!tab)
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");
64 SCM defn = SCM_EOL;
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,
84 0);
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);
96 void
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 ());
110 void
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);
123 void
124 Drum_notes_engraver::stop_translation_timestep ()
126 notes_.clear ();
127 scripts_.clear ();
129 events_.clear ();
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.",
136 /* create */
137 "NoteHead "
138 "Script",
140 /* accept */ "note-event",
141 /* read */ "drumStyleTable",
142 /* write */ "");