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>
11 #include "note-head.hh"
12 #include "staff-symbol-referencer.hh"
15 #include "pitch-interval.hh"
16 #include "protected-scm.hh"
21 * This class implements an engraver for ambitus grobs.
23 * TODO: There are quite some conceptional issues left open:
25 * - Many publishers put ambitus _before_ the first occurrence of a
26 * clef. Hence, formally the pitches are undefined in this case. Of
27 * course, one could always silently assume that ambitus pitches refer
28 * to the first occurrence of a clef. Or should we, by default, put
29 * the ambitus always after the first clef, if any?
31 * - Enharmonically equal pitches: Assume piece contains once a "gis",
32 * another time an "aes" as highest pitch. Which one should be
33 * selected for the ambitus grob? The "aes", because it is
34 * musically/notationally "higher" than "gis"? Or "gis", because (if
35 * using pure temperament) it has a slightly higher frequency? Or
36 * that pitch that come closer to the key signature? But there may be
37 * key signature changes in the piece...
39 * - Multiple voices in single staff: Assume a vocal piece of music,
40 * where the soprano voice and the alto voice are put into the same
41 * staff (this is generally a bad idea, but unfortunately common
42 * practice). Then, there probably should be two ambitus grobs, one
43 * for each voice. But how can you see which ambitus grob refers to
44 * which voice? Most probably you can guess it from the fact that the
45 * ambitus of the alto voice typically lies in a lower range than that
46 * of the soprano voice, but this is just a heuristic rather than a
47 * generally valid rule. In the case of only two voices, using stems
48 * in the ambitus grob might help, but probably looks quite ugly.
50 * - If a piece consists of several loosely coupled sections, should
51 * there be multiple ambitus grobs allowed, one for each section?
52 * Then there probably should be some "\ambitus" event added to
53 * mudela, stating where an ambitus grob should be placed. This
54 * ambitus grob should then represent the ambitus in the range of time
55 * between this "\ambitus" event and the next one (or the end of the
56 * piece, if there is no more such event). To be compliant with the
57 * current implementation, we might implicitly assume an "\ambitus"
58 * event at the beginning of the piece, but then the question where
59 * to put this first ambitus grob (before/after the clef?) becomes
62 * - Incipits of transcribed music may need special treatment for
63 * ambitus, since, for readability, the ambitus most probably should
64 * not refer to the ancient clefs of the incipit, but rather to the
65 * clefs used in the transcribed parts.
67 class Ambitus_engraver : public Engraver
70 TRANSLATOR_DECLARATIONS (Ambitus_engraver);
71 virtual void process_music ();
72 virtual void acknowledge_grob (Grob_info);
73 virtual void stop_translation_timestep ();
74 virtual void finalize ();
77 void create_ambitus ();
79 Drul_array<Item *> heads_;
80 Drul_array<Item *> accidentals_;
81 Pitch_interval pitch_interval_;
84 Protected_scm start_key_sig_;
88 Ambitus_engraver::create_ambitus ()
90 ambitus_ = make_item ("Ambitus",SCM_EOL);
95 Ambitus_engraver::Ambitus_engraver ()
102 Ambitus_engraver::process_music ()
105 * Ensure that ambitus is created in the very first timestep (on
106 * which lily does not call start_translation_timestep ()).
107 * Otherwise, if a voice begins with a rest, the ambitus grob will
108 * be placed after the rest.
117 Ambitus_engraver::stop_translation_timestep ()
119 if (ambitus_ && !is_typeset_)
122 * Evaluate middleCPosition not until now, since otherwise we
123 * may then oversee a clef that is defined in a staff context if
124 * we are in a voice context; middleCPosition would then be
127 start_c0_ = robust_scm2int (get_property ("middleCPosition"), 0);
128 start_key_sig_ = get_property ("keySignature");
133 heads_[d] = make_item ("AmbitusNoteHead", SCM_EOL);
134 accidentals_[d] = make_item ("AmbitusAccidental", SCM_EOL);
135 heads_[d]->set_property ("accidental-grob", accidentals_[d]->self_scm ());
137 while (flip (&d) != DOWN);
143 Ambitus_engraver::acknowledge_grob (Grob_info info)
145 Item *item = dynamic_cast <Item *>(info.grob_);
148 if (Note_head::has_interface (info.grob_))
150 Music *nr = info.music_cause ();
151 if (nr && nr->is_mus_type ("note-event"))
153 Pitch pitch = *unsmob_pitch (nr->get_property ("pitch"));
154 pitch_interval_.add_point (pitch);
161 Ambitus_engraver::finalize ()
163 if (ambitus_ && !pitch_interval_.is_empty ())
168 Pitch p = pitch_interval_[d];
169 heads_[d]->set_property ("position",
170 scm_from_int (start_c0_ +
173 SCM handle = scm_assoc (scm_cons (scm_from_int (p.get_octave ()),
174 scm_from_int (p.get_notename ())),
177 int sig_alter = (handle != SCM_BOOL_F) ? ly_scm2int (ly_car (handle)) : 0;
178 if (sig_alter == p.get_alteration ())
180 accidentals_[d]->suicide();
181 heads_[d]->set_property ("accidental-grob", SCM_EOL);
185 accidentals_[d]->set_property ("accidentals",
186 scm_list_1 (scm_from_int (p.get_alteration ())));
189 while (flip (&d) != DOWN);
191 ambitus_->set_property ("note-heads", scm_list_2 (heads_[DOWN]->self_scm (),
192 heads_[UP]->self_scm ()));
199 accidentals_[d]->suicide();
200 heads_[d]->suicide();
202 while (flip (&d) != DOWN);
207 ENTER_DESCRIPTION (Ambitus_engraver,
209 /* creats*/ "Ambitus",
211 /* acks */ "note-head-interface",