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