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