* lexer-gcc-3.1.sh: Remove.
[lilypond/patrick.git] / lily / note-heads-engraver.cc
blob1c6bf4142d4e70efd749cde07a472a46b834212b
1 /*
2 note-heads-engraver.cc -- part of GNU LilyPond
4 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 */
7 #include "engraver.hh"
9 #include <cctype>
10 using namespace std;
12 #include "dots.hh"
13 #include "dot-column.hh"
14 #include "duration.hh"
15 #include "item.hh"
16 #include "output-def.hh"
17 #include "pitch.hh"
18 #include "rhythmic-head.hh"
19 #include "staff-symbol-referencer.hh"
20 #include "stream-event.hh"
21 #include "warn.hh"
23 #include "translator.icc"
25 class Note_heads_engraver : public Engraver
27 vector<Item*> notes_;
28 vector<Stream_event*> note_evs_;
30 public:
31 TRANSLATOR_DECLARATIONS (Note_heads_engraver);
33 protected:
34 DECLARE_TRANSLATOR_LISTENER (note);
35 void process_music ();
36 void stop_translation_timestep ();
39 Note_heads_engraver::Note_heads_engraver ()
43 IMPLEMENT_TRANSLATOR_LISTENER (Note_heads_engraver, note);
44 void
45 Note_heads_engraver::listen_note (Stream_event *ev)
47 note_evs_.push_back (ev);
50 void
51 Note_heads_engraver::process_music ()
53 for (vsize i = 0; i < note_evs_.size (); i++)
55 Stream_event *ev = note_evs_[i];
56 Item *note = make_item ("NoteHead", ev->self_scm ());
58 Pitch *pit = unsmob_pitch (ev->get_property ("pitch"));
60 #if 0 /* TODO: should have a mechanism to switch off these warnings. */
62 if (!pit)
63 ev->origin ()->warning (_ ("NoteEvent without pitch"));
64 #endif
66 int pos = pit ? pit->steps () : 0;
67 SCM c0 = get_property ("middleCPosition");
68 if (scm_is_number (c0))
69 pos += scm_to_int (c0);
71 note->set_property ("staff-position", scm_from_int (pos));
74 Shape note heads change on step of the scale.
76 SCM shape_vector = get_property ("shapeNoteStyles");
77 if (scm_is_vector (shape_vector))
79 SCM scm_tonic = get_property ("tonic");
80 Pitch tonic (0, 0, 0);
81 if (unsmob_pitch (scm_tonic))
82 tonic = *unsmob_pitch (scm_tonic);
84 unsigned int delta = (pit->get_notename () - tonic.get_notename () + 7) % 7;
86 SCM style = SCM_EOL;
87 if (scm_c_vector_length (shape_vector) > delta
88 && scm_is_symbol (scm_vector_ref (shape_vector, scm_from_int (delta))))
89 style = scm_vector_ref (shape_vector, scm_from_int (delta));
90 if (scm_is_symbol (style))
91 note->set_property ("style", style);
94 notes_.push_back (note);
98 void
99 Note_heads_engraver::stop_translation_timestep ()
101 notes_.clear ();
102 note_evs_.clear ();
105 ADD_TRANSLATOR (Note_heads_engraver,
106 /* doc */ "Generate noteheads.",
107 /* create */
108 "NoteHead ",
109 /* accept */
110 "note-event",
111 /* read */ "middleCPosition",
112 /* write */ "");