2 note-heads-engraver.cc -- part of GNU LilyPond
4 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
12 #include "duration.hh"
14 #include "output-def.hh"
16 #include "rhythmic-head.hh"
17 #include "staff-symbol-referencer.hh"
18 #include "stream-event.hh"
21 #include "translator.icc"
23 class Note_heads_engraver : public Engraver
26 vector<Stream_event*> note_evs_;
29 TRANSLATOR_DECLARATIONS (Note_heads_engraver);
32 DECLARE_TRANSLATOR_LISTENER (note);
33 void process_music ();
34 void stop_translation_timestep ();
37 Note_heads_engraver::Note_heads_engraver ()
41 IMPLEMENT_TRANSLATOR_LISTENER (Note_heads_engraver, note);
43 Note_heads_engraver::listen_note (Stream_event *ev)
45 note_evs_.push_back (ev);
49 Note_heads_engraver::process_music ()
51 for (vsize i = 0; i < note_evs_.size (); i++)
53 Stream_event *ev = note_evs_[i];
54 Item *note = make_item ("NoteHead", ev->self_scm ());
56 Pitch *pit = unsmob_pitch (ev->get_property ("pitch"));
58 #if 0 /* TODO: should have a mechanism to switch off these warnings. */
61 ev->origin ()->warning (_ ("NoteEvent without pitch"));
64 int pos = pit ? pit->steps () : 0;
65 SCM c0 = get_property ("middleCPosition");
66 if (scm_is_number (c0))
67 pos += scm_to_int (c0);
69 note->set_property ("staff-position", scm_from_int (pos));
72 Shape note heads change on step of the scale.
74 SCM shape_vector = get_property ("shapeNoteStyles");
75 if (scm_is_vector (shape_vector))
77 SCM scm_tonic = get_property ("tonic");
78 Pitch tonic (0, 0, 0);
79 if (unsmob_pitch (scm_tonic))
80 tonic = *unsmob_pitch (scm_tonic);
82 unsigned int delta = (pit->get_notename () - tonic.get_notename () + 7) % 7;
85 if (scm_c_vector_length (shape_vector) > delta
86 && scm_is_symbol (scm_vector_ref (shape_vector, scm_from_int (delta))))
87 style = scm_vector_ref (shape_vector, scm_from_int (delta));
88 if (scm_is_symbol (style))
89 note->set_property ("style", style);
92 notes_.push_back (note);
97 Note_heads_engraver::stop_translation_timestep ()
103 ADD_TRANSLATOR (Note_heads_engraver,
104 /* doc */ "Generate noteheads.",
107 /* read */ "middleCPosition",