]> git.donarmstrong.com Git - lilypond.git/blob - lily/drum-note-engraver.cc
*** empty log message ***
[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
53 void
54 Drum_notes_engraver::process_music ()
55 {
56   SCM tab = 0;
57   for (int i = 0; i < events_.size (); i++)
58     {
59       if (!tab)
60         tab = get_property ("drumStyleTable");
61       
62       Music * ev = events_[i];
63       Item *note = make_item ("NoteHead", ev->self_scm ());
64       
65       Duration dur = *unsmob_duration (ev->get_property ("duration"));
66
67       note->set_property ("duration-log", scm_int2num (dur.duration_log ()));
68
69       if (dur.dot_count ())
70         {
71           Item * d = make_item ("Dots", ev->self_scm ());
72           Rhythmic_head::set_dots (note, d);
73           
74           if (dur.dot_count ()
75               != robust_scm2int (d->get_property ("dot-count"), 0))
76             d->set_property ("dot-count", scm_int2num (dur.dot_count ()));
77
78           d->set_parent (note, Y_AXIS);
79           
80           dots_.push (d);
81         }
82
83       SCM drum_type =  ev->get_property ("drum-type");
84
85       SCM defn = SCM_EOL;
86
87       if (scm_hash_table_p (tab) == SCM_BOOL_T)
88         defn = scm_hashq_ref (tab, drum_type, SCM_EOL);
89       
90       if (scm_is_pair (defn))
91         {
92           SCM pos = scm_caddr (defn);
93           SCM style = scm_car (defn);
94           SCM script = scm_cadr (defn);
95           
96           if (scm_integer_p (pos) == SCM_BOOL_T)
97             note->set_property ("staff-position", pos);
98           if (scm_is_symbol (style))
99             note->set_property ("style", style);
100
101           if (scm_is_string (script))
102             {
103               Item *p  = make_item ("Script", ev->self_scm ());
104               bool follow;
105               make_script_from_event (p, &follow,
106                                       context (), script,
107                                       0);
108
109               if (p->get_property ("follow-into-staff"))
110                 p->set_property ("staff-padding", SCM_EOL);
111               
112
113               p->set_parent (note, Y_AXIS);
114               Side_position_interface::add_support (p, note); 
115               scripts_.push (p);
116             }
117         }
118
119       notes_.push (note);
120     }
121 }
122
123 void
124 Drum_notes_engraver::acknowledge_grob (Grob_info inf)
125 {
126   if (Stem::has_interface (inf.grob_))
127     {
128       for (int i = 0; i < scripts_.size (); i++)
129         {
130           Grob*e = scripts_[i];
131
132           if (to_dir (e->get_property ("side-relative-direction")))
133             e->set_property ("direction-source", inf.grob_->self_scm ());
134
135           /*
136             add dep ? 
137            */
138           e->add_dependency (inf.grob_);
139           Side_position_interface::add_support (e, inf.grob_);
140         }
141     }
142    else if (Note_column::has_interface (inf.grob_))
143     {
144       for (int i = 0; i < scripts_.size (); i++)
145         {
146           Grob *e = scripts_[i];
147           
148           if (!e->get_parent (X_AXIS) &&
149               Side_position_interface::get_axis (e) == Y_AXIS)
150             {
151               e->set_parent (inf.grob_, X_AXIS);
152             }
153         }
154     }
155
156 }
157
158
159 void
160 Drum_notes_engraver::stop_translation_timestep ()
161 {
162   notes_.clear ();
163   dots_.clear ();
164   scripts_.clear ();
165   
166   events_.clear ();
167 }
168
169
170
171 ADD_TRANSLATOR (Drum_notes_engraver,
172 /* descr */       "Generate noteheads.",
173 /* creats*/       "NoteHead Dots Script",
174 /* accepts */     "note-event busy-playing-event",
175 /* acks  */       "stem-interface note-column-interface",
176 /* reads */       "drumStyleTable",
177 /* write */       "");
178