]> git.donarmstrong.com Git - lilypond.git/blob - lily/trill-spanner-engraver.cc
* configure.in: Test for and accept lmodern if EC fonts not found.
[lilypond.git] / lily / trill-spanner-engraver.cc
1 /*
2   trill-spanner-engraver.cc -- implement Trill_spanner_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 /*
10   C&P from text-spanner.cc
11
12   - todo: ending should be detected automatically? a new note
13     automatically is the end of the trill?
14   
15  */
16
17 #include "note-column.hh"
18 #include "side-position-interface.hh"
19 #include "engraver.hh"
20
21 class Trill_spanner_engraver : public Engraver
22 {
23 public:
24   TRANSLATOR_DECLARATIONS (Trill_spanner_engraver);  
25 protected:
26   virtual void finalize ();
27   virtual void acknowledge_grob (Grob_info);
28   virtual bool try_music (Music *);
29   virtual void stop_translation_timestep ();
30   virtual void process_music ();
31
32 private:
33   Spanner *span_;
34   Spanner *finished_;
35   Music *current_req_;
36   Drul_array<Music*> req_drul_;
37   void typeset_all ();
38 };
39
40
41 Trill_spanner_engraver::Trill_spanner_engraver ()
42 {
43   finished_ = 0;
44   current_req_ = 0;
45   span_ =0;
46   req_drul_[START] = 0;
47   req_drul_[STOP] = 0;
48 }
49
50 bool
51 Trill_spanner_engraver::try_music (Music *m)
52 {
53   if (m->is_mus_type ("trill-span-event"))
54     {
55       Direction d = to_dir (m->get_property ("span-direction"));
56       req_drul_[d] = m;
57       return true;
58     }
59
60   return false;
61 }
62
63 void
64 Trill_spanner_engraver::process_music ()
65 {
66   if (req_drul_[STOP])
67     {
68       if (!span_)
69         {
70           req_drul_[STOP]->origin ()->warning (_ ("can't find start of trill spanner"));
71         }
72       else
73         {
74           finished_ = span_;
75           span_ = 0;
76           current_req_ = 0;
77         }
78     }
79
80   if (req_drul_[START])
81     {
82       if (current_req_)
83         {
84           req_drul_[START]->origin ()->warning (_ ("already have a trill spanner"));
85         }
86       else
87         {
88           current_req_ = req_drul_[START];
89           span_  = make_spanner ("TrillSpanner", req_drul_[START]->self_scm ());
90           Side_position_interface::set_axis (span_, Y_AXIS);
91           req_drul_[START] = 0;
92         }
93     }
94 }
95
96 void
97 Trill_spanner_engraver::acknowledge_grob (Grob_info info)
98 {
99   Spanner * spans[2] ={span_, finished_};
100   for (int i = 0;  i < 2 ; i++)
101     {
102       if (spans[i] && Note_column::has_interface (info.grob_))
103         {
104           Side_position_interface::add_support (spans[i], info.grob_);
105           add_bound_item (spans[i], dynamic_cast<Item*> (info.grob_));
106         }
107     }
108 }
109
110 void
111 Trill_spanner_engraver::typeset_all ()
112 {  
113   if (finished_)
114     {
115       if (!finished_->get_bound (RIGHT))
116         {
117           Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
118           finished_->set_bound (RIGHT, e);
119         }
120       finished_ = 0;
121     }
122 }
123
124 void
125 Trill_spanner_engraver::stop_translation_timestep ()
126 {
127   if (span_ && !span_->get_bound (LEFT))
128     {
129       Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
130       span_->set_bound (LEFT, e);
131     }
132
133   typeset_all ();
134   req_drul_[START] = 0;
135   req_drul_[STOP] = 0;
136 }
137
138 void
139 Trill_spanner_engraver::finalize ()
140 {
141   typeset_all ();
142   if (span_)
143     {
144       current_req_->origin ()->warning (_ ("unterminated trill spanner"));
145       span_->suicide ();
146       span_ = 0;
147     }
148 }
149
150 ENTER_DESCRIPTION (Trill_spanner_engraver,
151 /* descr */       "Create trill spanner from a Music.",
152 /* creats*/       "TrillSpanner",
153 /* accepts */     "trill-span-event",
154 /* acks  */      "note-column-interface",
155 /* reads */       "",
156 /* write */       "");