]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-heads-engraver.cc
* flower
[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 <cctype>
8
9 #include "rhythmic-head.hh"
10 #include "output-def.hh"
11 #include "dots.hh"
12 #include "dot-column.hh"
13 #include "staff-symbol-referencer.hh"
14 #include "item.hh"
15 #include "engraver.hh"
16 #include "warn.hh"
17
18 class Note_heads_engraver : public Engraver
19 {
20   Link_array<Item> notes_;
21   Link_array<Item> dots_;
22   Link_array<Music> note_evs_;
23
24 public:
25   TRANSLATOR_DECLARATIONS (Note_heads_engraver);
26
27 protected:
28   virtual bool try_music (Music *ev);
29   virtual void process_music ();
30
31   virtual void stop_translation_timestep ();
32 };
33
34 Note_heads_engraver::Note_heads_engraver ()
35 {
36 }
37
38 bool
39 Note_heads_engraver::try_music (Music *m)
40 {
41   if (m->is_mus_type ("note-event"))
42     {
43       note_evs_.push (m);
44       return true;
45     }
46   else if (m->is_mus_type ("busy-playing-event"))
47     return note_evs_.size ();
48
49   return false;
50 }
51
52 void
53 Note_heads_engraver::process_music ()
54 {
55   for (int i = 0; i < note_evs_.size (); i++)
56     {
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_int2num (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_int2num (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       int pos = pit ? pit->steps () : 0;
81       SCM c0 = get_property ("middleCPosition");
82       if (scm_is_number (c0))
83         pos += scm_to_int (c0);
84
85       note->set_property ("staff-position", scm_int2num (pos));
86
87       /*
88         Shaped note heads change on step of the scale.
89       */
90       SCM shape_vector = get_property ("shapeNoteStyles");
91       if (scm_is_vector (shape_vector))
92         {
93           SCM scm_tonic = get_property ("tonic");
94           Pitch tonic (0, 0, 0);
95           if (unsmob_pitch (scm_tonic))
96             tonic = *unsmob_pitch (scm_tonic);
97
98           unsigned int delta = (pit->get_notename () - tonic.get_notename () + 7) % 7;
99
100           SCM style = SCM_EOL;
101           if (scm_c_vector_length (shape_vector) > delta
102               && scm_is_symbol (scm_vector_ref (shape_vector, scm_from_int (delta))))
103             {
104               style = scm_vector_ref (shape_vector, scm_from_int (delta));
105             }
106           if (scm_is_symbol (style))
107             {
108               note->set_property ("style", style);
109             }
110         }
111
112       notes_.push (note);
113     }
114 }
115
116 void
117 Note_heads_engraver::stop_translation_timestep ()
118 {
119   notes_.clear ();
120   dots_.clear ();
121   note_evs_.clear ();
122 }
123
124 ADD_TRANSLATOR (Note_heads_engraver,
125                 /* descr */ "Generate noteheads.",
126                 /* creats*/ "NoteHead Dots",
127                 /* accepts */ "note-event busy-playing-event",
128                 /* acks  */ "",
129                 /* reads */ "middleCPosition",
130                 /* write */ "");