]> git.donarmstrong.com Git - lilypond.git/blob - lily/ambitus-engraver.cc
remove
[lilypond.git] / lily / ambitus-engraver.cc
1 /*
2   ambitus-engraver.cc -- implement Ambitus_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2002--2004 Juergen Reuter <reuter@ipd.uka.de>
7 */
8
9 #include "engraver.hh"
10 #include "item.hh"
11 #include "note-head.hh"
12 #include "staff-symbol-referencer.hh"
13 #include "event.hh"
14 #include "pitch.hh"
15
16
17 /*
18   UGH UGH UGH .
19
20   rewrite this complely. --hwn
21  */
22
23 /*
24  * This class implements an engraver for ambitus grobs.
25  *
26  * TODO: There are quite some conceptional issues left open:
27  *
28  * - Many publishers put ambitus _before_ the first occurrence of a
29  * clef.  Hence, formally the pitches are undefined in this case.  Of
30  * course, one could always silently assume that ambitus pitches refer
31  * to the first occurrence of a clef.  Or should we, by default, put
32  * the ambitus always after the first clef, if any?
33  *
34  * - Enharmonically equal pitches: Assume piece contains once a "gis",
35  * another time an "aes" as highest pitch.  Which one should be
36  * selected for the ambitus grob?  The "aes", because it is
37  * musically/notationally "higher" than "gis"?  Or "gis", because (if
38  * using pure temperament) it has a slightly higher frequency?  Or
39  * that pitch that come closer to the key signature?  But there may be
40  * key signature changes in the piece...
41  *
42  * - Multiple voices in single staff: Assume a vocal piece of music,
43  * where the soprano voice and the alto voice are put into the same
44  * staff (this is generally a bad idea, but unfortunately common
45  * practice).  Then, there probably should be two ambitus grobs, one
46  * for each voice.  But how can you see which ambitus grob refers to
47  * which voice?  Most probably you can guess it from the fact that the
48  * ambitus of the alto voice typically lies in a lower range than that
49  * of the soprano voice, but this is just a heuristic rather than a
50  * generally valid rule.  In the case of only two voices, using stems
51  * in the ambitus grob might help, but probably looks quite ugly.
52  *
53  * - If a piece consists of several loosely coupled sections, should
54  * there be multiple ambitus grobs allowed, one for each section?
55  * Then there probably should be some "\ambitus" event added to
56  * mudela, stating where an ambitus grob should be placed.  This
57  * ambitus grob should then represent the ambitus in the range of time
58  * between this "\ambitus" event and the next one (or the end of the
59  * piece, if there is no more such event).  To be compliant with the
60  * current implementation, we might implicitly assume an "\ambitus"
61  * event at the beginning of the piece, but then the question where
62  * to put this first ambitus grob (before/after the clef?) becomes
63  * even more urgent.
64  *
65  * - Incipits of transcribed music may need special treatment for
66  * ambitus, since, for readability, the ambitus most probably should
67  * not refer to the ancient clefs of the incipit, but rather to the
68  * clefs used in the transcribed parts.
69  */
70 class Ambitus_engraver : public Engraver
71 {
72 public:
73 TRANSLATOR_DECLARATIONS (Ambitus_engraver);
74   virtual void process_music ();
75   virtual void acknowledge_grob (Grob_info);
76   virtual void stop_translation_timestep ();
77   virtual void finalize ();
78
79 private:
80   void create_ambitus ();
81   Item *ambitus_;
82   bool is_typeset;
83   Pitch pitch_min, pitch_max;
84 };
85
86 Ambitus_engraver::Ambitus_engraver ()
87 {
88   ambitus_ = 0;
89   is_typeset = 0;
90
91   /*
92    * (pitch_min > pitch_max) means that pitches are not yet
93    * initialized
94    */
95   pitch_min = Pitch (0, 0, SHARP);
96   pitch_max = Pitch (0, 0, FLAT);
97 }
98
99 void
100 Ambitus_engraver::process_music ()
101 {
102   /*
103    * Ensure that ambitus is created in the very first timestep (on
104    * which lily does not call start_translation_timestep ()).
105    * Otherwise, if a voice begins with a rest, the ambitus grob will
106    * be placed after the rest.
107    */
108   if (!ambitus_) {
109     create_ambitus ();
110   }
111 }
112
113 void
114 Ambitus_engraver::stop_translation_timestep ()
115 {
116   if (ambitus_ && !is_typeset)
117     {
118       /*
119        * Evaluate middleCPosition not until now, since otherwise we
120        * may then oversee a clef that is defined in a staff context if
121        * we are in a voice context; middleCPosition would then be
122        * assumed to be 0.
123        */
124       SCM c0 = get_property ("middleCPosition");
125       ambitus_->set_property ("c0-position", c0);
126
127       /*
128        * Similar for keySignature.
129        */
130       SCM key_signature = get_property ("keySignature");
131       ambitus_->set_property ("accidentals", key_signature);
132
133       
134       is_typeset = true;
135     }
136 }
137
138 void
139 Ambitus_engraver::acknowledge_grob (Grob_info info)
140 {
141   Item *item = dynamic_cast <Item *>(info.grob_);
142   if (item)
143     {
144       if (Note_head::has_interface (info.grob_))
145         {
146           Music *nr = info.music_cause ();
147           if (nr && nr->is_mus_type ("note-event"))
148             {
149               Pitch pitch = *unsmob_pitch (nr->get_property ("pitch"));
150               if (Pitch::compare (pitch_min, pitch_max) > 0) // already init'd?
151                 {
152                   // not yet init'd; use current pitch to init min/max
153                   pitch_min = pitch;
154                   pitch_max = pitch;
155                 }
156               else if (Pitch::compare (pitch, pitch_max) > 0) // new max?
157                 {
158                   pitch_max = pitch;
159                 }
160               else if (Pitch::compare (pitch, pitch_min) < 0) // new min?
161                 {
162                   pitch_min = pitch;
163                 }
164             }
165         }
166     }
167 }
168
169 void
170 Ambitus_engraver::create_ambitus ()
171 {
172   ambitus_ = make_item ("Ambitus",SCM_EOL);
173   is_typeset = false;           
174 }
175
176 void
177 Ambitus_engraver::finalize ()
178 {
179   if (ambitus_)
180     {
181       if (Pitch::compare (pitch_min, pitch_max) <= 0)
182         {
183           ambitus_->set_property ("pitch-min",
184                                   pitch_min.smobbed_copy ());
185           ambitus_->set_property ("pitch-max",
186                                   pitch_max.smobbed_copy ());
187         }
188       else // have not seen any pitch, so forget about the ambitus
189         {
190           /*
191            * Do not print a warning on empty ambitus range, since this
192            * most probably arises from an empty voice, such as shared
193            * global timesig/clef definitions.
194            */
195           ambitus_->suicide ();
196         }
197     }
198 }
199
200 ENTER_DESCRIPTION (Ambitus_engraver,
201 /* descr */       "",
202 /* creats*/       "Ambitus",
203 /* accepts */ "",
204 /* acks  */     "note-head-interface",
205 /* reads */       "",
206 /* write */       "");