]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/part-combine-engraver.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / part-combine-engraver.cc
index daaf17b7c594adf90d26522ef9bc93969be1e317..3fe404ce3510000b24881f63f9579c435b158e5c 100644 (file)
 /*
-  part-combine-engraver.cc -- implement PC-engraver
+  This file is part of LilyPond, the GNU music typesetter.
 
-  source file of the GNU LilyPond music typesetter
-  
-  (c) 2000--2004 Jan Nieuwenhuizen <janneke@gnu.org>
+  Copyright (C) 2000--2014 Jan Nieuwenhuizen <janneke@gnu.org>
 
   Han-Wen Nienhuys <hanwen@xs4all.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.
+
+  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 "engraver.hh"
-#include "item.hh"
-#include "text-item.hh"
 #include "note-head.hh"
-#include "stem.hh"
 #include "side-position-interface.hh"
-#include "multi-measure-rest.hh"
+#include "stem.hh"
+#include "stream-event.hh"
+#include "text-interface.hh"
+#include "item.hh"
+
+#include "translator.icc"
 
 class Part_combine_engraver : public Engraver
 {
   TRANSLATOR_DECLARATIONS (Part_combine_engraver);
 
 protected:
-  virtual void acknowledge_grob (Grob_info);
-  virtual void process_music ();
-  virtual void stop_translation_timestep ();
-  virtual bool try_music (Music *);
+  DECLARE_ACKNOWLEDGER (note_head);
+  DECLARE_ACKNOWLEDGER (stem);
+
+  DECLARE_TRANSLATOR_LISTENER (part_combine);
+  DECLARE_TRANSLATOR_LISTENER (note);
+  void process_music ();
+  void stop_translation_timestep ();
+  void create_item (Stream_event *ev);
+
 private:
   Item *text_;
-  Music *event_;
+  Stream_event *new_event_; // Event happened at this moment
+  bool note_found_;
+  // Event possibly from an earlier moment waiting to create a text:
+  Stream_event *waiting_event_;
 };
 
-bool
-Part_combine_engraver::try_music (Music*m)
+IMPLEMENT_TRANSLATOR_LISTENER (Part_combine_engraver, part_combine);
+void
+Part_combine_engraver::listen_part_combine (Stream_event *ev)
 {
-  event_ = m;
-  return true;
+  ASSIGN_EVENT_ONCE (new_event_, ev);
+  // If two events occur at the same moment, discard the second as the
+  // warning indicates:
+  waiting_event_ = new_event_;
+}
+
+IMPLEMENT_TRANSLATOR_LISTENER (Part_combine_engraver, note);
+void
+Part_combine_engraver::listen_note (Stream_event *)
+{
+  note_found_ = true;
 }
 
 Part_combine_engraver::Part_combine_engraver ()
 {
   text_ = 0;
-  event_  =0;
+  new_event_ = 0;
+  waiting_event_ = 0;
+  note_found_ = false;
 }
 
 void
-Part_combine_engraver::process_music ()
+Part_combine_engraver::create_item (Stream_event *ev)
 {
-  if (event_
-      && to_boolean (get_property ("soloADue")))
+  SCM what = scm_car (ev->get_property ("class"));
+  SCM text = SCM_EOL;
+  if (what == ly_symbol2scm ("solo-one-event"))
+    text = get_property ("soloText");
+  else if (what == ly_symbol2scm ("solo-two-event"))
+    text = get_property ("soloIIText");
+  else if (what == ly_symbol2scm ("unisono-event"))
+    text = get_property ("aDueText");
+
+  if (Text_interface::is_markup (text))
     {
-      SCM what = event_->get_property ("part-combine-status");
-      SCM text = SCM_EOL;
-      if (what == ly_symbol2scm ("solo1"))
-       text = get_property ("soloText");
-      else if (what== ly_symbol2scm ("solo2"))
-       text = get_property ("soloIIText");
-      else if (what == ly_symbol2scm ("unisono"))
-       text = get_property ("aDueText");
-
-      if (Text_item::markup_p (text))
-       {
-         text_ =  make_item ("CombineTextScript", event_->self_scm () );
-         text_->set_property ("text", text);
-       }
+      text_ = make_item ("CombineTextScript", ev->self_scm ());
+      text_->set_property ("text", text);
     }
 }
 
 void
-Part_combine_engraver::acknowledge_grob (Grob_info i)
+Part_combine_engraver::process_music ()
 {
-  if (text_)
+  if (waiting_event_
+      && to_boolean (get_property ("printPartCombineTexts")))
     {
-      if (Note_head::has_interface (i.grob_))
-       {
-         Grob*t = text_;
-         Side_position_interface::add_support (t, i.grob_);
-         if (Side_position_interface::get_axis (t) == X_AXIS
-             && !t->get_parent (Y_AXIS))
-           t->set_parent (i.grob_, Y_AXIS);
-       }
-      if (Stem::has_interface (i.grob_))
-       {
-         Side_position_interface::add_support (text_, i.grob_);
-       }
+      if (note_found_ || !to_boolean (get_property ("partCombineTextsOnNote")))
+        {
+          create_item (waiting_event_);
+          waiting_event_ = 0;
+        }
     }
 }
 
-void 
-Part_combine_engraver::stop_translation_timestep ()
+void
+Part_combine_engraver::acknowledge_note_head (Grob_info i)
 {
   if (text_)
     {
-      typeset_grob (text_);
-      text_ = 0;
+      Grob *t = text_;
+      Side_position_interface::add_support (t, i.grob ());
+      if (Side_position_interface::get_axis (t) == X_AXIS
+          && !t->get_parent (Y_AXIS))
+        t->set_parent (i.grob (), Y_AXIS);
     }
-  event_ = 0;
 }
 
-ENTER_DESCRIPTION (Part_combine_engraver,
-/* descr */       "Part combine engraver for orchestral scores:                "
-                 "Print markings a2, Solo, Solo II, and unisono ",
-/* creats*/       "CombineTextScript",
-/* accepts */     "part-combine-event",
-/* acks  */       "multi-measure-rest-interface "
-"slur-interface stem-interface note-head-interface"
-,/* reads */       "soloADue",
-/* write */       "");
+void
+Part_combine_engraver::acknowledge_stem (Grob_info i)
+{
+  if (text_)
+    Side_position_interface::add_support (text_, i.grob ());
+}
+
+void
+Part_combine_engraver::stop_translation_timestep ()
+{
+  text_ = 0;
+  new_event_ = 0;
+  note_found_ = false;
+}
+
+ADD_ACKNOWLEDGER (Part_combine_engraver, note_head);
+ADD_ACKNOWLEDGER (Part_combine_engraver, stem);
+ADD_TRANSLATOR (Part_combine_engraver,
+                /* doc */
+                "Part combine engraver for orchestral scores: Print markings"
+                " @q{a2}, @q{Solo}, @q{Solo II}, and @q{unisono}.",
+
+                /* create */
+                "CombineTextScript ",
+
+                /* read */
+                "printPartCombineTexts "
+                "partCombineTextsOnNote "
+                "soloText "
+                "soloIIText "
+                "aDueText ",
+
+                /* write */
+                ""
+               );