]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/lyric-phrasing-engraver.hh
269d5a96587bea16e329e882d28d2b3a3e575ed0
[lilypond.git] / lily / include / lyric-phrasing-engraver.hh
1 /*
2   lyric-phrasing-engraver.hh -- declare Lyric_phrasing_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  2000 Glen Prideaux <glenprideaux@iname.com>
7 */
8
9
10 #ifndef LYRIC_PHRASING_ENGRAVER_HH
11 #define LYRIC_PHRASING_ENGRAVER_HH
12
13 #include "lily-proto.hh"
14 #include "engraver.hh"
15 #include "item.hh"
16 #include "smobs.hh"
17
18 class Syllable_group;
19
20
21 /**
22    Align lyrics with noteheads, left aligning beginning of phrases,
23    right aligning end of phrases, centering others under their notes.
24  */
25
26 /* 
27 * Build an engraver that catches noteheads and lyrics.
28
29  (It needs to be in a context above Staff and Lyrics, eg. in Score
30 context.)
31
32 * Determine which heads belong to which lyrics
33
34  (eg. by looking at the names of their originating contexts, or maybe
35 some \properties)
36
37 * Attach the lyrics to the appropriate heads
38
39  (by doing lyric->set_parent (head, X_AXIS), that will fix the current
40 noteheadwidth guessing kludge)
41
42 * Check if the lyric syllables end or start a phrase.
43
44  (eg. check if the syllable ends with punctuation, and remember that
45 fact for the next one.)
46
47 * Adjust their alignment accordingly. 
48
49  (eg. by doing lyric->add_offset_callback (centered_on_parent,X_AXIS)
50 and setting self-alignment-X)
51
52 * Add a property to switch on/off the engraver (for multi stanza
53   vs. single stanza music)
54
55 Maybe this engraver could also take care of correct lyric alignment
56 for melismas as well.
57
58
59  */
60
61
62 class Lyric_phrasing_engraver : public Engraver 
63 {
64 protected:
65   virtual void acknowledge_grob (Grob_info);
66   virtual void create_grobs ();
67   virtual void stop_translation_timestep ();
68   virtual void finalize ();  
69 private:
70   void record_notehead (const String &context_id, Grob * notehead);
71   void record_lyric (const String &context_id, Grob * lyric);
72   void record_melisma (const String &context_id);
73   void record_extender (const String &context_id, Grob * extender);
74   Syllable_group * lookup_context_id (const String &context_id);
75
76 public:
77
78   ~Lyric_phrasing_engraver ();
79   TRANSLATOR_DECLARATIONS(  Lyric_phrasing_engraver);
80
81 private:
82   /** association list of Syllable_group smobs
83   */
84   Protected_scm voice_alist_;
85   Grob * any_notehead_l_;
86 };
87
88
89 class Syllable_group
90 {
91   bool first_in_phrase_b_;
92   Grob * notehead_l_;
93   Link_array<Grob> lyric_list_;
94   Grob * longest_lyric_l_;
95   Grob * shortest_lyric_l_;
96   int alignment_i_;
97   bool melisma_b_;
98   Real group_translation_f_;
99 public:
100   static SCM make_entry ();
101   void set_first_in_phrase (bool f);
102   void set_notehead (Grob * notehead);
103   void add_lyric (Grob * lyric);
104   void add_extender (Grob * extender);
105   void set_melisma () { melisma_b_ = true; }
106   bool get_melisma () { return melisma_b_; }
107   int lyric_count () { return lyric_list_.size (); }
108   void clear ();
109   bool is_empty ();
110   bool set_lyric_align (const char *punc, Grob *default_notehead_l);
111   void adjust_melisma_align ();
112   int appropriate_alignment (const char *punc);
113   Real amount_to_translate ();
114   void next_lyric ();
115   void copy (Syllable_group *);
116 private:
117   Syllable_group ();
118   DECLARE_SIMPLE_SMOBS (Syllable_group,);
119 } ;
120
121 Syllable_group * unsmob_voice_entry (SCM);
122
123
124 #endif // LYRIC_PHRASING_ENGRAVER_HH