]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-heads-engraver.cc
release: 1.5.24
[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   
25   Link_array<Item> dot_p_arr_;
26   Link_array<Note_req> note_req_l_arr_;
27   Moment note_end_mom_;
28 public:
29   TRANSLATOR_DECLARATIONS(Note_heads_engraver);
30
31 protected:
32   virtual void start_translation_timestep ();
33   virtual bool try_music (Music *req_l) ;
34   virtual void process_music ();
35
36   virtual void stop_translation_timestep ();
37 };
38
39
40 Note_heads_engraver::Note_heads_engraver()
41 {
42 }
43
44 bool
45 Note_heads_engraver::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 (dynamic_cast<Busy_playing_req*> (m))
55     {
56       return now_mom () < note_end_mom_;
57     }
58   return false;
59 }
60
61
62 void
63 Note_heads_engraver::process_music ()
64 {
65   for (int i=0; i < note_req_l_arr_.size (); i++)
66     {
67       Item *note_p  = new Item (get_property ("NoteHead"));
68       
69       Staff_symbol_referencer::set_interface (note_p);
70       
71       Music * req = note_req_l_arr_[i];
72       
73       Duration dur = *unsmob_duration (req->get_mus_property ("duration"));
74
75       note_p->set_grob_property ("duration-log", gh_int2scm (dur.duration_log ()));
76
77       if (dur.dot_count ())
78         {
79           Item * d = new Item (get_property ("Dots"));
80           Rhythmic_head::set_dots (note_p, d);
81           
82           if (dur.dot_count ()
83               != gh_scm2int (d->get_grob_property ("dot-count")))
84             d->set_grob_property ("dot-count", gh_int2scm (dur.dot_count ()));
85
86           d->set_parent (note_p, Y_AXIS);
87           announce_grob (d,0);
88           dot_p_arr_.push (d);
89         }
90
91       Pitch *pit =unsmob_pitch (req->get_mus_property ("pitch"));
92
93       int pos = pit->steps ();
94       SCM c0 = get_property ("centralCPosition");
95       if (gh_number_p (c0))
96         pos += gh_scm2int (c0);
97
98       note_p->set_grob_property ("staff-position",   gh_int2scm (pos));
99       if (to_boolean (get_property ("easyPlay")))
100         {
101           char s[2] = "a";
102           s[0] = (pit->notename_i_ + 2)%7 + 'a';
103
104           s[0] = toupper (s[0]);
105           note_p->set_grob_property ("note-character", ly_str02scm (s));
106         }
107       
108       announce_grob (note_p,req);
109       note_p_arr_.push (note_p);
110     }
111 }
112
113 void
114 Note_heads_engraver::stop_translation_timestep ()
115 {
116   for (int i=0; i < note_p_arr_.size (); i++)
117     {
118       typeset_grob (note_p_arr_[i]);
119     }
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 }
135
136
137 ENTER_DESCRIPTION(Note_heads_engraver,
138 /* descr */       "Generate one or more noteheads from Music of type Note_req.",
139 /* creats*/       "NoteHead Dots",
140 /* acks  */       "",
141 /* reads */       "easyPlay centralCPosition",
142 /* write */       "");