]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-heads-engraver.cc
release: 1.3.68
[lilypond.git] / lily / note-heads-engraver.cc
1 /*
2   head-grav.cc -- part of GNU LilyPond
3
4   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
5 */
6
7 #include "rhythmic-head.hh"
8 #include "engraver.hh"
9 #include "paper-def.hh"
10 #include "musical-request.hh"
11 #include "dots.hh"
12 #include "dot-column.hh"
13 #include "staff-symbol-referencer.hh"
14 #include "engraver.hh"
15 #include "pqueue.hh"
16
17 /**
18   make balls and rests
19  */
20 class Note_heads_engraver : public Engraver
21 {
22   Link_array<Rhythmic_head> note_p_arr_;
23   Link_array<Item> dot_p_arr_;
24   Link_array<Note_req> note_req_l_arr_;
25   Moment note_end_mom_;
26 public:
27   VIRTUAL_COPY_CONS(Translator);
28   Note_heads_engraver();
29   
30 protected:
31   virtual bool do_try_music (Music *req_l) ;
32   virtual void do_process_music();
33   virtual void do_pre_move_processing();
34 };
35
36
37
38
39
40 Note_heads_engraver::Note_heads_engraver()
41 {
42 }
43
44 bool
45 Note_heads_engraver::do_try_music (Music *m) 
46 {
47   if (Note_req * n =dynamic_cast <Note_req *> (m))
48     {
49       note_req_l_arr_.push (n);
50       note_end_mom_  = note_end_mom_ >? now_mom () + m->length_mom ();
51       
52       return true;
53     }
54   else if (Tonic_req* t = dynamic_cast<Tonic_req*> (m))
55     {
56       return true;
57     }
58   else if (Inversion_req* i = dynamic_cast<Inversion_req*> (m))
59     {
60       return true;
61     }
62   else if (Bass_req* b = dynamic_cast<Bass_req*> (m))
63     {
64       return true;
65     }
66   else if (Busy_playing_req * p = dynamic_cast<Busy_playing_req*> (m))
67     {
68       return now_mom () < note_end_mom_;
69     }
70   else if (Pitch_interrogate_req *p = dynamic_cast<Pitch_interrogate_req*> (m))
71     {
72       for (int i= note_req_l_arr_.size (); i--;)
73         p->pitch_arr_.push (note_req_l_arr_[i]->pitch_); // GUH UGH UGHUGH.
74       return true;
75     }
76   return false;
77   
78 }
79
80 void
81 Note_heads_engraver::do_process_music()
82 {
83   if (note_p_arr_.size ())
84     return ;
85   
86   for (int i=0; i < note_req_l_arr_.size (); i++)
87     {
88       Rhythmic_head *note_p  = new Rhythmic_head (get_property ("basicNoteHeadProperties"));
89       
90       Staff_symbol_referencer_interface::set_interface (note_p);
91
92
93       
94       Note_req * note_req_l = note_req_l_arr_[i];
95       
96       note_p->set_elt_property ("duration-log",
97                                 gh_int2scm (note_req_l->duration_.durlog_i_ <? 2));
98
99       if (note_req_l->duration_.dots_i_)
100         {
101           Item * d = new Item (get_property ("basicDotsProperties"));
102
103           Staff_symbol_referencer_interface::set_interface (d);
104           
105           note_p->set_dots (d);
106           
107           if (note_req_l->duration_.dots_i_
108               != gh_scm2int (d->get_elt_property ("dot-count")))
109             d->set_elt_property ("dot-count", gh_int2scm (note_req_l->duration_.dots_i_));
110
111           d->set_parent (note_p, Y_AXIS);
112           d->add_offset_callback (Dots::quantised_position_callback, Y_AXIS);
113           announce_element (Score_element_info (d,0));
114           dot_p_arr_.push (d);
115         }
116
117       note_p->set_elt_property("staff-position",  gh_int2scm (note_req_l->pitch_.steps ()));
118
119       Score_element_info itinf (note_p,note_req_l);
120       announce_element (itinf);
121       note_p_arr_.push (note_p);
122     }
123 }
124  
125 void
126 Note_heads_engraver::do_pre_move_processing()
127 {
128   for (int i=0; i < note_p_arr_.size (); i++)
129     {
130       typeset_element (note_p_arr_[i]);
131     }
132   note_p_arr_.clear ();
133   for (int i=0; i < dot_p_arr_.size (); i++)
134     {
135       typeset_element (dot_p_arr_[i]);
136     }
137   dot_p_arr_.clear ();
138   
139   note_req_l_arr_.clear ();
140 }
141
142
143
144
145 ADD_THIS_TRANSLATOR(Note_heads_engraver);
146