]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-heads-engraver.cc
patch::: 1.3.18.jcn1
[lilypond.git] / lily / note-heads-engraver.cc
1 /*
2   head-grav.cc -- part of GNU LilyPond
3
4   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
5 */
6
7 #include "note-head.hh"
8 #include "note-heads-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
15 ADD_THIS_TRANSLATOR (Note_heads_engraver);
16
17 Note_heads_engraver::Note_heads_engraver()
18 {
19 }
20
21 bool
22 Note_heads_engraver::do_try_music (Music *m) 
23 {
24   if (Note_req * n =dynamic_cast <Note_req *> (m))
25     {
26       note_req_l_arr_.push (n);
27       note_end_mom_  = note_end_mom_ >? now_mom () + m->length_mom ();
28       
29       return true;
30     }
31   else if (Tonic_req* t = dynamic_cast<Tonic_req*> (m))
32     {
33       return true;
34     }
35   else if (Inversion_req* i = dynamic_cast<Inversion_req*> (m))
36     {
37       return true;
38     }
39   else if (Bass_req* b = dynamic_cast<Bass_req*> (m))
40     {
41       return true;
42     }
43   else if (Busy_playing_req * p = dynamic_cast<Busy_playing_req*> (m))
44     {
45       return now_mom () < note_end_mom_;
46     }
47   else if (Pitch_interrogate_req *p = dynamic_cast<Pitch_interrogate_req*> (m))
48     {
49       for (int i= note_req_l_arr_.size (); i--;)
50         p->pitch_arr_.push (note_req_l_arr_[i]->pitch_); // GUH UGH UGHUGH.
51       return true;
52     }
53   return false;
54   
55 }
56
57 void
58 Note_heads_engraver::do_process_requests()
59 {
60   if (note_p_arr_.size ())
61     return ;
62   
63   SCM noteheadstyle = get_property ("noteHeadStyle", 0);
64   for (int i=0; i < note_req_l_arr_.size (); i++)
65     {
66       Note_head *note_p  = new Note_head;
67       
68       Staff_symbol_referencer_interface si (note_p);
69       si.set_interface ();
70
71       
72       Note_req * note_req_l = note_req_l_arr_[i];
73       
74       note_p->set_elt_property ("duration-log",
75                                 gh_int2scm (note_req_l->duration_.durlog_i_ <? 2));
76
77       if (note_req_l->duration_.dots_i_)
78         {
79           Dots * d = new Dots;
80
81           Staff_symbol_referencer_interface sd (d);
82           sd.set_interface ();
83           
84           note_p->add_dots (d);
85           d->set_elt_property ("dot-count", gh_int2scm (note_req_l->duration_.dots_i_));
86           announce_element (Score_element_info (d,0));
87           dot_p_arr_.push (d);
88         }
89       si.set_position(note_req_l->pitch_.steps ());
90
91       /*
92         TODO: transparent note heads.
93        */
94          
95       if (gh_string_p (noteheadstyle))
96         {
97           note_p->set_elt_property ("style", noteheadstyle);
98         }
99       
100       Score_element_info itinf (note_p,note_req_l);
101       announce_element (itinf);
102       note_p_arr_.push (note_p);
103     }
104 }
105  
106 void
107 Note_heads_engraver::do_pre_move_processing()
108 {
109   for (int i=0; i < note_p_arr_.size (); i++)
110     {
111       typeset_element (note_p_arr_[i]);
112     }
113   note_p_arr_.clear ();
114   for (int i=0; i < dot_p_arr_.size (); i++)
115     {
116       typeset_element (dot_p_arr_[i]);
117     }
118   dot_p_arr_.clear ();
119   
120   note_req_l_arr_.clear ();
121 }
122