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