X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fslash-repeat-engraver.cc;h=dbb55c1b385fead81d12454a018ae40fa0765040;hb=5b4b0d6e9a197e8f9eb085b7c2ad78b8be3e5cfc;hp=8cd9bc76c15918c5ab09a838011ec3d2800fa1d4;hpb=f2c2c5c43858f323e4708f83fd97e0f38017c275;p=lilypond.git diff --git a/lily/slash-repeat-engraver.cc b/lily/slash-repeat-engraver.cc index 8cd9bc76c1..dbb55c1b38 100644 --- a/lily/slash-repeat-engraver.cc +++ b/lily/slash-repeat-engraver.cc @@ -3,122 +3,80 @@ source file of the GNU LilyPond music typesetter - (c) 2000--2005 Han-Wen Nienhuys + (c) 2000--2008 Han-Wen Nienhuys , Erik Sandberg + */ -#include "repeated-music.hh" +#include "bar-line.hh" #include "global-context.hh" -#include "warn.hh" -#include "misc.hh" -#include "spanner.hh" +#include "international.hh" #include "item.hh" -#include "percent-repeat-iterator.hh" -#include "bar-line.hh" +#include "misc.hh" +#include "repeated-music.hh" #include "score-engraver.hh" +#include "spanner.hh" +#include "stream-event.hh" +#include "warn.hh" + +#include "translator.icc" /** This acknowledges repeated music with "percent" style. It typesets - a % sign. - - TODO: - - - BEAT case: Create items for single beat repeats, i.e. c4 / / / - - - DOUBLE_MEASURE case: attach a % to an appropriate barline. + a slash sign. */ class Slash_repeat_engraver : public Engraver { public: TRANSLATOR_DECLARATIONS (Slash_repeat_engraver); protected: - Music *repeat_; - - /// moment (global time) where beam started. - Moment start_mom_; - Moment stop_mom_; - - /// location within measure where beam started. - Moment beam_start_location_; - Moment next_moment_; - Moment body_length_; - - Item *beat_slash_; - Item *double_percent_; + Stream_event *slash_; protected: - virtual bool try_music (Music *); - PRECOMPUTED_VIRTUAL void start_translation_timestep (); - PRECOMPUTED_VIRTUAL void process_music (); + DECLARE_TRANSLATOR_LISTENER (percent); + void process_music (); }; Slash_repeat_engraver::Slash_repeat_engraver () { - repeat_ = 0; - beat_slash_ = 0; + slash_ = 0; } -bool -Slash_repeat_engraver::try_music (Music *m) +IMPLEMENT_TRANSLATOR_LISTENER (Slash_repeat_engraver, percent); +void +Slash_repeat_engraver::listen_percent (Stream_event *ev) { - if (m->is_mus_type ("repeated-music") - && !repeat_ - && m->get_property ("iterator-ctor") - == Percent_repeat_iterator::constructor_proc) - { - body_length_ = Repeated_music::body_get_length (m); - int count = Repeated_music::repeat_count (m); - - Moment now = now_mom (); - start_mom_ = now; - stop_mom_ = start_mom_ + Moment (count) * body_length_; - next_moment_ = start_mom_ + body_length_; - - Moment meas_length - = robust_scm2moment (get_property ("measureLength"), Moment (0)); - if (body_length_ < meas_length) - { - repeat_ = m; - } - else - return false; - - Global_context *global = get_global_context (); - for (int i = 0; i < count; i++) - global->add_moment_to_process (next_moment_ + Moment (i) * body_length_); - - return true; - } - - return false; + /*todo: separate events for percent and slash */ + Moment meas_length + = robust_scm2moment (get_property ("measureLength"), Moment (0)); + + if (get_event_length (ev) < meas_length) + ASSIGN_EVENT_ONCE (slash_, ev); + + /* + don't warn if nothing happens: this can happen if there are whole + measure repeats. + */ } void Slash_repeat_engraver::process_music () { - if (repeat_ && now_mom () == next_moment_) + if (slash_) { - beat_slash_ = make_item ("RepeatSlash", repeat_->self_scm ()); - next_moment_ = next_moment_ + body_length_; - - get_global_context ()->add_moment_to_process (next_moment_); + make_item ("RepeatSlash", slash_->self_scm ()); + slash_ = 0; } } -void -Slash_repeat_engraver::start_translation_timestep () -{ - if (stop_mom_ == now_mom ()) - { - repeat_ = 0; - } - beat_slash_ = 0; -} +ADD_TRANSLATOR (Slash_repeat_engraver, + /* doc */ + "Make beat repeats.", + /* create */ + "RepeatSlash ", -#include "translator.icc" + /* read */ + "measureLength ", -ADD_TRANSLATOR (Slash_repeat_engraver, - /* descr */ "Make beat repeats.", - /* creats*/ "RepeatSlash", - /* accepts */ "repeated-music", - /* reads */ "measureLength", - /* write */ ""); + /* write */ + "" + );