-/*
- new-chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver
-
+/*
+ new-chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver
+
source file of the GNU LilyPond music typesetter
-
- (c) 2000--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-
- */
-#include "engraver.hh"
-#include "repeated-music.hh"
-#include "engraver-group-engraver.hh"
-#include "global-translator.hh"
-#include "warn.hh"
-#include "misc.hh"
-#include "spanner.hh"
-#include "item.hh"
-#include "percent-repeat-iterator.hh"
-#include "bar.hh"
+ (c) 2000--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>, Erik Sandberg <mandolaerik@gmail.com>
+*/
-#include "score-engraver.hh"
-#include "translator-group.hh"
-/**
- This acknowledges repeated music with "percent" style. It typesets
- a % sign.
+#include "score-engraver.hh"
- TODO:
+#include "bar-line.hh"
+#include "global-context.hh"
+#include "international.hh"
+#include "item.hh"
+#include "misc.hh"
+#include "percent-repeat-iterator.hh"
+#include "repeated-music.hh"
+#include "score-context.hh"
+#include "side-position-interface.hh"
+#include "spanner.hh"
+#include "warn.hh"
- - BEAT case: Create items for single beat repeats, i.e. c4 / / /
+#include "translator.icc"
- - DOUBLE_MEASURE case: attach a % to an appropriate barline.
-
+/*
+* TODO: Create separate Double_percent_repeat_engraver?
+* Or, at least move double percent handling to Slash_repeat_engraver
*/
+
class Percent_repeat_engraver : public Engraver
{
void typeset_perc ();
public:
- VIRTUAL_COPY_CONS (Translator);
- Percent_repeat_engraver ();
+ TRANSLATOR_DECLARATIONS (Percent_repeat_engraver);
+
protected:
- Repeated_music * repeat_;
+ Music *percent_event_;
- /// moment (global time) where beam started.
- Moment start_mom_;
+ /// moment (global time) where percent started.
Moment stop_mom_;
+ Moment start_mom_;
+
+ enum Repeat_sign_type
+ {
+ UNKNOWN,
+ MEASURE,
+ DOUBLE_MEASURE,
+ };
+ Repeat_sign_type repeat_sign_type_;
+
+ Spanner *percent_;
+ Spanner *percent_counter_;
- /// location within measure where beam started.
- Moment beam_start_location_;
- Moment next_moment_;
- Moment body_length_;
-
- enum {
- UNKNOWN,
- BEAT,
- MEASURE,
- DOUBLE_MEASURE,
- } repeat_sign_type_ ;
-
- Item * beat_slash_;
- Item * double_percent_;
- Spanner * perc_p_;
- Spanner * finished_perc_p_;
- Item * stem_tremolo_;
protected:
virtual void finalize ();
- virtual bool try_music (Music*);
- virtual void stop_translation_timestep ();
- virtual void start_translation_timestep ();
- virtual void process_music ();
+ virtual bool try_music (Music *);
+
+ void stop_translation_timestep ();
+ void start_translation_timestep ();
+ void process_music ();
};
Percent_repeat_engraver::Percent_repeat_engraver ()
{
- perc_p_ = finished_perc_p_ = 0;
- repeat_ =0;
- stem_tremolo_ = 0;
+ percent_ = 0;
+ percent_counter_ = 0;
- beat_slash_ = 0;
- double_percent_ = 0;
+ percent_event_ = 0;
}
bool
-Percent_repeat_engraver::try_music (Music * m)
+Percent_repeat_engraver::try_music (Music *m)
{
- Repeated_music * rp = dynamic_cast<Repeated_music*> (m);
- if (rp
- && rp->get_mus_property ("iterator-ctor")
- == Percent_repeat_iterator::constructor_cxx_function
- && !repeat_)
+ if (m->is_mus_type ("percent-event")
+ && !percent_event_)
{
- body_length_ = rp->body_length_mom ();
- int count = rp->repeat_count ();
-
- Moment now = now_mom ();
- start_mom_ = now;
- stop_mom_ = start_mom_ + Moment (count) * body_length_;
- next_moment_ = start_mom_ + body_length_;
-
- SCM m = get_property ("measureLength");
- Moment meas_len;
- if (unsmob_moment (m))
- meas_len = *unsmob_moment (m);
-
- if (body_length_ < meas_len &&
- meas_len.main_part_.mod_rat (body_length_.main_part_) == Moment (0,0))
- repeat_sign_type_ = BEAT;
- else if (meas_len == body_length_)
+ Moment body_length = m->get_length ();
+ Moment meas_len (robust_scm2moment (get_property ("measureLength"),
+ Moment (1)));
+
+ if (meas_len == body_length)
+ {
repeat_sign_type_ = MEASURE;
- else if (Moment (2)* meas_len == body_length_)
- {
- repeat_sign_type_ = DOUBLE_MEASURE;
- next_moment_ += meas_len ;
- }
+ 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_);
+ }
else
- {
- warning (_ ("Don't know how to handle a percent repeat of this length."));
- return false;
- }
-
- repeat_ = rp;
+ return false;
-
- Global_translator *global_l =0;
- Translator *t = this;
- do
- {
- t = t->daddy_trans_l_ ;
- global_l = dynamic_cast<Global_translator*> (t);
- }
- while (!global_l);
+ percent_event_ = m;
- for (int i = 0; i < count; i++)
- global_l->add_moment_to_process (now + Moment (1+i) * body_length_);
-
return true;
}
void
Percent_repeat_engraver::process_music ()
{
- if (repeat_ && now_mom () == next_moment_)
+ if (percent_event_ && now_mom ().main_part_ == start_mom_.main_part_)
{
- if (repeat_sign_type_ == BEAT)
+ if (repeat_sign_type_ == MEASURE)
{
- beat_slash_ = new Item (get_property ("RepeatSlash"));
- announce_grob (beat_slash_, repeat_);
- }
- else if (repeat_sign_type_ == MEASURE)
- {
- finished_perc_p_ = perc_p_;
- typeset_perc ();
- perc_p_ = new Spanner (get_property ("PercentRepeat"));
- SCM col =get_property ("currentCommandColumn");
- perc_p_->set_bound (LEFT, unsmob_grob (col));
- announce_grob (perc_p_, repeat_);
+ if (percent_)
+ typeset_perc ();
+ percent_ = make_spanner ("PercentRepeat", percent_event_->self_scm ());
+
+ Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
+ percent_->set_bound (LEFT, col);
+
+ SCM count = percent_event_->get_property ("repeat-count");
+ if (count != SCM_EOL && to_boolean (get_property ("countPercentRepeats")))
+ {
+ percent_counter_
+ = make_spanner ("PercentRepeatCounter", percent_event_->self_scm ());
+
+ SCM text = scm_number_to_string (count, scm_from_int (10));
+ percent_counter_->set_property ("text", text);
+ percent_counter_->set_bound (LEFT, col);
+ Side_position_interface::add_support (percent_counter_,
+ percent_);
+ percent_counter_->set_parent (percent_, Y_AXIS);
+ }
+ else
+ percent_counter_ = 0;
}
else if (repeat_sign_type_ == DOUBLE_MEASURE)
-
{
- double_percent_ = new Item (get_property ("DoublePercentRepeat"));
- announce_grob (double_percent_, repeat_);
-
- /*
- forbid breaks on a % line. Should forbid all breaks, really.
- */
- Score_engraver * e = 0;
- Translator * t = daddy_grav_l ();
- for (; !e && t; t = t->daddy_trans_l_)
+ 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")))
{
- e = dynamic_cast<Score_engraver*> (t);
+ Item *double_percent_counter = make_item ("DoublePercentRepeatCounter",
+ percent_event_->self_scm());
+
+ SCM text = scm_number_to_string (count,
+ scm_from_int (10));
+ double_percent_counter->set_property ("text", text);
+
+ Side_position_interface::add_support (double_percent_counter,
+ double_percent);
+ double_percent_counter->set_parent (double_percent, Y_AXIS);
+ double_percent_counter->set_parent (double_percent, X_AXIS);
}
+
+ /* forbid breaks on a % line. Should forbid all breaks, really. */
+ context ()->get_score_context ()->set_property ("forbidBreak", SCM_BOOL_T);
- if (!e)
- programming_error ("No score engraver!");
- else
- e->forbid_breaks (); // guh. Use properties!
+ /* No more processing needed. */
+ repeat_sign_type_ = UNKNOWN;
}
- next_moment_ = next_moment_ + body_length_;
}
}
void
Percent_repeat_engraver::finalize ()
{
- typeset_perc ();
- if (perc_p_)
+ if (percent_)
{
- repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
- perc_p_->suicide ();
+ percent_event_->origin ()->warning (_ ("unterminated percent repeat"));
+ percent_->suicide ();
+ percent_counter_->suicide();
}
}
void
Percent_repeat_engraver::typeset_perc ()
{
- if (finished_perc_p_)
+ if (percent_)
{
- SCM col =get_property ("currentCommandColumn");
- finished_perc_p_->set_bound (RIGHT, unsmob_grob (col));
- typeset_grob (finished_perc_p_);
- finished_perc_p_ = 0;
- }
+ Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
- if (beat_slash_)
- {
- typeset_grob (beat_slash_);
- beat_slash_ = 0;
- }
+ percent_->set_bound (RIGHT, col);
+ percent_ = 0;
- if (double_percent_)
- {
- typeset_grob (double_percent_);
- double_percent_ = 0;
+ if (percent_counter_)
+ percent_counter_->set_bound (RIGHT, col);
+ percent_counter_ = 0;
}
}
-
-
-
void
Percent_repeat_engraver::start_translation_timestep ()
{
- if (stop_mom_ == now_mom ())
+ if (stop_mom_.main_part_ == now_mom ().main_part_)
{
- if (perc_p_)
- {
- finished_perc_p_ = perc_p_;
- typeset_perc ();
- }
- repeat_ = 0;
- perc_p_ = 0;
+ if (percent_)
+ typeset_perc ();
+ percent_event_ = 0;
repeat_sign_type_ = UNKNOWN;
}
}
-
void
Percent_repeat_engraver::stop_translation_timestep ()
{
- typeset_perc ();
}
-ADD_THIS_TRANSLATOR (Percent_repeat_engraver);
-
-
+ADD_TRANSLATOR (Percent_repeat_engraver,
+ /* doc */
+ "Make whole bar and double bar repeats.",
+
+ /* create */
+ "DoublePercentRepeat "
+ "DoublePercentRepeatCounter "
+ "PercentRepeat "
+ "PercentRepeatCounter ",
+
+ /* accept */
+ "percent-event ",
+
+ /* read */
+ "countPercentRepeats "
+ "currentCommandColumn "
+ "measureLength ",
+
+ /* write */
+ "forbidBreak "
+ );