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>
10 #include "engraver.hh"
11 #include "translator-group.hh"
12 #include "volta-spanner.hh"
14 #include "note-column.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
25 TRANSLATOR_DECLARATIONS(Volta_engraver);
28 virtual void acknowledge_grob (Grob_info);
29 virtual void finalize ();
30 virtual void stop_translation_timestep ();
31 virtual void process_music ();
32 virtual void create_grobs ();
35 Spanner *volta_span_p_;
36 Spanner *end_volta_span_p_;
41 Volta_engraver::Volta_engraver ()
44 end_volta_span_p_ = 0;
49 Volta_engraver::process_music ()
51 SCM cs = get_property ("repeatCommands");
55 while (gh_pair_p (cs))
59 if (gh_pair_p (c) && ly_car (c) == ly_symbol2scm ("volta")
60 && gh_pair_p (ly_cdr (c)))
62 if (ly_cadr (c) == SCM_BOOL_F)
65 start_str_ = ly_cadr (c);
73 SCM l (get_property ("voltaSpannerDuration"));
74 Moment now = now_mom ();
76 bool early_stop = unsmob_moment (l)
77 && *unsmob_moment (l) <= now - started_mom_;
79 end = end || early_stop;
83 if (end && !volta_span_p_)
85 warning (_ ("No volta spanner to end")); // fixme: be more verbose.
89 end_volta_span_p_ = volta_span_p_;
93 maybe do typeset_grob () directly?
96 if (!gh_string_p (start_str_))
97 end_volta_span_p_->set_grob_property ("last-volta", SCM_BOOL_T);
100 if (gh_string_p (start_str_) && volta_span_p_)
102 warning (_ ("Already have a volta spanner. Stopping that one prematurely."));
104 if (end_volta_span_p_)
106 warning (_ ("Also have a stopped spanner. Giving up."));
110 end_volta_span_p_ = volta_span_p_;
116 this could just as well be done in process_music (), but what the hack.
119 Volta_engraver::create_grobs ()
121 if (!volta_span_p_ && gh_string_p (start_str_))
123 started_mom_ = now_mom () ;
125 volta_span_p_ = new Spanner (get_property ("VoltaBracket"));
126 Volta_spanner::set_interface (volta_span_p_);
127 announce_grob (volta_span_p_,0);
128 volta_span_p_->set_grob_property ("text", start_str_);
133 Volta_engraver::acknowledge_grob (Grob_info i)
135 if (Item* item = dynamic_cast<Item*> (i.grob_l_))
137 if (Note_column::has_interface (item))
140 Volta_spanner::add_column (volta_span_p_,item);
142 if (Bar::has_interface (item))
145 Volta_spanner::add_bar (volta_span_p_, item);
146 if (end_volta_span_p_)
147 Volta_spanner::add_bar (end_volta_span_p_ , item);
153 Volta_engraver::finalize ()
157 typeset_grob (volta_span_p_);
159 if (end_volta_span_p_)
161 typeset_grob (end_volta_span_p_);
168 Volta_engraver::stop_translation_timestep ()
170 if (end_volta_span_p_)
172 Side_position_interface::add_staff_support (end_volta_span_p_);
174 typeset_grob (end_volta_span_p_);
175 end_volta_span_p_ =0;
180 TODO: should attach volta to paper-column if no bar is found.
183 ENTER_DESCRIPTION(Volta_engraver,
184 /* descr */ "Make volta brackets",
185 /* creats*/ "VoltaBracket",
186 /* acks */ "bar-line-interface note-column-interface",
187 /* reads */ "repeatCommands voltaSpannerDuration",