[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make \time work with \tweak and \footnote (issue 149170044 by addres

From: dak
Subject: Re: Make \time work with \tweak and \footnote (issue 149170044 by address@hidden)
Date: Tue, 30 Sep 2014 04:54:22 +0000

Reviewers: Dan Eble,

On 2014/09/30 03:50:30, Dan Eble wrote:
\compoundMeter should create a TimeSignatureEvent too.

[Slaps forehead]

I managed to do it by
incorporating \time into the definition of \compoundMeter, but perhaps
you have
a better idea.

I'll take a look.

Make \time work with \tweak and \footnote

The way this is done is to let a TimeSignatureMusic expression expand to
produce a TimeSignatureEvent that can be listened to.  The
Time_signature_engraver _does_ listen to this event and uses it to set
the origin for TimeSignature grobs created in the same time step.
Another effect is that any warnings associated with a TimeSignature grob
will be able to point to a source location in case that the respective
change of timing parameters can be traced to TimeSignatureMusic in a
context below the context of the Time_signature_engraver creating the

Since events that can be listened to create a Bottom context implicitly,
this causes a difference for cases like

\score { { \time 3/4 \skip 2. r2. } }

Previously, Staff (and Voice) contexts were only created _after_ the
\skip completed (the timing parameters are set in the Timing context,
equal to Score by default), making the time signature appear only in
measure 2.  Now the implicit creation of a Staff (and thus a
Time_signature_engraver) in the course of creating a Bottom context (in
this case a Voice) makes the time signature appear right away.

If one uses a separate non-printing context for containing timing info,
one has to make sure that any implicitly created Bottom context is
non-printing as well.

Please review this at

Affected files (+24, -5 lines):
  M lily/
  M scm/define-event-classes.scm
  M scm/define-music-callbacks.scm
  M scm/define-music-types.scm

Index: lily/
diff --git a/lily/ b/lily/ index 8461a01058251f67425e2cb1bd16e335a02bc053..8c444e57471d86cd13ecfc1ed5d7d1063b789e3e 100644
--- a/lily/
+++ b/lily/
@@ -22,9 +22,12 @@
 #include "item.hh"
 #include "international.hh"
 #include "misc.hh"
+#include "stream-event.hh"
 #include "time-signature.hh"
 #include "warn.hh"

+#include "translator.icc"
    generate time_signatures.
@@ -32,6 +35,7 @@ class Time_signature_engraver : public Engraver
   Item *time_signature_;
   SCM last_time_fraction_;
+  SCM time_cause_;

   virtual void derived_mark () const;
@@ -39,26 +43,33 @@ protected:
   void process_music ();
   TRANSLATOR_DECLARATIONS (Time_signature_engraver);

 Time_signature_engraver::derived_mark () const
   scm_gc_mark (last_time_fraction_);
+  scm_gc_mark (time_cause_);

 Time_signature_engraver::Time_signature_engraver ()
   time_signature_ = 0;
+  time_cause_ = SCM_EOL;
   last_time_fraction_ = SCM_BOOL_F;

+IMPLEMENT_TRANSLATOR_LISTENER (Time_signature_engraver, time_signature);
+Time_signature_engraver::listen_time_signature (Stream_event *ev)
+  time_cause_ = ev->self_scm ();
 Time_signature_engraver::process_music ()
-  /*
-    not rigorously safe, since the value might get GC'd and
-    reallocated in the same spot */
   SCM fr = get_property ("timeSignatureFraction");
   if (!time_signature_
       && last_time_fraction_ != fr
@@ -77,7 +88,7 @@ Time_signature_engraver::process_music ()

-      time_signature_ = make_item ("TimeSignature", SCM_EOL);
+      time_signature_ = make_item ("TimeSignature", time_cause_);
       time_signature_->set_property ("fraction", fr);

       if (last_time_fraction_ == SCM_BOOL_F)
@@ -92,6 +103,7 @@ void
 Time_signature_engraver::stop_translation_timestep ()
   time_signature_ = 0;
+  time_cause_ = SCM_EOL;

 #include "translator.icc"
Index: scm/define-event-classes.scm
diff --git a/scm/define-event-classes.scm b/scm/define-event-classes.scm
index ac6f215ae2280c16a7b92a4be90ff0fc42a37c39..b56894508122c37b573711818b614194a6af85cd 100644
--- a/scm/define-event-classes.scm
+++ b/scm/define-event-classes.scm
@@ -38,6 +38,7 @@
laissez-vibrer-event mark-event multi-measure-text-event
                     note-grouping-event pes-or-flexa-event repeat-tie-event
                     spacing-section-event layout-instruction-event
+                    time-signature-event
completize-extender-event break-span-event alternative-event))

     (layout-instruction-event . (apply-output-event))
Index: scm/define-music-callbacks.scm
diff --git a/scm/define-music-callbacks.scm b/scm/define-music-callbacks.scm
index e9fe53eb1b0a253e85d1af3b1d05d20ce767fae0..a6441d1e21798e58296d17fcbff0d376a0bb0ac9 100644
--- a/scm/define-music-callbacks.scm
+++ b/scm/define-music-callbacks.scm
@@ -126,4 +126,5 @@ to be used by the sequential-iterator"
                   context 'measureLength new-measure-length))))
-           'Score))))
+           'Score)
+          (make-music 'TimeSignatureEvent music))))
Index: scm/define-music-types.scm
diff --git a/scm/define-music-types.scm b/scm/define-music-types.scm
index 8d0464bf4c9009f2c86955ea5f9a7d4520ca3582..359e10eac1f6a4e382f9044aa5d77c88c9988738 100644
--- a/scm/define-music-types.scm
+++ b/scm/define-music-types.scm
@@ -666,6 +666,11 @@ Syntax: @code{\\times @var{fraction} @var{music}}, e.g.,
         (types . (general-music time-signature-music))

+    (TimeSignatureEvent
+ . ((description . "An event created when setting a new time signature")
+        (types . (general-music event time-signature-event))
+        ))
      . ((description . "Music that has been transposed.")
         (iterator-ctor . ,ly:music-wrapper-iterator::constructor)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]