2 note-heads-engraver.cc -- part of GNU LilyPond
4 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "rhythmic-head.hh"
12 #include "output-def.hh"
14 #include "dot-column.hh"
15 #include "staff-symbol-referencer.hh"
18 #include "duration.hh"
20 class Note_heads_engraver : public Engraver
22 Link_array<Item> notes_;
23 Link_array<Item> dots_;
24 Link_array<Music> note_evs_;
27 TRANSLATOR_DECLARATIONS (Note_heads_engraver);
30 virtual bool try_music (Music *ev);
31 void process_music ();
32 void stop_translation_timestep ();
35 Note_heads_engraver::Note_heads_engraver ()
40 Note_heads_engraver::try_music (Music *m)
42 if (m->is_mus_type ("note-event"))
47 else if (m->is_mus_type ("busy-playing-event"))
48 return note_evs_.size ();
54 Note_heads_engraver::process_music ()
56 for (int i = 0; i < note_evs_.size (); i++)
58 Music *ev = note_evs_[i];
59 Item *note = make_item ("NoteHead", ev->self_scm ());
61 Duration dur = *unsmob_duration (ev->get_property ("duration"));
63 note->set_property ("duration-log", scm_from_int (dur.duration_log ()));
66 Item *d = make_item ("Dots", note->self_scm ());
67 Rhythmic_head::set_dots (note, d);
70 != robust_scm2int (d->get_property ("dot-count"), 0))
71 d->set_property ("dot-count", scm_from_int (dur.dot_count ()));
73 d->set_parent (note, Y_AXIS);
78 Pitch *pit = unsmob_pitch (ev->get_property ("pitch"));
80 #if 0 /* TODO: should have a mechanism to switch off these warnings. */
84 ev->origin ()->warning (_ ("NoteEvent without pitch"));
88 int pos = pit ? pit->steps () : 0;
89 SCM c0 = get_property ("middleCPosition");
90 if (scm_is_number (c0))
91 pos += scm_to_int (c0);
93 note->set_property ("staff-position", scm_from_int (pos));
96 Shape note heads change on step of the scale.
98 SCM shape_vector = get_property ("shapeNoteStyles");
99 if (scm_is_vector (shape_vector))
101 SCM scm_tonic = get_property ("tonic");
102 Pitch tonic (0, 0, 0);
103 if (unsmob_pitch (scm_tonic))
104 tonic = *unsmob_pitch (scm_tonic);
106 unsigned int delta = (pit->get_notename () - tonic.get_notename () + 7) % 7;
109 if (scm_c_vector_length (shape_vector) > delta
110 && scm_is_symbol (scm_vector_ref (shape_vector, scm_from_int (delta))))
112 style = scm_vector_ref (shape_vector, scm_from_int (delta));
114 if (scm_is_symbol (style))
116 note->set_property ("style", style);
125 Note_heads_engraver::stop_translation_timestep ()
132 #include "translator.icc"
134 ADD_TRANSLATOR (Note_heads_engraver,
135 /* doc */ "Generate noteheads.",
136 /* create */ "NoteHead Dots",
137 /* accept */ "note-event busy-playing-event",
138 /* read */ "middleCPosition",