2 note-heads-engraver.cc -- part of GNU LilyPond
4 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "rhythmic-head.hh"
10 #include "output-def.hh"
12 #include "dot-column.hh"
13 #include "staff-symbol-referencer.hh"
15 #include "engraver.hh"
18 class Note_heads_engraver : public Engraver
20 Link_array<Item> notes_;
21 Link_array<Item> dots_;
22 Link_array<Music> note_evs_;
25 TRANSLATOR_DECLARATIONS (Note_heads_engraver);
28 virtual bool try_music (Music *ev);
29 virtual void process_music ();
30 virtual void stop_translation_timestep ();
33 Note_heads_engraver::Note_heads_engraver ()
38 Note_heads_engraver::try_music (Music *m)
40 if (m->is_mus_type ("note-event"))
45 else if (m->is_mus_type ("busy-playing-event"))
46 return note_evs_.size ();
52 Note_heads_engraver::process_music ()
54 for (int i = 0; i < note_evs_.size (); i++)
56 Music *ev = note_evs_[i];
57 Item *note = make_item ("NoteHead", ev->self_scm ());
59 Duration dur = *unsmob_duration (ev->get_property ("duration"));
61 note->set_property ("duration-log", scm_int2num (dur.duration_log ()));
64 Item *d = make_item ("Dots", note->self_scm ());
65 Rhythmic_head::set_dots (note, d);
68 != robust_scm2int (d->get_property ("dot-count"), 0))
69 d->set_property ("dot-count", scm_int2num (dur.dot_count ()));
71 d->set_parent (note, Y_AXIS);
76 Pitch *pit = unsmob_pitch (ev->get_property ("pitch"));
79 ev->origin ()->warning (_ ("NoteEvent without pitch"));
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);
86 note->set_property ("staff-position", scm_int2num (pos));
89 Shaped note heads change on step of the scale.
91 SCM shape_vector = get_property ("shapeNoteStyles");
92 if (scm_is_vector (shape_vector))
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);
99 unsigned int delta = (pit->get_notename () - tonic.get_notename () + 7) % 7;
102 if (scm_c_vector_length (shape_vector) > delta
103 && scm_is_symbol (scm_vector_ref (shape_vector, scm_from_int (delta))))
105 style = scm_vector_ref (shape_vector, scm_from_int (delta));
107 if (scm_is_symbol (style))
109 note->set_property ("style", style);
118 Note_heads_engraver::stop_translation_timestep ()
125 ADD_TRANSLATOR (Note_heads_engraver,
126 /* descr */ "Generate noteheads.",
127 /* creats*/ "NoteHead Dots",
128 /* accepts */ "note-event busy-playing-event",
130 /* reads */ "middleCPosition",