Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / note-heads-engraver.cc
blob4aa97dd4b90c62666feb682274a967c38c536aa7
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 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"
22 #include <cctype>
23 using namespace std;
25 #include "duration.hh"
26 #include "item.hh"
27 #include "output-def.hh"
28 #include "pitch.hh"
29 #include "rhythmic-head.hh"
30 #include "staff-symbol-referencer.hh"
31 #include "stream-event.hh"
32 #include "warn.hh"
34 #include "translator.icc"
36 class Note_heads_engraver : public Engraver
38 vector<Stream_event *> note_evs_;
40 public:
41 TRANSLATOR_DECLARATIONS (Note_heads_engraver);
43 protected:
44 DECLARE_TRANSLATOR_LISTENER (note);
45 void process_music ();
46 void stop_translation_timestep ();
49 Note_heads_engraver::Note_heads_engraver ()
53 IMPLEMENT_TRANSLATOR_LISTENER (Note_heads_engraver, note);
54 void
55 Note_heads_engraver::listen_note (Stream_event *ev)
57 note_evs_.push_back (ev);
60 void
61 Note_heads_engraver::process_music ()
63 SCM c0 = get_property ("middleCPosition");
64 SCM layout_proc = get_property ("staffLineLayoutFunction");
66 for (vsize i = 0; i < note_evs_.size (); i++)
68 Stream_event *ev = note_evs_[i];
69 Item *note = make_item ("NoteHead", ev->self_scm ());
71 Pitch *pit = unsmob_pitch (ev->get_property ("pitch"));
73 #if 0 /* TODO: should have a mechanism to switch off these warnings. */
75 if (!pit)
76 ev->origin ()->warning (_ ("NoteEvent without pitch"));
77 #endif
79 int pos;
80 if (pit == 0)
81 pos = 0;
82 else if (ly_is_procedure (layout_proc))
84 SCM pitch = ev->get_property ("pitch");
85 pos = scm_to_int (scm_call_1 (layout_proc, pitch));
87 else
88 pos = pit->steps ();
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;
108 SCM style = SCM_EOL;
109 if (scm_c_vector_length (shape_vector) > delta
110 && scm_is_symbol (scm_vector_ref (shape_vector, scm_from_int (delta))))
111 style = scm_vector_ref (shape_vector, scm_from_int (delta));
112 if (scm_is_symbol (style))
113 note->set_property ("style", style);
118 void
119 Note_heads_engraver::stop_translation_timestep ()
121 note_evs_.clear ();
124 ADD_TRANSLATOR (Note_heads_engraver,
125 /* doc */
126 "Generate note heads.",
128 /* create */
129 "NoteHead ",
131 /* read */
132 "middleCPosition "
133 "staffLineLayoutFunction ",
135 /* write */