]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/drum-note-engraver.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / drum-note-engraver.cc
index 54cc4845398a108eea5ce230e2640695a803b632..591fc9d1b6468445c3fa36d9f5ac8cf31c4cdb5d 100644 (file)
 /*
-  drum-note-engraver.cc
-  
-  (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  This file is part of LilyPond, the GNU music typesetter.
+
+  Copyright (C) 1997--2014 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 <ctype.h>
 
-#include "rhythmic-head.hh"
-#include "event.hh"
+#include <cctype>
+using namespace std;
+
 #include "item.hh"
+#include "duration.hh"
 #include "engraver.hh"
-#include "warn.hh"
+#include "note-column.hh"
+#include "rhythmic-head.hh"
 #include "side-position-interface.hh"
-#include "script.hh"
+#include "script-interface.hh"
 #include "stem.hh"
-#include "note-column.hh"
+#include "stream-event.hh"
+#include "warn.hh"
+
+#include "translator.icc"
 
 class Drum_notes_engraver : public Engraver
 {
-  Link_array<Item> notes_;
-  Link_array<Item> dots_;
-  Link_array<Item> scripts_;
-  Link_array<Music> events_;
+  vector<Item *> scripts_;
+  vector<Stream_event *> events_;
 
 public:
-  TRANSLATOR_DECLARATIONS(Drum_notes_engraver);
+  TRANSLATOR_DECLARATIONS (Drum_notes_engraver);
 
 protected:
-  virtual bool try_music (Music *ev) ;
-  virtual void process_music ();
-  virtual void acknowledge_grob (Grob_info); 
-  virtual void stop_translation_timestep ();
+  void process_music ();
+  DECLARE_ACKNOWLEDGER (stem);
+  DECLARE_ACKNOWLEDGER (note_column);
+  DECLARE_TRANSLATOR_LISTENER (note);
+  void stop_translation_timestep ();
 };
 
-Drum_notes_engraver::Drum_notes_engraver()
+Drum_notes_engraver::Drum_notes_engraver ()
 {
 }
 
-bool
-Drum_notes_engraver::try_music (Music *m) 
+IMPLEMENT_TRANSLATOR_LISTENER (Drum_notes_engraver, note);
+void
+Drum_notes_engraver::listen_note (Stream_event *ev)
 {
-  if (m->is_mus_type ("note-event"))
-    {
-      events_.push (m);
-      return true;
-    }
-  else if (m->is_mus_type ("busy-playing-event"))
-    return events_.size ();
-  else if (m->is_mus_type ("start-playing-event"))
-    return events_.size ();
-  
-  return false;
+  events_.push_back (ev);
 }
 
-
 void
 Drum_notes_engraver::process_music ()
 {
   SCM tab = 0;
-  for (int i=0; i < events_.size (); i++)
+  for (vsize i = 0; i < events_.size (); i++)
     {
       if (!tab)
-       tab = get_property ("drumStyleTable");
-      
-      Item *note = make_item ("NoteHead");
-      Music * ev = events_[i];
-      
-      Duration dur = *unsmob_duration (ev->get_mus_property ("duration"));
-
-      note->set_grob_property ("duration-log", gh_int2scm (dur.duration_log ()));
-
-      if (dur.dot_count ())
-       {
-         Item * d = make_item ("Dots");
-         Rhythmic_head::set_dots (note, d);
-         
-         if (dur.dot_count ()
-             != robust_scm2int (d->get_grob_property ("dot-count"), 0))
-           d->set_grob_property ("dot-count", gh_int2scm (dur.dot_count ()));
-
-         d->set_parent (note, Y_AXIS);
-         announce_grob (d, SCM_EOL);
-         dots_.push (d);
-       }
-
-      SCM drum_type =  ev->get_mus_property ("drum-type");
+        tab = get_property ("drumStyleTable");
+
+      Stream_event *ev = events_[i];
+      Item *note = make_item ("NoteHead", ev->self_scm ());
+
+      SCM drum_type = ev->get_property ("drum-type");
 
       SCM defn = SCM_EOL;
 
       if (scm_hash_table_p (tab) == SCM_BOOL_T)
-       defn = scm_hashq_ref (tab, drum_type, SCM_EOL);
-      
-      if (gh_pair_p (defn))
-       {
-         SCM pos = gh_caddr (defn);
-         SCM style =gh_car (defn);
-         SCM script = gh_cadr (defn);
-         
-         if (scm_integer_p (pos) == SCM_BOOL_T)
-           note->set_grob_property ("staff-position", pos);
-         if (gh_symbol_p (style))
-           note->set_grob_property ("style", style);
-
-         if (gh_string_p (script))
-           {
-             Item *p  = make_item ("Script");
-             SCM desc  = SCM_EOL;
-             make_script_from_event (p, &desc,
-                                     daddy_trans_, script,
-                                     0);
-
-             if (p->get_grob_property ("follow-into-staff"))
-               p->set_grob_property ("staff-padding", SCM_EOL);
-             
-             announce_grob (p, ev->self_scm ());
-
-             p->set_parent (note, Y_AXIS);
-             Side_position_interface::add_support (p, note); 
-             scripts_.push (p);
-           }
-       }
-
-
-      
-      announce_grob (note,ev->self_scm());
-      notes_.push (note);
+        defn = scm_hashq_ref (tab, drum_type, SCM_EOL);
+
+      if (scm_is_pair (defn))
+        {
+          SCM pos = scm_caddr (defn);
+          SCM style = scm_car (defn);
+          SCM script = scm_cadr (defn);
+
+          if (scm_integer_p (pos) == SCM_BOOL_T)
+            note->set_property ("staff-position", pos);
+          if (scm_is_symbol (style))
+            note->set_property ("style", style);
+
+          if (scm_is_string (script))
+            {
+              Item *p = make_item ("Script", ev->self_scm ());
+              make_script_from_event (p, context (), script,
+                                      0);
+
+              p->set_parent (note, Y_AXIS);
+              Side_position_interface::add_support (p, note);
+              scripts_.push_back (p);
+            }
+        }
     }
 }
 
 void
-Drum_notes_engraver::acknowledge_grob (Grob_info inf)
+Drum_notes_engraver::acknowledge_stem (Grob_info inf)
 {
-  if (Stem::has_interface (inf.grob_))
+  for (vsize i = 0; i < scripts_.size (); i++)
     {
-      for (int i=0; i < scripts_.size (); i++)
-       {
-         Grob*e = scripts_[i];
-
-         if (to_dir (e->get_grob_property ("side-relative-direction")))
-           e->set_grob_property ("direction-source", inf.grob_->self_scm ());
-
-         /*
-           add dep ? 
-          */
-         e->add_dependency (inf.grob_);
-         Side_position_interface::add_support (e, inf.grob_);
-       }
+      Grob *e = scripts_[i];
+
+      if (to_dir (e->get_property ("side-relative-direction")))
+        e->set_object ("direction-source", inf.grob ()->self_scm ());
+
+      Side_position_interface::add_support (e, inf.grob ());
     }
