]> git.donarmstrong.com Git - lilypond.git/commitdiff
Fix #818.
authorNeil Puttock <n.puttock@gmail.com>
Mon, 20 Sep 2010 22:13:02 +0000 (23:13 +0100)
committerNeil Puttock <n.puttock@gmail.com>
Mon, 20 Sep 2010 22:13:02 +0000 (23:13 +0100)
Use unsmob_engraver ()/unsmob_performer () instead of
explicit casting in translator-group.cc when filtering
translators added via \with { }

* lily/include/performer.hh, lily/performer.hh

  add unsmob_performer ()

* lily/translator-group.cc (filter_engravers/filter_performers):

  use unsmob_* () instead of dynamic_cast when checking
  translator is of correct class to remove

input/regression/filter-translators.ly [new file with mode: 0644]
lily/include/performer.hh
lily/performer.cc
lily/translator-group.cc

diff --git a/input/regression/filter-translators.ly b/input/regression/filter-translators.ly
new file mode 100644 (file)
index 0000000..1c10a22
--- /dev/null
@@ -0,0 +1,21 @@
+\version "2.13.34"
+
+\header {
+  texidoc = "Context modification via @code{\\with} filters translators
+of the wrong type: performers for an @code{Engraver_group} and engravers
+for a @code{Performer_group}.  In this test, the
+@code{Instrument_name_engraver} is added to a @code{StaffGroup}, but
+does not affect midi output, since it is filtered out."
+}
+
+\score {
+  \new StaffGroup \with {
+    \consists "Instrument_name_engraver"
+    instrumentName = #"StaffGroup"
+  }
+  {
+    a'1
+  }
+  \layout { }
+  \midi { }
+}
index 11a5c32c8a59bdf4976d231afcbac05b49cc288e..0b0497e322b2fdacf9ab32fe09fde3bc7842f98a 100644 (file)
@@ -40,5 +40,7 @@ protected:
   virtual void create_audio_elements ();
 };
 
+Performer *unsmob_performer (SCM perf);
+
 #endif /* PERFORMER_HH */
 
index c177f9e975e2760df30700a2470095ccc00c8313..60a0519d42b31336abaa8b1bff32022a46305581 100644 (file)
@@ -19,6 +19,7 @@
 */
 
 #include "context.hh"
+#include "performer.hh"
 #include "performer-group.hh"
 #include "warn.hh"
 
@@ -48,3 +49,9 @@ Performer::announce_element (Audio_element_info i)
 
   get_daddy_performer ()->announce_element (i);
 }
+
+Performer *
+unsmob_performer (SCM perf)
+{
+  return dynamic_cast<Performer *> (unsmob_translator (perf));
+}
index 84a97bf52e206bdf980ab6bae228fabac470cbab..f9812e9798f272a9c96caa85905bf69b08b38387 100644 (file)
 #include "context-def.hh"
 #include "context.hh"
 #include "dispatcher.hh"
+#include "engraver.hh"
 #include "engraver-group.hh"
 #include "international.hh"
 #include "main.hh"
 #include "music.hh"
 #include "output-def.hh"
+#include "performer.hh"
 #include "performer-group.hh"
 #include "scheme-engraver.hh"
 #include "scm-hash.hh"
@@ -52,7 +54,7 @@ Translator_group::connect_to_context (Context *c)
   if (context_)
     {
       programming_error ("translator group is already connected to context "
-                        +  context_->context_name ());
+                        + context_->context_name ());
     }
   
   context_ = c;
@@ -84,13 +86,22 @@ Translator_group::finalize ()
 {
 }
 
+/*
+  Both filter_performers and filter_engravers used to use a direct dynamic_cast
+  on the unsmobbed translator to be filtered, i.e.,
+
+  if (dynamic_cast<Performer *> (unsmob_translator (scm_car (*tail))))
+
+  but this caused mysterious optimisation issues in several GUB builds.  See
+  issue #818 for the background to this change.
+*/
 SCM
 filter_performers (SCM ell)
 {
   SCM *tail = &ell;
   for (SCM p = ell; scm_is_pair (p); p = scm_cdr (p))
     {
-      if (dynamic_cast<Performer *> (unsmob_translator (scm_car (*tail))))
+      if (unsmob_performer (scm_car (*tail)))
        *tail = scm_cdr (*tail);
       else
        tail = SCM_CDRLOC (*tail);
@@ -104,7 +115,7 @@ filter_engravers (SCM ell)
   SCM *tail = &ell;
   for (SCM p = ell; scm_is_pair (p); p = scm_cdr (p))
     {
-      if (dynamic_cast<Engraver *> (unsmob_translator (scm_car (*tail))))
+      if (unsmob_engraver (scm_car (*tail)))
        *tail = scm_cdr (*tail);
       else
        tail = SCM_CDRLOC (*tail);