lilypond-devel
[Top][All Lists]
Advanced

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

Re: Issue 2717: Implement \single, \omit and \hide (issue 6495135)


From: dak
Subject: Re: Issue 2717: Implement \single, \omit and \hide (issue 6495135)
Date: Mon, 24 Sep 2012 08:44:31 +0000

Reviewers: Keith,

Message:
On 2012/09/24 06:34:00, Keith wrote:
Works well for me.

You mis-typed something in the description because

> so you can use things like \single\voiceOne c4 .

is not true.

But it is _intended_ to be true.  It is just that LilyPond is an
inconsistent heap of garbage that does not bother generating the same
kind of data for Scheme generated overrides as it does for manually
generated overrides.

And then the iterator takes a look and tries figuring out what kind of
data structure was actually used.  \single failed to do the same.

New patch up, but this will likely afflict other override-reinterpreting
commands as well.

Thanks for checking up on my over-optimistic statements.

Description:
Issue 2717: Implement \single, \omit and \hide

\omit StringNumber would be equivalent to
\override StringNumber #'stencil = ##f,

\hide StringNumber would be equivalent to
\override StringNumber #'transparent = ##t

and something like \single\omit StringNumber \3 would be equivalent to
\tweak StringNumber #'stencil ##f \3

\single can, like \once, translate larger override sets like \voiceOne
into a tweak, so you can use things like \single\voiceOne c4 .

The disadvantage of this particular approach is that with
\single\omit StringNumber \3 you still need to be specific about the
grob you want to see erased, even though \3 would sufficiently provide
that information.  It would be conceivable to allow
\single\omit \default \3
for that, by letting \erase \default create something that does not
actually work in music but is understood by \single, but that does not
seem all too satisfactory either.

The advantage is that this makes most overrides in ly/property-init.ly
available as tweaks.


Please review this at http://codereview.appspot.com/6495135/

Affected files:
  M ly/music-functions-init.ly


Index: ly/music-functions-init.ly
diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly
index e1dcd992e00bf66c60fa7e09e012632732fc7db6..a8dace2e229ab74e5f1264c54b81a5eb64857611 100644
--- a/ly/music-functions-init.ly
+++ b/ly/music-functions-init.ly
@@ -475,6 +475,12 @@ given through @var{ratio}.")
     \revert NoteHead #'stencil
   #})

+hide =
+#(define-music-function (parser location grob) (string?)
+   (_i "Set @var{grob}'s @samp{transparent} property to @code{#t},
+making it invisible while still retaining its dimensions.")
+   #{ \override $grob #'transparent = ##t #})
+
 inStaffSegno =
 #(define-music-function (parser location) ()
    (_i "Put the segno variant 'varsegno' at this position into the staff,
@@ -664,6 +670,12 @@ octaveCheck =
    (make-music 'RelativeOctaveCheck
                'pitch pitch))

+omit =
+#(define-music-function (parser location grob) (string?)
+   (_i "Override the given @var{grob}'s stencil with @code{#f},
+effectively omitting it without taking up space.")
+   #{ \override $grob #'stencil = ##f #})
+
 once =
 #(define-music-function (parser location music) (ly:music?)
(_i "Set @code{once} to @code{#t} on all layout instruction events in @var{music}.")
@@ -1140,6 +1152,39 @@ shiftDurations =
     (lambda (x)
       (shift-one-duration-log x dur dots)) arg))

+single =
+#(define-music-function (parser location overrides music)
+   (ly:music? ly:music?)
+   (_i "Convert @var{overrides} to tweaks and apply them to @var{music}.
+This does not convert @code{\\revert}, @code{\\set} or @code{\\unset}
+and ignores nested overrides.")
+   (set! (ly:music-property music 'tweaks)
+         (fold-some-music
+          (lambda (m) (eq? (ly:music-property m 'name)
+                           'OverrideProperty))
+          (lambda (m tweaks)
+            (let check ((p (or (ly:music-property m 'grob-property #f)
+                               (ly:music-property m 'grob-property-path))))
+              (cond ((pair? p)
+                     (if (pair? (cdr p))
+                         tweaks ;ignore nested properties
+                         (check (car p)))) ;unpack single element path
+                    ((string? p)
+                     (check (string->symbol p)))
+                    ((symbol? p)
+                     (acons (cons (ly:music-property m 'symbol) ;grob name
+                                  p) ;grob property
+                            (ly:music-property m 'grob-value)
+                            tweaks))
+                    (else
+                     ;; This should never happen
+ (ly:parser-error parser (format #f "\\single confused by ~s" m)
+                                      location)
+                     tweaks))))
+          (ly:music-property music 'tweaks)
+          overrides))
+   music)
+
 skip =
 #(define-music-function (parser location dur) (ly:duration?)
   (_i "Skip forward by @var{dur}.")





reply via email to

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