2 ambitus-engraver.cc -- implement Ambitus_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2002--2007 Juergen Reuter <reuter@ipd.uka.de>
8 Han-Wen Nienhuys <hanwen@xs4all.nl
11 #include "engraver.hh"
13 #include "axis-group-interface.hh"
15 #include "note-head.hh"
16 #include "pitch-interval.hh"
17 #include "pointer-group-interface.hh"
18 #include "protected-scm.hh"
19 #include "side-position-interface.hh"
20 #include "staff-symbol-referencer.hh"
21 #include "stream-event.hh"
23 #include "translator.icc"
25 class Ambitus_engraver : public Engraver
28 TRANSLATOR_DECLARATIONS (Ambitus_engraver);
29 void process_music ();
30 void acknowledge_note_head (Grob_info);
31 void stop_translation_timestep ();
32 virtual void finalize ();
33 virtual void derived_mark () const;
36 void create_ambitus ();
39 Drul_array<Item *> heads_;
40 Drul_array<Item *> accidentals_;
41 Pitch_interval pitch_interval_;
48 Ambitus_engraver::derived_mark () const
50 scm_gc_mark (start_key_sig_);
54 Ambitus_engraver::create_ambitus ()
56 ambitus_ = make_item ("AmbitusLine", SCM_EOL);
57 group_ = make_item ("Ambitus", SCM_EOL);
61 heads_[d] = make_item ("AmbitusNoteHead", SCM_EOL);
62 accidentals_[d] = make_item ("AmbitusAccidental", SCM_EOL);
63 accidentals_[d]->set_parent (heads_[d], Y_AXIS);
64 heads_[d]->set_object ("accidental-grob",
65 accidentals_[d]->self_scm ());
66 Axis_group_interface::add_element (group_, heads_[d]);
67 Axis_group_interface::add_element (group_, accidentals_[d]);
68 Side_position_interface::add_support (accidentals_[d], heads_[d]);
70 while (flip (&d) != DOWN);
72 ambitus_->set_parent (heads_[DOWN], X_AXIS);
73 Axis_group_interface::add_element (group_, ambitus_);
78 Ambitus_engraver::Ambitus_engraver ()
81 heads_[LEFT] = heads_[RIGHT] = 0;
82 accidentals_[LEFT] = accidentals_[RIGHT] = 0;
85 start_key_sig_ = SCM_EOL;
89 Ambitus_engraver::process_music ()
92 * Ensure that ambitus is created in the very first timestep (on
93 * which lily does not call start_translation_timestep ()).
94 * Otherwise, if a voice begins with a rest, the ambitus grob will
95 * be placed after the rest.
102 Ambitus_engraver::stop_translation_timestep ()
104 if (ambitus_ && !is_typeset_)
107 * Evaluate middleCPosition not until now, since otherwise we
108 * may then oversee a clef that is defined in a staff context if
109 * we are in a voice context; middleCPosition would then be
112 start_c0_ = robust_scm2int (get_property ("middleCPosition"), 0);
113 start_key_sig_ = get_property ("keySignature");
120 Ambitus_engraver::acknowledge_note_head (Grob_info info)
122 Stream_event *nr = info.event_cause ();
123 if (nr && nr->in_event_class ("note-event"))
125 Pitch pitch = *unsmob_pitch (nr->get_property ("pitch"));
126 pitch_interval_.add_point (pitch);
131 Ambitus_engraver::finalize ()
133 if (ambitus_ && !pitch_interval_.is_empty ())
138 Pitch p = pitch_interval_[d];
139 heads_[d]->set_property ("staff-position",
140 scm_from_int (start_c0_
143 SCM handle = scm_assoc (scm_cons (scm_from_int (p.get_octave ()),
144 scm_from_int (p.get_notename ())),
147 if (handle == SCM_BOOL_F)
148 handle = scm_assoc (scm_from_int (p.get_notename ()),
151 Rational sig_alter = (handle != SCM_BOOL_F)
152 ? robust_scm2rational (scm_cdr (handle), Rational (0)) : Rational (0);
154 if (sig_alter == p.get_alteration ())
156 accidentals_[d]->suicide ();
157 heads_[d]->set_object ("accidental-grob", SCM_EOL);
161 accidentals_[d]->set_property ("alteration", ly_rational2scm (p.get_alteration ()));
164 while (flip (&d) != DOWN);
167 Pointer_group_interface::add_grob (ambitus_, ly_symbol2scm ("note-heads"), heads_[DOWN]);
168 Pointer_group_interface::add_grob (ambitus_, ly_symbol2scm ("note-heads"), heads_[UP]);
175 accidentals_[d]->suicide ();
176 heads_[d]->suicide ();
178 while (flip (&d) != DOWN);
180 ambitus_->suicide ();
184 ADD_ACKNOWLEDGER (Ambitus_engraver, note_head);
185 ADD_TRANSLATOR (Ambitus_engraver,