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