]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/slash-repeat-engraver.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / slash-repeat-engraver.cc
index 92115d3904018dd4f1c135080ba117fc363bfa73..a6b3faa56c42c76e3a9ad0d24b5fe66ddaa95f81 100644 (file)
 /*
-  slash-repeat-engraver.cc -- implement Slash_repeat_engraver
+  This file is part of LilyPond, the GNU music typesetter.
 
-  source file of the GNU LilyPond music typesetter
+  Copyright (C) 2000--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>, Erik Sandberg
+  <mandolaerik@gmail.com>
 
-  (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-*/
+  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.
 
-#include "repeated-music.hh"
-#include "global-context.hh"
-#include "warn.hh"
-#include "misc.hh"
-#include "spanner.hh"
-#include "item.hh"
-#include "percent-repeat-iterator.hh"
-#include "bar-line.hh"
-#include "score-engraver.hh"
+  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.
 
-/**
-   This acknowledges repeated music with "percent" style.  It typesets
-   a % sign.
+  You should have received a copy of the GNU General Public License
+  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
+*/
 
-   TODO:
+#include "item.hh"
+#include "engraver.hh"
+#include "stream-event.hh"
 
-   - BEAT case: Create items for single beat repeats, i.e. c4 / / /
+#include "translator.icc"
 
-   - DOUBLE_MEASURE case: attach a % to an appropriate barline.
+/*
+  This acknowledges repeated music with "percent" style.  It typesets
+  a slash sign or double percent 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 *);
-  void start_translation_timestep ();
+  DECLARE_TRANSLATOR_LISTENER (repeat_slash);
   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, repeat_slash);
+void
+Slash_repeat_engraver::listen_repeat_slash (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;
+  ASSIGN_EVENT_ONCE (slash_, ev);
 }
 
 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_);
+      SCM count = slash_->get_property ("slash-count");
+      if (scm_to_int (count) == 0)
+        make_item ("DoubleRepeatSlash", slash_->self_scm ());
+      else
+        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.",
 
-#include "translator.icc"
+                /* create */
+                "DoubleRepeatSlash "
+                "RepeatSlash ",
 
-ADD_TRANSLATOR (Slash_repeat_engraver,
-               /* doc */ "Make beat repeats.",
-               /* create */ "RepeatSlash",
-               /* accept */ "repeated-music",
-               /* read */ "measureLength",
-               /* write */ "");
+                /* read */
+                "",
+
+                /* write */
+                ""
+               );