2 note-heads-engraver.cc -- part of GNU LilyPond
4 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
12 #include "rhythmic-head.hh"
13 #include "output-def.hh"
15 #include "dot-column.hh"
16 #include "staff-symbol-referencer.hh"
19 #include "duration.hh"
21 class Note_heads_engraver : public Engraver
25 vector<Music*> note_evs_;
28 TRANSLATOR_DECLARATIONS (Note_heads_engraver);
31 virtual bool try_music (Music *ev);
32 void process_music ();
33 void stop_translation_timestep ();
36 Note_heads_engraver::Note_heads_engraver ()
41 Note_heads_engraver::try_music (Music *m)
43 if (m->is_mus_type ("note-event"))
45 note_evs_.push_back (m);
48 else if (m->is_mus_type ("busy-playing-event"))
49 return note_evs_.size ();
55 Note_heads_engraver::process_music ()
57 for (vsize i = 0; i < note_evs_.size (); i++)
59 Music *ev = note_evs_[i];
60 Item *note = make_item ("NoteHead", ev->self_scm ());
62 Duration dur = *unsmob_duration (ev->get_property ("duration"));
64 note->set_property ("duration-log", scm_from_int (dur.duration_log ()));
67 Item *d = make_item ("Dots", note->self_scm ());
68 Rhythmic_head::set_dots (note, d);
71 != robust_scm2int (d->get_property ("dot-count"), 0))
72 d->set_property ("dot-count", scm_from_int (dur.dot_count ()));
74 d->set_parent (note, Y_AXIS);
79 Pitch *pit = unsmob_pitch (ev->get_property ("pitch"));
81 #if 0 /* TODO: should have a mechanism to switch off these warnings. */
84 ev->origin ()->warning (_ ("NoteEvent without pitch"));
87 int pos = pit ? pit->steps () : 0;
88 SCM c0 = get_property ("middleCPosition");
89 if (scm_is_number (c0))
90 pos += scm_to_int (c0);
92 note->set_property ("staff-position", scm_from_int (pos));
95 Shape note heads change on step of the scale.
97 SCM shape_vector = get_property ("shapeNoteStyles");
98 if (scm_is_vector (shape_vector))
100 SCM scm_tonic = get_property ("tonic");
101 Pitch tonic (0, 0, 0);
102 if (unsmob_pitch (scm_tonic))
103 tonic = *unsmob_pitch (scm_tonic);
105 unsigned int delta = (pit->get_notename () - tonic.get_notename () + 7) % 7;
108 if (scm_c_vector_length (shape_vector) > delta
109 && scm_is_symbol (scm_vector_ref (shape_vector, scm_from_int (delta))))
110 style = scm_vector_ref (shape_vector, scm_from_int (delta));
111 if (scm_is_symbol (style))
112 note->set_property ("style", style);
115 notes_.push_back (note);
120 Note_heads_engraver::stop_translation_timestep ()
127 #include "translator.icc"
129 ADD_TRANSLATOR (Note_heads_engraver,
130 /* doc */ "Generate noteheads.",
136 "busy-playing-event",
137 /* read */ "middleCPosition",