]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-heads-engraver.cc
(Paper_column): copy rank_. This fixes
[lilypond.git] / lily / note-heads-engraver.cc
1 /*
2   note-heads-engraver.cc -- part of GNU LilyPond
3
4   (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
5 */
6
7 #include <cctype>
8
9 #include "rhythmic-head.hh"
10 #include "output-def.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_evs_;
23
24 public:
25   TRANSLATOR_DECLARATIONS (Note_heads_engraver);
26
27 protected:
28   virtual bool try_music (Music *ev) ;
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_evs_.push (m);
44       return true;
45     }
46   else if (m->is_mus_type ("busy-playing-event"))
47     return note_evs_.size ();
48   
49   return false;
50 }
51
52
53 void
54 Note_heads_engraver::process_music ()
55 {
56   for (int i= 0; i < note_evs_.size (); i++)
57     {
58
59       Music * ev = note_evs_[i];
60       Item *note = make_item ("NoteHead", ev->self_scm ());
61       
62       Duration dur = *unsmob_duration (ev->get_property ("duration"));
63
64       note->set_property ("duration-log", scm_int2num (dur.duration_log ()));
65       if (dur.dot_count ())
66         {
67           Item * d = make_item ("Dots", note->self_scm ());
68           Rhythmic_head::set_dots (note, d);
69           
70           if (dur.dot_count ()
71               != robust_scm2int (d->get_property ("dot-count"), 0))
72             d->set_property ("dot-count", scm_int2num (dur.dot_count ()));
73
74           d->set_parent (note, Y_AXIS);
75           
76           dots_.push (d);
77         }
78
79       Pitch *pit =unsmob_pitch (ev->get_property ("pitch"));
80
81       int pos = pit ? pit->steps () : 0;
82       SCM c0 = get_property ("middleCPosition");
83       if (scm_is_number (c0))
84         pos += scm_to_int (c0);
85
86       note->set_property ("staff-position",   scm_int2num (pos));
87
88       /*
89         Shaped note heads change on step of the scale.
90        */
91       SCM shape_vector = get_property ("shapeNoteStyles");
92       if (ly_c_vector_p (shape_vector))
93         {
94           SCM scm_tonic = get_property ("tonic");
95           Pitch tonic (0,0,0); 
96           if (unsmob_pitch (scm_tonic))
97             tonic = *unsmob_pitch (scm_tonic);
98       
99           unsigned int delta = (pit->get_notename() - tonic.get_notename() + 7) % 7;
100           
101           SCM style = SCM_EOL;
102           if (SCM_VECTOR_LENGTH (shape_vector) > delta
103               && scm_is_symbol (scm_vector_ref (shape_vector, scm_from_int (delta))))
104             {
105               style = scm_vector_ref (shape_vector, scm_from_int (delta));
106             }
107           if (scm_is_symbol (style))
108             {
109               note->set_property ("style", style);
110             }
111         }
112       
113       notes_.push (note);
114     }
115 }
116
117 void
118 Note_heads_engraver::stop_translation_timestep ()
119 {
120   notes_.clear ();
121   dots_.clear ();
122   note_evs_.clear ();
123 }
124
125
126
127 ENTER_DESCRIPTION (Note_heads_engraver,
128 /* descr */       "Generate noteheads.",
129 /* creats*/       "NoteHead Dots",
130 /* accepts */     "note-event busy-playing-event",
131 /* acks  */      "",
132 /* reads */       "middleCPosition",
133 /* write */       "");