]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-heads-engraver.cc
release: 1.3.142
[lilypond.git] / lily / note-heads-engraver.cc
1 /*
2   head-grav.cc -- part of GNU LilyPond
3
4   (c)  1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
5 */
6 #include <ctype.h>
7
8 #include "rhythmic-head.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 "item.hh"
15 #include "score-engraver.hh"
16 #include "warn.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   
30 protected:
31   virtual void start_translation_timestep ();
32   virtual bool try_music (Music *req_l) ;
33   virtual void create_grobs ();
34   virtual void acknowledge_grob (Grob_info) ;
35   virtual void stop_translation_timestep ();
36 };
37
38
39 bool
40 Note_heads_engraver::try_music (Music *m) 
41 {
42   if (Note_req * n =dynamic_cast <Note_req *> (m))
43     {
44       note_req_l_arr_.push (n);
45       note_end_mom_  = note_end_mom_ >? now_mom () + m->length_mom ();
46       
47       return true;
48     }
49   else if (dynamic_cast<Busy_playing_req*> (m))
50     {
51       return now_mom () < note_end_mom_;
52     }
53   return false;
54   
55 }
56
57 void
58 Note_heads_engraver::acknowledge_grob (Grob_info)
59 {
60   //create_grobs ();
61 }
62
63 void
64 Note_heads_engraver::create_grobs ()
65 {
66   if (note_p_arr_.size ())
67     return ;
68   
69   for (int i=0; i < note_req_l_arr_.size (); i++)
70     {
71       Item *note_p  = new Item (get_property ("NoteHead"));
72       
73       Staff_symbol_referencer::set_interface (note_p);
74
75
76       
77       Music * req = note_req_l_arr_[i];
78       
79       Duration dur   = *unsmob_duration (req->get_mus_property ("duration"));
80       note_p->set_grob_property ("duration-log",
81                                 gh_int2scm (dur.duration_log () <? 2));
82
83       if (dur.dot_count ())
84         {
85           Item * d = new Item (get_property ("Dots"));
86           Rhythmic_head::set_dots (note_p, d);
87           
88           if (dur.dot_count ()
89               != gh_scm2int (d->get_grob_property ("dot-count")))
90             d->set_grob_property ("dot-count", gh_int2scm (dur.dot_count ()));
91
92           d->set_parent (note_p, Y_AXIS);
93           announce_grob (d,0);
94           dot_p_arr_.push (d);
95         }
96
97       Pitch *pit =unsmob_pitch (req->get_mus_property ("pitch"));
98       note_p->set_grob_property ("staff-position",  gh_int2scm (pit->steps ()));
99
100       if (to_boolean (get_property ("easyPlay")))
101         {
102           char s[2] = "a";
103           s[0] = (pit->notename_i_ + 2)%7 + 'a';
104
105           s[0] = toupper (s[0]);
106           note_p->set_grob_property ("note-character", ly_str02scm (s));
107         }
108       
109       announce_grob (note_p,req);
110       note_p_arr_.push (note_p);
111     }
112 }
113  
114 void
115 Note_heads_engraver::stop_translation_timestep ()
116 {
117   for (int i=0; i < note_p_arr_.size (); i++)
118     {
119       typeset_grob (note_p_arr_[i]);
120     }
121   note_p_arr_.clear ();
122   for (int i=0; i < dot_p_arr_.size (); i++)
123     {
124       typeset_grob (dot_p_arr_[i]);
125     }
126   dot_p_arr_.clear ();
127   
128   note_req_l_arr_.clear ();
129 }
130
131 void
132 Note_heads_engraver::start_translation_timestep ()
133 {
134   /* TODO:make this settable?
135    */
136   if (note_end_mom_ > now_mom ())
137     {
138       Score_engraver * e = 0;
139       Translator * t  =  daddy_grav_l ();
140       for (; !e && t;  t = t->daddy_trans_l_)
141         {
142           e = dynamic_cast<Score_engraver*> (t);
143         }
144
145       if (!e)
146         programming_error ("No score engraver!");
147       else
148         e->forbid_breaks ();    // guh. Use properties!
149     }
150 }
151
152
153
154 ADD_THIS_TRANSLATOR (Note_heads_engraver);
155