lilypond-1.3.154
[lilypond.git] / lily / volta-engraver.cc
bloba3e14ce4833708d9a8cbc45e2ead04821ec6761a
1 /*
2 volta-engraver.cc -- implement Volta_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "engraver.hh"
11 #include "translator-group.hh"
12 #include "volta-spanner.hh"
13 #include "item.hh"
14 #include "note-column.hh"
15 #include "bar.hh"
16 #include "side-position-interface.hh"
19 Create Volta spanners, by reading repeatCommands property, usually
20 set by Unfolded_repeat_iterator.
22 class Volta_engraver : public Engraver
24 public:
25 Volta_engraver ();
26 VIRTUAL_COPY_CONS (Translator);
27 protected:
29 virtual void acknowledge_grob (Grob_info);
30 virtual void finalize ();
31 virtual void stop_translation_timestep ();
32 virtual void process_music ();
33 virtual void create_grobs ();
35 Moment started_mom_;
36 Spanner *volta_span_p_;
37 Spanner *end_volta_span_p_;
39 SCM start_str_;
42 ADD_THIS_TRANSLATOR (Volta_engraver);
44 Volta_engraver::Volta_engraver ()
46 volta_span_p_ = 0;
47 end_volta_span_p_ = 0;
51 void
52 Volta_engraver::process_music ()
54 SCM cs = get_property ("repeatCommands");
56 bool end = false;
57 start_str_ = SCM_EOL;
58 while (gh_pair_p (cs))
60 SCM c = gh_car (cs);
62 if (gh_pair_p (c) && gh_car (c) == ly_symbol2scm ("volta"))
64 if (gh_cadr (c) == SCM_BOOL_F)
65 end = true;
66 else
67 start_str_ = gh_cadr (c);
70 cs = gh_cdr (cs);
73 if (volta_span_p_)
75 SCM l (get_property ("voltaSpannerDuration"));
76 Moment now = now_mom ();
78 bool early_stop = unsmob_moment (l)
79 && *unsmob_moment (l) <= now - started_mom_;
81 end = end || early_stop;
85 if (end && !volta_span_p_)
87 warning (_ ("No volta spanner to end")); // fixme: be more verbose.
89 else if (end)
91 end_volta_span_p_ = volta_span_p_;
92 volta_span_p_ =0;
95 maybe do typeset_grob () directly?
98 if (!gh_string_p (start_str_))
99 end_volta_span_p_->set_grob_property ("last-volta", SCM_BOOL_T);
102 if (gh_string_p (start_str_) && volta_span_p_)
104 warning (_ ("Already have a volta spanner. Stopping that one prematurely."));
106 if (end_volta_span_p_)
108 warning (_ ("Also have a stopped spanner. Giving up."));
109 return ;
112 end_volta_span_p_ = volta_span_p_;
113 volta_span_p_ = 0;
118 this could just as well be done in process_music (), but what the hack.
120 void
121 Volta_engraver::create_grobs ()
123 if (!volta_span_p_ && gh_string_p (start_str_))
125 started_mom_ = now_mom () ;
127 volta_span_p_ = new Spanner (get_property ("VoltaBracket"));
128 Volta_spanner::set_interface (volta_span_p_);
129 announce_grob (volta_span_p_,0);
130 volta_span_p_->set_grob_property ("text", start_str_);
134 void
135 Volta_engraver::acknowledge_grob (Grob_info i)
137 if (Item* item = dynamic_cast<Item*> (i.elem_l_))
139 if (Note_column::has_interface (item))
141 if (volta_span_p_)
142 Volta_spanner::add_column (volta_span_p_,item);
143 if (end_volta_span_p_)
144 Volta_spanner::add_column (end_volta_span_p_,item);
146 if (Bar::has_interface (item))
148 if (volta_span_p_)
149 Volta_spanner::add_bar (volta_span_p_, item);
150 if (end_volta_span_p_)
151 Volta_spanner::add_bar (end_volta_span_p_ , item);
156 void
157 Volta_engraver::finalize ()
159 if (volta_span_p_)
161 typeset_grob (volta_span_p_);
163 if (end_volta_span_p_)
165 typeset_grob (end_volta_span_p_);
171 void
172 Volta_engraver::stop_translation_timestep ()
174 if (end_volta_span_p_)
176 Side_position_interface::add_staff_support (end_volta_span_p_);
178 typeset_grob (end_volta_span_p_);
179 end_volta_span_p_ =0;
184 TODO: should attach volta to paper-column if no bar is found.