]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/laissez-vibrer-engraver.cc
Doc-es: various updates.
[lilypond.git] / lily / laissez-vibrer-engraver.cc
index 7a9a4dee72f2b99332021b4da9397c102ebe4fcf..2d2e2dd2e87ee0e06ae9aaa93e4072e4396d4e3f 100644 (file)
@@ -1,12 +1,22 @@
 /*
-  laissez-vibrer-engraver.cc -- implement Laissez_vibrer_engraver
+  This file is part of LilyPond, the GNU music typesetter.
 
-  source file of the GNU LilyPond music typesetter
+  Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
-  (c) 2005--2007 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"
@@ -19,17 +29,18 @@ class Laissez_vibrer_engraver : public Engraver
 {
   Stream_event *event_;
   Grob *lv_column_;
-  vector<Grob*> lv_ties_;
-  
-  void stop_translation_timestep (); 
-  DECLARE_ACKNOWLEDGER (note_head);
+  vector<Grob *> lv_ties_;
+
+  void stop_translation_timestep ();
+  void acknowledge_note_head (Grob_info);
 protected:
-  DECLARE_TRANSLATOR_LISTENER (laissez_vibrer);
+  void listen_laissez_vibrer (Stream_event *);
 public:
   TRANSLATOR_DECLARATIONS (Laissez_vibrer_engraver);
 };
 
-Laissez_vibrer_engraver::Laissez_vibrer_engraver ()
+Laissez_vibrer_engraver::Laissez_vibrer_engraver (Context *c)
+  : Engraver (c)
 {
   event_ = 0;
   lv_column_ = 0;
@@ -43,7 +54,6 @@ Laissez_vibrer_engraver::stop_translation_timestep ()
   lv_ties_.clear ();
 }
 
-IMPLEMENT_TRANSLATOR_LISTENER (Laissez_vibrer_engraver, laissez_vibrer);
 void
 Laissez_vibrer_engraver::listen_laissez_vibrer (Stream_event *ev)
 {
@@ -53,30 +63,65 @@ Laissez_vibrer_engraver::listen_laissez_vibrer (Stream_event *ev)
 void
 Laissez_vibrer_engraver::acknowledge_note_head (Grob_info inf)
 {
-  if (!event_)
+  /* use the heard event_ for all note heads, or an individual event for just
+   * a single note head (attached as an articulation inside a chord) */
+  Stream_event *tie_ev = event_;
+  Grob *head = inf.grob ();
+  Stream_event *note_ev = unsmob<Stream_event> (head->get_property ("cause"));
+  if (!tie_ev && note_ev && note_ev->in_event_class ("note-event"))
+    {
+      SCM articulations = note_ev->get_property ("articulations");
+      for (SCM s = articulations; !tie_ev && scm_is_pair (s); s = scm_cdr (s))
+        {
+          Stream_event *ev = unsmob<Stream_event> (scm_car (s));
+          if (ev && ev->in_event_class ("laissez-vibrer-event"))
+            tie_ev = ev;
+        }
+    }
+
+  if (!tie_ev)
     return;
 
+  SCM cause = tie_ev->self_scm ();
+
   if (!lv_column_)
+    lv_column_ = make_item ("LaissezVibrerTieColumn", cause);
+
+  Grob *lv_tie = make_item ("LaissezVibrerTie", cause);
+  lv_tie->set_object ("note-head", head->self_scm ());
+
+  Pointer_group_interface::add_grob (lv_column_, ly_symbol2scm ("ties"),
+                                     lv_tie);
+
+  if (is_direction (unsmob<Stream_event> (cause)->get_property ("direction")))
     {
-      lv_column_ = make_item ("LaissezVibrerTieColumn", event_->self_scm ());
+      Direction d = to_dir (unsmob<Stream_event> (cause)->get_property ("direction"));
+      lv_tie->set_property ("direction", scm_from_int (d));
     }
-  
-  Grob *lv_tie = make_item ("LaissezVibrerTie", event_->self_scm ());
-  lv_tie->set_object ("note-head", inf.grob ()->self_scm ());
-  
-  Pointer_group_interface::add_grob (lv_column_, ly_symbol2scm ("ties"),
-                                    lv_tie);
+
   lv_tie->set_parent (lv_column_, Y_AXIS);
 
   lv_ties_.push_back (lv_tie);
 }
 
-ADD_ACKNOWLEDGER (Laissez_vibrer_engraver, note_head);
-ADD_TRANSLATOR (Laissez_vibrer_engraver, 
-               /* doc */ "Create Laissez vibrer items.",
-               
-               /* create */
-               "LaissezVibrerTie "
-               "LaissezVibrerTieColumn ",
-               /* read */ "",
-               /* write */ "");
+void
+Laissez_vibrer_engraver::boot ()
+{
+  ADD_LISTENER (Laissez_vibrer_engraver, laissez_vibrer);
+  ADD_ACKNOWLEDGER (Laissez_vibrer_engraver, note_head);
+}
+
+ADD_TRANSLATOR (Laissez_vibrer_engraver,
+                /* doc */
+                "Create laissez vibrer items.",
+
+                /* create */
+                "LaissezVibrerTie "
+                "LaissezVibrerTieColumn ",
+
+                /* read */
+                "",
+
+                /* write */
+                ""
+               );