]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-heads-engraver.cc
release: 1.3.113
[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 "paper-def.hh"
9 #include "musical-request.hh"
10 #include "dots.hh"
11 #include "dot-column.hh"
12 #include "staff-symbol-referencer.hh"
13 #include "item.hh"
14 #include "score-engraver.hh"
15 #include "warn.hh"
16
17 /**
18   make balls and rests
19  */
20 class Note_heads_engraver : public Engraver
21 {
22   Link_array<Item> 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   
29 protected:
30   virtual void start_translation_timestep ();
31   virtual bool try_music (Music *req_l) ;
32   virtual void create_grobs ();
33   virtual void acknowledge_grob (Grob_info) ;
34   virtual void stop_translation_timestep();
35 };
36
37
38 bool
39 Note_heads_engraver::try_music (Music *m) 
40 {
41   if (Note_req * n =dynamic_cast <Note_req *> (m))
42     {
43       note_req_l_arr_.push (n);
44       note_end_mom_  = note_end_mom_ >? now_mom () + m->length_mom ();
45       
46       return true;
47     }
48   else if (dynamic_cast<Busy_playing_req*> (m))
49     {
50       return now_mom () < note_end_mom_;
51     }
52   return false;
53   
54 }
55
56 void
57 Note_heads_engraver::acknowledge_grob (Grob_info)
58 {
59   //create_grobs ();
60 }
61
62 void
63 Note_heads_engraver::create_grobs ()
64 {
65   if (note_p_arr_.size ())
66     return ;
67   
68   for (int i=0; i < note_req_l_arr_.size (); i++)
69     {
70       Item *note_p  = new Item (get_property ("NoteHead"));
71       
72       Staff_symbol_referencer::set_interface (note_p);
73
74
75       
76       Music * req = note_req_l_arr_[i];
77       
78       Duration dur   = *unsmob_duration (req->get_mus_property ("duration"));
79       note_p->set_grob_property ("duration-log",
80                                 gh_int2scm (dur.duration_log () <? 2));
81
82       if (dur.dot_count ())
83         {
84           Item * d = new Item (get_property ("Dots"));
85           Rhythmic_head::set_dots (note_p, d);
86           
87           if (dur.dot_count ()
88               != gh_scm2int (d->get_grob_property ("dot-count")))
89             d->set_grob_property ("dot-count", gh_int2scm (dur.dot_count ()));
90
91           d->set_parent (note_p, Y_AXIS);
92           announce_grob (d,0);
93           dot_p_arr_.push (d);
94         }
95
96       note_p->set_grob_property("staff-position",  gh_int2scm (unsmob_pitch (req->get_mus_property ("pitch"))->steps ()));
97
98       announce_grob (note_p,req);
99       note_p_arr_.push (note_p);
100     }
101 }
102  
103 void
104 Note_heads_engraver::stop_translation_timestep()
105 {
106   for (int i=0; i < note_p_arr_.size (); i++)
107     {
108       typeset_grob (note_p_arr_[i]);
109     }
110   note_p_arr_.clear ();
111   for (int i=0; i < dot_p_arr_.size (); i++)
112     {
113       typeset_grob (dot_p_arr_[i]);
114     }
115   dot_p_arr_.clear ();
116   
117   note_req_l_arr_.clear ();
118 }
119
120 void
121 Note_heads_engraver::start_translation_timestep ()
122 {
123   /* TODO:make this settable?
124    */
125   if (note_end_mom_ > now_mom() )
126     {
127       Score_engraver * e = 0;
128       Translator * t  =  daddy_grav_l ();
129       for (; !e && t;  t = t->daddy_trans_l_)
130         {
131           e = dynamic_cast<Score_engraver*> (t);
132         }
133
134       if (!e)
135         programming_error ("No score engraver!");
136       else
137         e->forbid_breaks ();    // guh. Use properties!
138     }
139 }
140
141
142
143 ADD_THIS_TRANSLATOR(Note_heads_engraver);
144