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);
53 Note_heads_engraver::process_music ()
55 for (vsize i = 0; i < note_evs_.size (); i++)
57 Music *ev = note_evs_[i];
58 Item *note = make_item ("NoteHead", ev->self_scm ());
60 Duration dur = *unsmob_duration (ev->get_property ("duration"));
62 note->set_property ("duration-log", scm_from_int (dur.duration_log ()));
65 Item *d = make_item ("Dots", note->self_scm ());
66 Rhythmic_head::set_dots (note, d);
69 != robust_scm2int (d->get_property ("dot-count"), 0))
70 d->set_property ("dot-count", scm_from_int (dur.dot_count ()));
72 d->set_parent (note, Y_AXIS);
77 Pitch *pit = unsmob_pitch (ev->get_property ("pitch"));
79 #if 0 /* TODO: should have a mechanism to switch off these warnings. */
82 ev->origin ()->warning (_ ("NoteEvent without pitch"));
85 int pos = pit ? pit->steps () : 0;
86 SCM c0 = get_property ("middleCPosition");
87 if (scm_is_number (c0))
88 pos += scm_to_int (c0);
90 note->set_property ("staff-position", scm_from_int (pos));
93 Shape note heads change on step of the scale.
95 SCM shape_vector = get_property ("shapeNoteStyles");
96 if (scm_is_vector (shape_vector))
98 SCM scm_tonic = get_property ("tonic");
99 Pitch tonic (0, 0, 0);
100 if (unsmob_pitch (scm_tonic))
101 tonic = *unsmob_pitch (scm_tonic);
103 unsigned int delta = (pit->get_notename () - tonic.get_notename () + 7) % 7;
106 if (scm_c_vector_length (shape_vector) > delta
107 && scm_is_symbol (scm_vector_ref (shape_vector, scm_from_int (delta))))
108 style = scm_vector_ref (shape_vector, scm_from_int (delta));
109 if (scm_is_symbol (style))
110 note->set_property ("style", style);
113 notes_.push_back (note);
118 Note_heads_engraver::stop_translation_timestep ()
125 #include "translator.icc"
127 ADD_TRANSLATOR (Note_heads_engraver,
128 /* doc */ "Generate noteheads.",
134 /* read */ "middleCPosition",