]> git.donarmstrong.com Git - lilypond.git/blob - lily/drum-note-engraver.cc
* lily/include/grob-info.hh (class Grob_info): make data member
[lilypond.git] / lily / drum-note-engraver.cc
1 /*
2   drum-note-engraver.cc
3
4   (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
5 */
6
7 #include <cctype>
8
9 #include "rhythmic-head.hh"
10 #include "engraver.hh"
11 #include "warn.hh"
12 #include "side-position-interface.hh"
13 #include "script-interface.hh"
14 #include "stem.hh"
15 #include "note-column.hh"
16
17 class Drum_notes_engraver : public Engraver
18 {
19   Link_array<Item> notes_;
20   Link_array<Item> dots_;
21   Link_array<Item> scripts_;
22   Link_array<Music> events_;
23
24 public:
25   TRANSLATOR_DECLARATIONS (Drum_notes_engraver);
26
27 protected:
28   virtual bool try_music (Music *ev);
29   virtual void process_music ();
30   virtual void acknowledge_grob (Grob_info);
31   virtual void stop_translation_timestep ();
32 };
33
34 Drum_notes_engraver::Drum_notes_engraver ()
35 {
36 }
37
38 bool
39 Drum_notes_engraver::try_music (Music *m)
40 {
41   if (m->is_mus_type ("note-event"))
42     {
43       events_.push (m);
44       return true;
45     }
46   else if (m->is_mus_type ("busy-playing-event"))
47     return events_.size ();
48
49   return false;
50 }
51
52 void
53 Drum_notes_engraver::process_music ()
54 {
55   SCM tab = 0;
56   for (int i = 0; i < events_.size (); i++)
57     {
58       if (!tab)
59         tab = get_property ("drumStyleTable");
60
61       Music *ev = events_[i];
62       Item *note = make_item ("NoteHead", ev->self_scm ());
63
64       Duration dur = *unsmob_duration (ev->get_property ("duration"));
65
66       note->set_property ("duration-log", scm_int2num (dur.duration_log ()));
67
68       if (dur.dot_count ())
69         {
70           Item *d = make_item ("Dots", ev->self_scm ());
71           Rhythmic_head::set_dots (note, d);
72
73           if (dur.dot_count ()
74               != robust_scm2int (d->get_property ("dot-count"), 0))
75             d->set_property ("dot-count", scm_int2num (dur.dot_count ()));
76
77           d->set_parent (note, Y_AXIS);
78
79           dots_.push (d);
80         }
81
82       SCM drum_type = ev->get_property ("drum-type");
83
84       SCM defn = SCM_EOL;
85
86       if (scm_hash_table_p (tab) == SCM_BOOL_T)
87         defn = scm_hashq_ref (tab, drum_type, SCM_EOL);
88
89       if (scm_is_pair (defn))
90         {
91           SCM pos = scm_caddr (defn);
92           SCM style = scm_car (defn);
93           SCM script = scm_cadr (defn);
94
95           if (scm_integer_p (pos) == SCM_BOOL_T)
96             note->set_property ("staff-position", pos);
97           if (scm_is_symbol (style))
98             note->set_property ("style", style);
99
100           if (scm_is_string (script))
101             {
102               Item *p = make_item ("Script", ev->self_scm ());
103               bool follow;
104               make_script_from_event (p, &follow,
105                                       context (), script,
106                                       0);
107
108               if (p->get_property ("follow-into-staff"))
109                 p->set_property ("staff-padding", SCM_EOL);
110
111               p->set_parent (note, Y_AXIS);
112               Side_position_interface::add_support (p, note);
113               scripts_.push (p);
114             }
115         }
116
117       notes_.push (note);
118     }
119 }
120
121 void
122 Drum_notes_engraver::acknowledge_grob (Grob_info inf)
123 {
124   if (Stem::has_interface (inf.grob ()))
125     {
126       for (int i = 0; i < scripts_.size (); i++)
127         {
128           Grob *e = scripts_[i];
129
130           if (to_dir (e->get_property ("side-relative-direction")))
131             e->set_property ("direction-source", inf.grob ()->self_scm ());
132
133           /*
134             add dep ?
135           */
136           e->add_dependency (inf.grob ());
137           Side_position_interface::add_support (e, inf.grob ());
138         }
139     }
140   else if (Note_column::has_interface (inf.grob ()))
141     {
142       for (int i = 0; i < scripts_.size (); i++)
143         {
144           Grob *e = scripts_[i];
145
146           if (!e->get_parent (X_AXIS)
147               && Side_position_interface::get_axis (e) == Y_AXIS)
148             {
149               e->set_parent (inf.grob (), X_AXIS);
150             }
151         }
152     }
153 }
154
155 void
156 Drum_notes_engraver::stop_translation_timestep ()
157 {
158   notes_.clear ();
159   dots_.clear ();
160   scripts_.clear ();
161
162   events_.clear ();
163 }
164
165 ADD_TRANSLATOR (Drum_notes_engraver,
166                 /* descr */ "Generate noteheads.",
167                 /* creats*/ "NoteHead Dots Script",
168                 /* accepts */ "note-event busy-playing-event",
169                 /* acks  */ "stem-interface note-column-interface",
170                 /* reads */ "drumStyleTable",
171                 /* write */ "");
172