/*
- new-chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver
+ This file is part of LilyPond, the GNU music typesetter.
- source file of the GNU LilyPond music typesetter
+ Copyright (C) 2000--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>, Erik Sandberg <mandolaerik@gmail.com>
- (c) 2000--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>, Erik Sandberg <mandolaerik@gmail.com>
+ LilyPond is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ LilyPond is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
*/
#include "international.hh"
#include "item.hh"
#include "misc.hh"
-#include "percent-repeat-iterator.hh"
#include "repeated-music.hh"
#include "side-position-interface.hh"
#include "spanner.hh"
+#include "stream-event.hh"
#include "warn.hh"
#include "translator.icc"
class Percent_repeat_engraver : public Engraver
{
void typeset_perc ();
+ bool check_count_visibility (SCM count);
public:
TRANSLATOR_DECLARATIONS (Percent_repeat_engraver);
protected:
- Music *percent_event_;
+ Stream_event *percent_event_;
/// moment (global time) where percent started.
Moment stop_mom_;
Spanner *percent_;
Spanner *percent_counter_;
+
+ Grob *first_command_column_;
+ Moment command_moment_;
+
protected:
virtual void finalize ();
- virtual bool try_music (Music *);
+ DECLARE_TRANSLATOR_LISTENER (percent);
void stop_translation_timestep ();
void start_translation_timestep ();
{
percent_ = 0;
percent_counter_ = 0;
-
percent_event_ = 0;
+
+ first_command_column_ = 0;
+ command_moment_ = Moment (-1);
}
-bool
-Percent_repeat_engraver::try_music (Music *m)
+void
+Percent_repeat_engraver::start_translation_timestep ()
+{
+ if (now_mom ().main_part_ != command_moment_.main_part_)
+ {
+ first_command_column_ = unsmob_grob (get_property ("currentCommandColumn"));
+ command_moment_ = now_mom ();
+ }
+
+ if (stop_mom_.main_part_ == now_mom ().main_part_)
+ {
+ if (percent_)
+ typeset_perc ();
+ percent_event_ = 0;
+ repeat_sign_type_ = UNKNOWN;
+ }
+}
+
+IMPLEMENT_TRANSLATOR_LISTENER (Percent_repeat_engraver, percent);
+void
+Percent_repeat_engraver::listen_percent (Stream_event *ev)
{
- if (m->is_mus_type ("percent-event")
- && !percent_event_)
+ if (!percent_event_)
{
- Moment body_length = m->get_length ();
+ Moment body_length = get_event_length (ev);
Moment meas_len (robust_scm2moment (get_property ("measureLength"),
Moment (1)));
-
if (meas_len == body_length)
- {
- repeat_sign_type_ = MEASURE;
- start_mom_ = now_mom ();
- stop_mom_ = now_mom () + body_length;
- get_global_context ()->add_moment_to_process (stop_mom_);
- }
+ {
+ repeat_sign_type_ = MEASURE;
+ start_mom_ = now_mom ();
+ stop_mom_ = now_mom () + body_length;
+ get_global_context ()->add_moment_to_process (stop_mom_);
+ }
else if (Moment (2) * meas_len == body_length)
- {
- repeat_sign_type_ = DOUBLE_MEASURE;
- start_mom_ = now_mom () + meas_len;
- stop_mom_ = now_mom () + body_length; /* never used */
- get_global_context ()->add_moment_to_process (start_mom_);
- }
+ {
+ repeat_sign_type_ = DOUBLE_MEASURE;
+ start_mom_ = now_mom () + meas_len;
+ stop_mom_ = now_mom () + body_length; /* never used */
+ get_global_context ()->add_moment_to_process (start_mom_);
+ }
else
- return false;
-
- percent_event_ = m;
-
- return true;
+ {
+ /*
+ don't warn about percent repeats: slash repeats are not
+ exactly 1 or 2 measures long.
+ */
+ return;
+ }
+ percent_event_ = ev;
}
-
- return false;
+ else
+ /* print a warning: no assignment happens because
+ percent_event_ != 0 */
+ ASSIGN_EVENT_ONCE (percent_event_, ev);
}
void
{
if (percent_)
typeset_perc ();
+
percent_ = make_spanner ("PercentRepeat", percent_event_->self_scm ());
- Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
+ Grob *col = first_command_column_;
percent_->set_bound (LEFT, col);
SCM count = percent_event_->get_property ("repeat-count");
- if (count != SCM_EOL && to_boolean (get_property ("countPercentRepeats")))
+ if (count != SCM_EOL && to_boolean (get_property ("countPercentRepeats"))
+ && check_count_visibility (count))
{
percent_counter_
= make_spanner ("PercentRepeatCounter", percent_event_->self_scm ());
Item *double_percent = make_item ("DoublePercentRepeat", percent_event_->self_scm ());
SCM count = percent_event_->get_property ("repeat-count");
- if (count != SCM_EOL
- && to_boolean (get_property ("countPercentRepeats")))
+ if (count != SCM_EOL && to_boolean (get_property ("countPercentRepeats"))
+ && check_count_visibility (count))
{
Item *double_percent_counter = make_item ("DoublePercentRepeatCounter",
- percent_event_->self_scm());
+ percent_event_->self_scm ());
SCM text = scm_number_to_string (count,
scm_from_int (10));
{
percent_event_->origin ()->warning (_ ("unterminated percent repeat"));
percent_->suicide ();
- percent_counter_->suicide();
+ percent_counter_->suicide ();
}
}
{
if (percent_)
{
- Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
+ Grob *col = first_command_column_;
percent_->set_bound (RIGHT, col);
percent_ = 0;
}
}
-void
-Percent_repeat_engraver::start_translation_timestep ()
+bool
+Percent_repeat_engraver::check_count_visibility (SCM count)
{
- if (stop_mom_.main_part_ == now_mom ().main_part_)
- {
- if (percent_)
- typeset_perc ();
- percent_event_ = 0;
- repeat_sign_type_ = UNKNOWN;
- }
+ SCM proc = get_property ("repeatCountVisibility");
+ return (ly_is_procedure (proc) && to_boolean (scm_call_2 (proc,
+ count,
+ context ()->self_scm ())));
}
+
void
Percent_repeat_engraver::stop_translation_timestep ()
{
"DoublePercentRepeatCounter "
"PercentRepeat "
"PercentRepeatCounter ",
-
- /* accept */
- "percent-event ",
/* read */
"countPercentRepeats "
"currentCommandColumn "
- "measureLength ",
+ "measureLength "
+ "repeatCountVisibility ",
/* write */
"forbidBreak "