2 ambitus-engraver.cc -- implement Ambitus_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2002--2004 Juergen Reuter <reuter@ipd.uka.de>
8 Han-Wen Nienhuys <hanwen@xs4all.nl
12 #include "engraver.hh"
14 #include "note-head.hh"
15 #include "staff-symbol-referencer.hh"
18 #include "pitch-interval.hh"
19 #include "protected-scm.hh"
20 #include "side-position-interface.hh"
23 class Ambitus_engraver : public Engraver
26 TRANSLATOR_DECLARATIONS (Ambitus_engraver);
27 virtual void process_music ();
28 virtual void acknowledge_grob (Grob_info);
29 virtual void stop_translation_timestep ();
30 virtual void finalize ();
33 void create_ambitus ();
35 Drul_array<Item *> heads_;
36 Drul_array<Item *> accidentals_;
37 Pitch_interval pitch_interval_;
40 Protected_scm start_key_sig_;
44 Ambitus_engraver::create_ambitus ()
46 ambitus_ = make_item ("AmbitusLine",SCM_EOL);
50 heads_[d] = make_item ("AmbitusNoteHead", SCM_EOL);
51 accidentals_[d] = make_item ("AmbitusAccidental", SCM_EOL);
52 heads_[d]->set_property ("accidental-grob", accidentals_[d]->self_scm ());
53 Side_position_interface::add_support (accidentals_[d], heads_[d]);
55 while (flip (&d) != DOWN);
56 ambitus_->set_parent (heads_[DOWN], X_AXIS);
61 Ambitus_engraver::Ambitus_engraver ()
68 Ambitus_engraver::process_music ()
71 * Ensure that ambitus is created in the very first timestep (on
72 * which lily does not call start_translation_timestep ()).
73 * Otherwise, if a voice begins with a rest, the ambitus grob will
74 * be placed after the rest.
83 Ambitus_engraver::stop_translation_timestep ()
85 if (ambitus_ && !is_typeset_)
88 * Evaluate middleCPosition not until now, since otherwise we
89 * may then oversee a clef that is defined in a staff context if
90 * we are in a voice context; middleCPosition would then be
93 start_c0_ = robust_scm2int (get_property ("middleCPosition"), 0);
94 start_key_sig_ = get_property ("keySignature");
102 Ambitus_engraver::acknowledge_grob (Grob_info info)
104 Item *item = dynamic_cast <Item *>(info.grob_);
107 if (Note_head::has_interface (info.grob_))
109 Music *nr = info.music_cause ();
110 if (nr && nr->is_mus_type ("note-event"))
112 Pitch pitch = *unsmob_pitch (nr->get_property ("pitch"));
113 pitch_interval_.add_point (pitch);
120 Ambitus_engraver::finalize ()
122 if (ambitus_ && !pitch_interval_.is_empty ())
127 Pitch p = pitch_interval_[d];
128 heads_[d]->set_property ("staff-position",
129 scm_from_int (start_c0_ +
132 SCM handle = scm_assoc (scm_cons (scm_from_int (p.get_octave ()),
133 scm_from_int (p.get_notename ())),
136 int sig_alter = (handle != SCM_BOOL_F) ? ly_scm2int (ly_car (handle)) : 0;
137 if (sig_alter == p.get_alteration ())
139 accidentals_[d]->suicide();
140 heads_[d]->set_property ("accidental-grob", SCM_EOL);
144 accidentals_[d]->set_property ("accidentals",
145 scm_list_1 (scm_from_int (p.get_alteration ())));
148 while (flip (&d) != DOWN);
150 ambitus_->set_property ("note-heads", scm_list_2 (heads_[DOWN]->self_scm (),
151 heads_[UP]->self_scm ()));
158 accidentals_[d]->suicide();
159 heads_[d]->suicide();
161 while (flip (&d) != DOWN);
166 ENTER_DESCRIPTION (Ambitus_engraver,
168 /* creats*/ "Ambitus",
170 /* acks */ "note-head-interface",