-   else if (Note_column::has_interface (inf.grob_))
+}
+
+void
+Drum_notes_engraver::acknowledge_note_column (Grob_info inf)
+{
+  for (vsize i = 0; i < scripts_.size (); i++)
     {
-      for (int i=0; i < scripts_.size (); i++)
-       {
-         Grob *e = scripts_[i];
-         
-         if (!e->get_parent (X_AXIS) &&
-             Side_position_interface::get_axis (e) == Y_AXIS)
-           {
-             e->set_parent (inf.grob_, X_AXIS);
-           }
-       }
-    }
+      Grob *e = scripts_[i];
 
-}
+      if (!e->get_parent (X_AXIS)
+          && Side_position_interface::get_axis (e) == Y_AXIS)
+        e->set_parent (inf.grob (), X_AXIS);
 
+      Side_position_interface::add_support (e, inf.grob ());
+    }
+}
 
 void
 Drum_notes_engraver::stop_translation_timestep ()
 {
-  for (int i=0; i < notes_.size (); i++)
-    {
-      typeset_grob (notes_[i]);
-    }
-  notes_.clear ();
-  for (int i=0; i < dots_.size (); i++)
-    {
-      typeset_grob (dots_[i]);
-    }
-  dots_.clear ();
-  for (int i=0; i < scripts_.size (); i++)
-    {
-      typeset_grob (scripts_[i]);
-    }
   scripts_.clear ();
-  
   events_.clear ();
 }
 
+ADD_ACKNOWLEDGER (Drum_notes_engraver, stem);
+ADD_ACKNOWLEDGER (Drum_notes_engraver, note_column);
+
+ADD_TRANSLATOR (Drum_notes_engraver,
+                /* doc */
+                "Generate drum note heads.",
 
+                /* create */
+                "NoteHead "
+                "Script ",
 
-ENTER_DESCRIPTION(Drum_notes_engraver,
-/* descr */       "Generate noteheads.",
-/* creats*/       "NoteHead Dots Script",
-/* accepts */     "note-event busy-playing-event",
-/* acks  */       "stem-interface note-column-interface",
-/* reads */       "drumStyleTable",
-/* write */       "");
+                /* read */
+                "drumStyleTable ",
 
+                /* write */
+                ""
+               );