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