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
99 Ambitus_engraver::stop_translation_timestep ()
101 if (ambitus_ && !is_typeset_)
104 * Evaluate middleCPosition not until now, since otherwise we
105 * may then oversee a clef that is defined in a staff context if
106 * we are in a voice context; middleCPosition would then be
109 start_c0_ = robust_scm2int (get_property ("middleCPosition"), 0);
110 start_key_sig_ = get_property ("keySignature");
117 Ambitus_engraver::acknowledge_note_head (Grob_info info)
119 Stream_event *nr = info.event_cause ();
120 if (nr && nr->in_event_class ("note-event"))
122 Pitch pitch = *unsmob_pitch (nr->get_property ("pitch"));
123 pitch_interval_.add_point (pitch);
128 Ambitus_engraver::finalize ()
130 if (ambitus_ && !pitch_interval_.is_empty ())
135 Pitch p = pitch_interval_[d];
136 heads_[d]->set_property ("staff-position",
137 scm_from_int (start_c0_
140 SCM handle = scm_assoc (scm_cons (scm_from_int (p.get_octave ()),
141 scm_from_int (p.get_notename ())),
144 if (handle == SCM_BOOL_F)
145 handle = scm_assoc (scm_from_int (p.get_notename ()),
148 Rational sig_alter = (handle != SCM_BOOL_F)
149 ? robust_scm2rational (scm_cdr (handle), Rational (0)) : Rational (0);
151 if (sig_alter == p.get_alteration ())
153 accidentals_[d]->suicide ();
154 heads_[d]->set_object ("accidental-grob", SCM_EOL);
158 accidentals_[d]->set_property ("alteration", ly_rational2scm (p.get_alteration ()));
161 while (flip (&d) != DOWN);
164 Pointer_group_interface::add_grob (ambitus_, ly_symbol2scm ("note-heads"), heads_[DOWN]);
165 Pointer_group_interface::add_grob (ambitus_, ly_symbol2scm ("note-heads"), heads_[UP]);
172 accidentals_[d]->suicide ();
173 heads_[d]->suicide ();
175 while (flip (&d) != DOWN);
177 ambitus_->suicide ();
181 ADD_ACKNOWLEDGER (Ambitus_engraver, note_head);
182 ADD_TRANSLATOR (Ambitus_engraver,