]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-heads-engraver.cc
* lily/lily-guile.cc (alist_to_hashq): new function
[lilypond.git] / lily / note-heads-engraver.cc
1 /*
2   note-heads-engraver.cc -- part of GNU LilyPond
3
4   (c)  1997--2003 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 "event.hh"
11 #include "dots.hh"
12 #include "dot-column.hh"
13 #include "staff-symbol-referencer.hh"
14 #include "item.hh"
15 #include "engraver.hh"
16 #include "warn.hh"
17
18 class Note_heads_engraver : public Engraver
19 {
20   Link_array<Item> notes_;
21   Link_array<Item> dots_;
22   Link_array<Music> note_reqs_;
23
24 public:
25   TRANSLATOR_DECLARATIONS(Note_heads_engraver);
26
27 protected:
28   virtual bool try_music (Music *req) ;
29   virtual void process_music ();
30
31   virtual void stop_translation_timestep ();
32 };
33
34 Note_heads_engraver::Note_heads_engraver()
35 {
36 }
37
38 bool
39 Note_heads_engraver::try_music (Music *m) 
40 {
41   if (m->is_mus_type ("note-event"))
42     {
43       note_reqs_.push (m);
44       return true;
45     }
46   else if (m->is_mus_type ("busy-playing-event"))
47     return note_reqs_.size ();
48   else if (m->is_mus_type ("start-playing-event"))
49     return note_reqs_.size ();
50   
51   return false;
52 }
53
54
55 void
56 Note_heads_engraver::process_music ()
57 {
58   for (int i=0; i < note_reqs_.size (); i++)
59     {
60       Item *note = make_item ("NoteHead");
61
62       Music * req = note_reqs_[i];
63       
64       Duration dur = *unsmob_duration (req->get_mus_property ("duration"));
65
66       note->set_grob_property ("duration-log", gh_int2scm (dur.duration_log ()));
67
68       if (dur.dot_count ())
69         {
70           Item * d = make_item ("Dots");
71           Rhythmic_head::set_dots (note, d);
72           
73           if (dur.dot_count ()
74               != robust_scm2int (d->get_grob_property ("dot-count"), 0))
75             d->set_grob_property ("dot-count", gh_int2scm (dur.dot_count ()));
76
77           d->set_parent (note, Y_AXIS);
78           announce_grob (d, SCM_EOL);
79           dots_.push (d);
80         }
81
82       Pitch *pit =unsmob_pitch (req->get_mus_property ("pitch"));
83
84       int pos = pit ? pit->steps () : 0;
85       SCM c0 = get_property ("centralCPosition");
86       if (gh_number_p (c0))
87         pos += gh_scm2int (c0);
88
89       note->set_grob_property ("staff-position",   gh_int2scm (pos));
90       announce_grob (note,req->self_scm());
91       notes_.push (note);
92     }
93 }
94
95 void
96 Note_heads_engraver::stop_translation_timestep ()
97 {
98   for (int i=0; i < notes_.size (); i++)
99     {
100       typeset_grob (notes_[i]);
101     }
102
103   notes_.clear ();
104   for (int i=0; i < dots_.size (); i++)
105     {
106       typeset_grob (dots_[i]);
107     }
108   dots_.clear ();
109   note_reqs_.clear ();
110 }
111
112
113
114 ENTER_DESCRIPTION(Note_heads_engraver,
115 /* descr */       "Generate noteheads.",
116 /* creats*/       "NoteHead Dots",
117 /* accepts */     "note-event busy-playing-event",
118 /* acks  */      "",
119 /* reads */       "centralCPosition",
120 /* write */       "");