]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-heads-engraver.cc
release: 1.3.90
[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 #include "item.hh"
17
18 /**
19   make balls and rests
20  */
21 class Note_heads_engraver : public Engraver
22 {
23   Link_array<Item> note_p_arr_;
24   Link_array<Item> dot_p_arr_;
25   Link_array<Note_req> note_req_l_arr_;
26   Moment note_end_mom_;
27 public:
28   VIRTUAL_COPY_CONS(Translator);
29   Note_heads_engraver();
30   
31 protected:
32   virtual bool do_try_music (Music *req_l) ;
33   virtual void do_process_music();
34   virtual void do_pre_move_processing();
35 };
36
37
38
39
40
41 Note_heads_engraver::Note_heads_engraver()
42 {
43 }
44
45 bool
46 Note_heads_engraver::do_try_music (Music *m) 
47 {
48   if (Note_req * n =dynamic_cast <Note_req *> (m))
49     {
50       note_req_l_arr_.push (n);
51       note_end_mom_  = note_end_mom_ >? now_mom () + m->length_mom ();
52       
53       return true;
54     }
55   else if (Tonic_req* t = dynamic_cast<Tonic_req*> (m))
56     {
57       return true;
58     }
59   else if (Inversion_req* i = dynamic_cast<Inversion_req*> (m))
60     {
61       return true;
62     }
63   else if (Bass_req* b = dynamic_cast<Bass_req*> (m))
64     {
65       return true;
66     }
67   else if (Busy_playing_req * p = dynamic_cast<Busy_playing_req*> (m))
68     {
69       return now_mom () < note_end_mom_;
70     }
71   return false;
72   
73 }
74
75 void
76 Note_heads_engraver::do_process_music()
77 {
78   if (note_p_arr_.size ())
79     return ;
80   
81   for (int i=0; i < note_req_l_arr_.size (); i++)
82     {
83       Item *note_p  = new Item (get_property ("basicNoteHeadProperties"));
84       
85       Staff_symbol_referencer::set_interface (note_p);
86
87
88       
89       Note_req * note_req_l = note_req_l_arr_[i];
90       
91       note_p->set_elt_property ("duration-log",
92                                 gh_int2scm (note_req_l->duration_.durlog_i_ <? 2));
93
94       if (note_req_l->duration_.dots_i_)
95         {
96           Item * d = new Item (get_property ("basicDotsProperties"));
97
98           Staff_symbol_referencer::set_interface (d);
99           
100           Rhythmic_head::set_dots (note_p, d);
101           
102           if (note_req_l->duration_.dots_i_
103               != gh_scm2int (d->get_elt_property ("dot-count")))
104             d->set_elt_property ("dot-count", gh_int2scm (note_req_l->duration_.dots_i_));
105
106           d->set_parent (note_p, Y_AXIS);
107           d->add_offset_callback (Dots::quantised_position_callback, Y_AXIS);
108           announce_element (d,0);
109           dot_p_arr_.push (d);
110         }
111
112       note_p->set_elt_property("staff-position",  gh_int2scm (note_req_l->pitch_.steps ()));
113
114       announce_element (note_p,note_req_l);
115       note_p_arr_.push (note_p);
116     }
117 }
118  
119 void
120 Note_heads_engraver::do_pre_move_processing()
121 {
122   for (int i=0; i < note_p_arr_.size (); i++)
123     {
124       typeset_element (note_p_arr_[i]);
125     }
126   note_p_arr_.clear ();
127   for (int i=0; i < dot_p_arr_.size (); i++)
128     {
129       typeset_element (dot_p_arr_[i]);
130     }
131   dot_p_arr_.clear ();
132   
133   note_req_l_arr_.clear ();
134 }
135
136
137
138
139 ADD_THIS_TRANSLATOR(Note_heads_engraver);
140