]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-heads-engraver.cc
*** empty log message ***
[lilypond.git] / lily / note-heads-engraver.cc
1 /*
2   note-heads-engraver.cc -- part of GNU LilyPond
3
4   (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 */
6
7 #include "engraver.hh"
8
9 #include <cctype>
10 using namespace std;
11
12 #include "dots.hh"
13 #include "dot-column.hh"
14 #include "duration.hh"
15 #include "item.hh"
16 #include "output-def.hh"
17 #include "rhythmic-head.hh"
18 #include "staff-symbol-referencer.hh"
19 #include "stream-event.hh"
20 #include "warn.hh"
21
22 #include "translator.icc"
23
24 class Note_heads_engraver : public Engraver
25 {
26   vector<Item*> notes_;
27   vector<Item*> dots_;
28   vector<Stream_event*> note_evs_;
29
30 public:
31   TRANSLATOR_DECLARATIONS (Note_heads_engraver);
32
33 protected:
34   DECLARE_TRANSLATOR_LISTENER (note);
35   void process_music ();
36   void stop_translation_timestep ();
37 };
38
39 Note_heads_engraver::Note_heads_engraver ()
40 {
41 }
42
43 IMPLEMENT_TRANSLATOR_LISTENER (Note_heads_engraver, note);
44 void
45 Note_heads_engraver::listen_note (Stream_event *ev)
46 {
47   note_evs_.push_back (ev);
48 }
49
50 void
51 Note_heads_engraver::process_music ()
52 {
53   for (vsize i = 0; i < note_evs_.size (); i++)
54     {
55       Stream_event *ev = note_evs_[i];
56       Item *note = make_item ("NoteHead", ev->self_scm ());
57
58       Duration dur = *unsmob_duration (ev->get_property ("duration"));
59
60       note->set_property ("duration-log", scm_from_int (dur.duration_log ()));
61       if (dur.dot_count ())
62         {
63           Item *d = make_item ("Dots", note->self_scm ());
64           Rhythmic_head::set_dots (note, d);
65
66           if (dur.dot_count ()
67               != robust_scm2int (d->get_property ("dot-count"), 0))
68             d->set_property ("dot-count", scm_from_int (dur.dot_count ()));
69
70           d->set_parent (note, Y_AXIS);
71
72           dots_.push_back (d);
73         }
74
75       Pitch *pit = unsmob_pitch (ev->get_property ("pitch"));
76
77 #if 0 /* TODO: should have a mechanism to switch off these warnings. */
78
79       if (!pit)
80         ev->origin ()->warning (_ ("NoteEvent without pitch"));
81 #endif
82
83       int pos = pit ? pit->steps () : 0;
84       SCM c0 = get_property ("middleCPosition");
85       if (scm_is_number (c0))
86         pos += scm_to_int (c0);
87
88       note->set_property ("staff-position", scm_from_int (pos));
89
90       /*
91         Shape note heads change on step of the scale.
92       */
93       SCM shape_vector = get_property ("shapeNoteStyles");
94       if (scm_is_vector (shape_vector))
95         {
96           SCM scm_tonic = get_property ("tonic");
97           Pitch tonic (0, 0, 0);
98           if (unsmob_pitch (scm_tonic))
99             tonic = *unsmob_pitch (scm_tonic);
100
101           unsigned int delta = (pit->get_notename () - tonic.get_notename () + 7) % 7;
102
103           SCM style = SCM_EOL;
104           if (scm_c_vector_length (shape_vector) > delta
105               && scm_is_symbol (scm_vector_ref (shape_vector, scm_from_int (delta))))
106             style = scm_vector_ref (shape_vector, scm_from_int (delta));
107           if (scm_is_symbol (style))
108             note->set_property ("style", style);
109         }
110
111       notes_.push_back (note);
112     }
113 }
114
115 void
116 Note_heads_engraver::stop_translation_timestep ()
117 {
118   notes_.clear ();
119   dots_.clear ();
120   note_evs_.clear ();
121 }
122
123 ADD_TRANSLATOR (Note_heads_engraver,
124                 /* doc */ "Generate noteheads.",
125                 /* create */
126                 "NoteHead "
127                 "Dots",
128                 /* accept */
129                 "note-event",
130                 /* read */ "middleCPosition",
131                 /* write */ "");