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"
17 #include "pitch-interval.hh"
18 #include "protected-scm.hh"
19 #include "staff-symbol-referencer.hh"
20 #include "axis-group-interface.hh"
21 #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 ();
36 Drul_array<Item *> heads_;
37 Drul_array<Item *> accidentals_;
38 Pitch_interval pitch_interval_;
41 Protected_scm start_key_sig_;
45 Ambitus_engraver::create_ambitus ()
47 ambitus_ = make_item ("AmbitusLine",SCM_EOL);
48 group_ = make_item ("Ambitus",SCM_EOL);
52 heads_[d] = make_item ("AmbitusNoteHead", SCM_EOL);
53 accidentals_[d] = make_item ("AmbitusAccidental", SCM_EOL);
54 accidentals_[d]->set_parent (heads_[d], Y_AXIS);
55 heads_[d]->set_property ("accidental-grob", accidentals_[d]->self_scm ());
56 Axis_group_interface::add_element (group_, heads_[d]);
57 Axis_group_interface::add_element (group_, accidentals_[d]);
58 Side_position_interface::add_support (accidentals_[d], heads_[d]);
60 while (flip (&d) != DOWN);
61 ambitus_->set_parent (heads_[DOWN], X_AXIS);
62 Axis_group_interface::add_element (group_, ambitus_);
68 Ambitus_engraver::Ambitus_engraver ()
71 heads_[LEFT] = heads_[RIGHT] = 0;
72 accidentals_[LEFT] = accidentals_[RIGHT] = 0;
78 Ambitus_engraver::process_music ()
81 * Ensure that ambitus is created in the very first timestep (on
82 * which lily does not call start_translation_timestep ()).
83 * Otherwise, if a voice begins with a rest, the ambitus grob will
84 * be placed after the rest.
93 Ambitus_engraver::stop_translation_timestep ()
95 if (ambitus_ && !is_typeset_)
98 * Evaluate middleCPosition not until now, since otherwise we
99 * may then oversee a clef that is defined in a staff context if
100 * we are in a voice context; middleCPosition would then be
103 start_c0_ = robust_scm2int (get_property ("middleCPosition"), 0);
104 start_key_sig_ = get_property ("keySignature");
112 Ambitus_engraver::acknowledge_grob (Grob_info info)
114 Item *item = dynamic_cast <Item *>(info.grob_);
117 if (Note_head::has_interface (info.grob_))
119 Music *nr = info.music_cause ();
120 if (nr && nr->is_mus_type ("note-event"))
122 Pitch pitch = *unsmob_pitch (nr->get_property ("pitch"));
123 pitch_interval_.add_point (pitch);
130 Ambitus_engraver::finalize ()
132 if (ambitus_ && !pitch_interval_.is_empty ())
137 Pitch p = pitch_interval_[d];
138 heads_[d]->set_property ("staff-position",
139 scm_from_int (start_c0_ +
142 SCM handle = scm_assoc (scm_cons (scm_from_int (p.get_octave ()),
143 scm_from_int (p.get_notename ())),
146 if (handle == SCM_BOOL_F)
147 handle = scm_assoc (scm_from_int (p.get_notename ()),
150 int sig_alter = (handle != SCM_BOOL_F) ? scm_to_int (ly_cdr (handle)) : 0;
151 if (sig_alter == p.get_alteration ())
153 accidentals_[d]->suicide();
154 heads_[d]->set_property ("accidental-grob", SCM_EOL);
158 accidentals_[d]->set_property ("accidentals",
159 scm_list_1 (scm_from_int (p.get_alteration ())));
162 while (flip (&d) != DOWN);
164 ambitus_->set_property ("note-heads", scm_list_2 (heads_[DOWN]->self_scm (),
165 heads_[UP]->self_scm ()));
172 accidentals_[d]->suicide();
173 heads_[d]->suicide();
175 while (flip (&d) != DOWN);
180 ENTER_DESCRIPTION (Ambitus_engraver,
182 /* creats*/ "Ambitus AmbitusLine AmbitusNoteHead AmbitusAccidental",
184 /* acks */ "note-head-interface",