2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "engraver.hh"
25 #include "duration.hh"
27 #include "output-def.hh"
29 #include "rhythmic-head.hh"
30 #include "staff-symbol-referencer.hh"
31 #include "stream-event.hh"
34 #include "translator.icc"
38 class Note_heads_engraver : public Engraver
40 vector<Stream_event *> note_evs_;
43 TRANSLATOR_DECLARATIONS (Note_heads_engraver);
46 DECLARE_TRANSLATOR_LISTENER (note);
47 void process_music ();
48 void stop_translation_timestep ();
51 Note_heads_engraver::Note_heads_engraver ()
55 IMPLEMENT_TRANSLATOR_LISTENER (Note_heads_engraver, note);
57 Note_heads_engraver::listen_note (Stream_event *ev)
59 note_evs_.push_back (ev);
63 Note_heads_engraver::process_music ()
65 SCM c0 = get_property ("middleCPosition");
66 SCM layout_proc = get_property ("staffLineLayoutFunction");
68 for (vsize i = 0; i < note_evs_.size (); i++)
70 Stream_event *ev = note_evs_[i];
71 Item *note = make_item ("NoteHead", ev->self_scm ());
73 Pitch *pit = unsmob<Pitch> (ev->get_property ("pitch"));
75 #if 0 /* TODO: should have a mechanism to switch off these warnings. */
78 ev->origin ()->warning (_ ("NoteEvent without pitch"));
84 else if (ly_is_procedure (layout_proc))
86 SCM pitch = ev->get_property ("pitch");
87 pos = scm_to_int (scm_call_1 (layout_proc, pitch));
92 if (scm_is_number (c0))
93 pos += scm_to_int (c0);
95 note->set_property ("staff-position", scm_from_int (pos));
98 Shape note heads change on step of the scale.
100 SCM shape_vector = get_property ("shapeNoteStyles");
101 if (scm_is_vector (shape_vector))
103 SCM scm_tonic = get_property ("tonic");
105 if (unsmob<Pitch> (scm_tonic))
106 tonic = *unsmob<Pitch> (scm_tonic);
108 unsigned int delta = (pit->get_notename () - tonic.get_notename () + 7) % 7;
111 if (scm_c_vector_length (shape_vector) > delta
112 && scm_is_symbol (scm_vector_ref (shape_vector, scm_from_int (delta))))
113 style = scm_vector_ref (shape_vector, scm_from_int (delta));
114 if (scm_is_symbol (style))
115 note->set_property ("style", style);
121 Note_heads_engraver::stop_translation_timestep ()
126 ADD_TRANSLATOR (Note_heads_engraver,
128 "Generate note heads.",
135 "staffLineLayoutFunction ",