2 ambitus-engraver.cc -- implement Ambitus_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2002--2005 Juergen Reuter <reuter@ipd.uka.de>
8 Han-Wen Nienhuys <hanwen@xs4all.nl
11 #include "engraver.hh"
12 #include "note-head.hh"
13 #include "pitch-interval.hh"
14 #include "protected-scm.hh"
15 #include "staff-symbol-referencer.hh"
16 #include "axis-group-interface.hh"
17 #include "side-position-interface.hh"
19 #include "translator.icc"
21 class Ambitus_engraver : public Engraver
24 TRANSLATOR_DECLARATIONS (Ambitus_engraver);
25 void process_music ();
26 void acknowledge_note_head (Grob_info);
27 void stop_translation_timestep ();
28 virtual void finalize ();
29 virtual void derived_mark () const;
32 void create_ambitus ();
35 Drul_array<Item *> heads_;
36 Drul_array<Item *> accidentals_;
37 Pitch_interval pitch_interval_;
44 Ambitus_engraver::derived_mark () const
46 scm_gc_mark (start_key_sig_);
50 Ambitus_engraver::create_ambitus ()
52 ambitus_ = make_item ("AmbitusLine", SCM_EOL);
53 group_ = make_item ("Ambitus", SCM_EOL);
57 heads_[d] = make_item ("AmbitusNoteHead", SCM_EOL);
58 accidentals_[d] = make_item ("AmbitusAccidental", SCM_EOL);
59 accidentals_[d]->set_parent (heads_[d], Y_AXIS);
60 heads_[d]->set_object ("accidental-grob",
61 accidentals_[d]->self_scm ());
62 Axis_group_interface::add_element (group_, heads_[d]);
63 Axis_group_interface::add_element (group_, accidentals_[d]);
64 Side_position_interface::add_support (accidentals_[d], heads_[d]);
66 while (flip (&d) != DOWN);
68 ambitus_->set_parent (heads_[DOWN], X_AXIS);
69 Axis_group_interface::add_element (group_, ambitus_);
74 Ambitus_engraver::Ambitus_engraver ()
77 heads_[LEFT] = heads_[RIGHT] = 0;
78 accidentals_[LEFT] = accidentals_[RIGHT] = 0;
81 start_key_sig_ = SCM_EOL;
85 Ambitus_engraver::process_music ()
88 * Ensure that ambitus is created in the very first timestep (on
89 * which lily does not call start_translation_timestep ()).
90 * Otherwise, if a voice begins with a rest, the ambitus grob will
91 * be placed after the rest.
98 Ambitus_engraver::stop_translation_timestep ()
100 if (ambitus_ && !is_typeset_)
103 * Evaluate middleCPosition not until now, since otherwise we
104 * may then oversee a clef that is defined in a staff context if
105 * we are in a voice context; middleCPosition would then be
108 start_c0_ = robust_scm2int (get_property ("middleCPosition"), 0);
109 start_key_sig_ = get_property ("keySignature");
116 Ambitus_engraver::acknowledge_note_head (Grob_info info)
118 Music *nr = info.music_cause ();
119 if (nr && nr->is_mus_type ("note-event"))
121 Pitch pitch = *unsmob_pitch (nr->get_property ("pitch"));
122 pitch_interval_.add_point (pitch);
127 Ambitus_engraver::finalize ()
129 if (ambitus_ && !pitch_interval_.is_empty ())
134 Pitch p = pitch_interval_[d];
135 heads_[d]->set_property ("staff-position",
136 scm_from_int (start_c0_
139 SCM handle = scm_assoc (scm_cons (scm_from_int (p.get_octave ()),
140 scm_from_int (p.get_notename ())),
143 if (handle == SCM_BOOL_F)
144 handle = scm_assoc (scm_from_int (p.get_notename ()),
147 int sig_alter = (handle != SCM_BOOL_F)
148 ? scm_to_int (scm_cdr (handle)) : 0;
150 if (sig_alter == p.get_alteration ())
152 accidentals_[d]->suicide ();
153 heads_[d]->set_object ("accidental-grob", SCM_EOL);
157 SCM l = scm_list_1 (scm_from_int (p.get_alteration ()));
158 accidentals_[d]->set_property ("accidentals", l);
161 while (flip (&d) != DOWN);
163 ambitus_->set_object ("note-heads", scm_list_2 (heads_[DOWN]->self_scm (),
164 heads_[UP]->self_scm ()));
171 accidentals_[d]->suicide ();
172 heads_[d]->suicide ();
174 while (flip (&d) != DOWN);
176 ambitus_->suicide ();
180 ADD_ACKNOWLEDGER (Ambitus_engraver, note_head);
181 ADD_TRANSLATOR (Ambitus_engraver,
183 /* create */ "Ambitus AmbitusLine AmbitusNoteHead AmbitusAccidental",