lilypond-devel
[Top][All Lists]
Advanced

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

Re: Add music-type-predicate function (issue 255910043 by address@hidden


From: dak
Subject: Re: Add music-type-predicate function (issue 255910043 by address@hidden)
Date: Tue, 21 Jul 2015 06:33:26 +0000

Reviewers: simon.albrecht,


https://codereview.appspot.com/255910043/diff/1/scm/define-music-display-methods.scm
File scm/define-music-display-methods.scm (right):

https://codereview.appspot.com/255910043/diff/1/scm/define-music-display-methods.scm#newcode129
scm/define-music-display-methods.scm:129: (define post-event?
(music-type-predicate 'postevent))
How did this typo ('postevent instead of 'post-event) escape regtests?
It produces oodles of warnings for
input/regression/display-lily-tests.ly.

Pushed a fixed version but it was mere chance that I happened to reread
the patch before pushing.

Description:
Add music-type-predicate function

This creates a predicate function checking for a set of types.


Also:

Use music-type-predicate where useful

Please review this at https://codereview.appspot.com/255910043/

Affected files (+16, -16 lines):
  M ly/music-functions-init.ly
  M scm/define-music-display-methods.scm
  M scm/music-functions.scm


Index: ly/music-functions-init.ly
diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly
index 64cfa134b39bc046673067bc42b20faf35706642..b73d372feb9395e12c8811d7e361bd5079128a19 100644
--- a/ly/music-functions-init.ly
+++ b/ly/music-functions-init.ly
@@ -1800,10 +1800,10 @@ unsets already in @var{music} cause a warning. Non-property-related music is ig
      (let
          ((lst
            (fold-some-music
-            (lambda (m) (or (music-is-of-type? m 'layout-instruction-event)
-                            (music-is-of-type? m 'context-specification)
-                            (music-is-of-type? m 'apply-context)
-                            (music-is-of-type? m 'time-signature-music)))
+            (music-type-predicate '(layout-instruction-event
+                                    context-specification
+                                    apply-context
+                                    time-signature-music))
             (lambda (m overrides)
               (case (ly:music-property m 'name)
                 ((OverrideProperty)
Index: scm/define-music-display-methods.scm
diff --git a/scm/define-music-display-methods.scm b/scm/define-music-display-methods.scm index 04c9c8beb3b8f67a3f65b7b5ab7a66e447c5388c..a7affc8ee8c7c3576ad95e31b02c0ae424645518 100644
--- a/scm/define-music-display-methods.scm
+++ b/scm/define-music-display-methods.scm
@@ -126,8 +126,7 @@ expression."
 ;;; post events
 ;;;

-(define (post-event? m)
-  (music-is-of-type? m 'post-event))
+(define post-event? (music-type-predicate 'postevent))

 (define* (event-direction->lily-string event #:optional (required #t))
   (let ((direction (ly:music-property event 'direction)))
@@ -418,7 +417,7 @@ Otherwise, return #f."
          (chord-repeat (ly:music-property chord 'duration)))
     (call-with-values
         (lambda ()
-          (partition (lambda (m) (music-is-of-type? m 'rhythmic-event))
+          (partition (music-type-predicate 'rhythmic-event)
                      elements))
       (lambda (chord-elements other-elements)
         (cond ((pair? chord-elements)
Index: scm/music-functions.scm
diff --git a/scm/music-functions.scm b/scm/music-functions.scm
index 75e6da5349077ef08cb64f9d83665a88f4af6fae..7b46066edbba5698431bdce207fb8f7ebdca61a3 100644
--- a/scm/music-functions.scm
+++ b/scm/music-functions.scm
@@ -35,6 +35,14 @@
   "Does @code{mus} belong to the music class @code{type}?"
   (memq type (ly:music-property mus 'types)))

+(define-safe-public (music-type-predicate types)
+  "Returns a predicate function that can be used for checking
+music to have one of the types listed in @var{types}."
+   (if (cheap-list? types)
+       (lambda (m)
+         (any (lambda (t) (music-is-of-type? m t)) types))
+       (lambda (m) (music-is-of-type? m types))))
+
 ;; TODO move this
 (define-public ly:grob-property
   (make-procedure-with-setter ly:grob-property
@@ -715,9 +723,7 @@ duration is replaced with the specified @var{duration}."
   ;; articulations on individual events since they can't actually get
   ;; into a repeat chord given its input syntax.

-  (define (keep-element? m)
-    (any (lambda (t) (music-is-of-type? m t))
-         event-types))
+  (define keep-element? (music-type-predicate event-types))
   (define origin (ly:music-property repeat-chord 'origin #f))
   (define (set-origin! l)
     (if origin
@@ -1981,12 +1987,7 @@ not recursing into matches themselves."
   "Return a flat list of all music with @var{type} (either a single
 type symbol or a list of alternatives) inside of @var{music}, not
 recursing into matches themselves."
-  (extract-music
-   music
-   (if (cheap-list? type)
-       (lambda (m)
-         (any (lambda (t) (music-is-of-type? m t)) type))
-       (lambda (m) (music-is-of-type? m type)))))
+  (extract-music music (music-type-predicate type)))

 (define*-public (event-chord-wrap! music)
   "Wrap isolated rhythmic events and non-postevent events in





reply via email to

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