lilypond-devel
[Top][All Lists]
Advanced

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

Re: Shortcut for \repeat unfold


From: David Kastrup
Subject: Re: Shortcut for \repeat unfold
Date: Sun, 26 Sep 2021 00:55:19 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Dan Eble <dan@lyric.works> writes:

> On Sep 25, 2021, at 14:27, David Kastrup <dak@gnu.org> wrote:
>> 
>> Dan Eble <dan@lyric.works> writes:
>> 
>> How about we change \repeat ... \alternative in its structure to be
>> \repeat ... { \alternative ... }, namely introduce a separate music
>> expression for \alternative?  That way neither \repeat nor \alternative
>> need to be special.
>
> Alternatives inside the repeat block are already partially supported.
> They just don't work as desired in the most interesting case: at the
> tail.
>
> I'm optimistic about implementing full support, but it's tangled up in
> work on \repeat segno and there's something making it hard for me to
> work much on LilyPond recently.

Would the following stopgap measure make any sense for decoupling the
needs expressed in this thread and your time planning?

>From 27e1064d6dfc8a4748b0a62efa2c979339099f9a Mon Sep 17 00:00:00 2001
From: David Kastrup <dak@gnu.org>
Date: Sun, 26 Sep 2021 00:48:48 +0200
Subject: [PATCH] Allow partial \repeat commands without \alternative

This allows using

    \repeat <string> <number> \etc

and

    \repeat <string> \etc

to act like partial music functions in order to make it easy to define
abbreviations.  However, those partial music functions don't support
appending `\alternative` phrases like repeats usually do.
---
 lily/include/lily-imports.hh   |  1 +
 lily/lily-imports.cc           |  1 +
 lily/parser.yy                 | 20 ++++++++++++++++++--
 scm/ly-syntax-constructors.scm |  8 +++++++-
 4 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/lily/include/lily-imports.hh b/lily/include/lily-imports.hh
index 88fa4b2478..3b35e5131b 100644
--- a/lily/include/lily-imports.hh
+++ b/lily/include/lily-imports.hh
@@ -166,6 +166,7 @@ extern Variable property_revert;
 extern Variable property_set;
 extern Variable property_unset;
 extern Variable repeat;
+extern Variable repeat_alt;
 extern Variable repetition_chord;
 extern Variable sequential_alternative_music;
 extern Variable sequential_music;
diff --git a/lily/lily-imports.cc b/lily/lily-imports.cc
index 6c4e4496ab..ea6ff46032 100644
--- a/lily/lily-imports.cc
+++ b/lily/lily-imports.cc
@@ -153,6 +153,7 @@ Variable property_revert ("property-revert");
 Variable property_set ("property-set");
 Variable property_unset ("property-unset");
 Variable repeat ("repeat");
+Variable repeat_alt ("repeat-alt");
 Variable repetition_chord ("repetition-chord");
 Variable sequential_alternative_music ("sequential-alternative-music");
 Variable sequential_music ("sequential-music");
diff --git a/lily/parser.yy b/lily/parser.yy
index 01f9f0a2a5..8a737ac8ef 100644
--- a/lily/parser.yy
+++ b/lily/parser.yy
@@ -849,6 +849,22 @@ partial_function:
                                             scm_cadr ($2), scm_car ($2)),
                                 $4);
        }
+       | REPEAT simple_string unsigned_number
+       {
+               $$ = scm_cons (scm_list_3 (Syntax::repeat, $3, $2), SCM_EOL);
+       }
+       | REPEAT simple_string unsigned_number partial_function
+       {
+               $$ = scm_cons (scm_list_3 (Syntax::repeat, $3, $2), $4);
+       }
+       | REPEAT simple_string
+       {
+               $$ = scm_cons (scm_list_2 (Syntax::repeat, $2), SCM_EOL);
+       }
+       | REPEAT simple_string partial_function
+       {
+               $$ = scm_cons (scm_list_2 (Syntax::repeat, $2), $3);
+       }
 // Stupid duplication because we already expect ETC here.  It will follow 
anyway.
        | script_dir markup_mode markup_partial_function
        {
@@ -1487,11 +1503,11 @@ music_assign:
 repeated_music:
        REPEAT simple_string unsigned_number music
        {
-               $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, SCM_EOL);
+               $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4);
        }
        | REPEAT simple_string unsigned_number music 
sequential_alternative_music
        {
-               $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, $5);
+               $$ = MAKE_SYNTAX (repeat_alt, @$, $2, $3, $4, $5);
        }
        ;
 
diff --git a/scm/ly-syntax-constructors.scm b/scm/ly-syntax-constructors.scm
index 7f9fe275e9..3ef6b01611 100644
--- a/scm/ly-syntax-constructors.scm
+++ b/scm/ly-syntax-constructors.scm
@@ -190,7 +190,13 @@
         (make-sequential-music (list tempo-change tempo-set))
         tempo-change)))
 
-(define-public (repeat type num body alts)
+(define-public repeat
+  (define-syntax-function ly:music?
+    (type num body)
+    (string? index? ly:music?)
+    (ly:set-origin! (make-repeat type num body '()))))
+
+(define-public (repeat-alt type num body alts)
   (ly:set-origin! (make-repeat type num body alts)))
 
 (define (script-to-mmrest-text music)
-- 
2.32.0


-- 
David Kastrup

reply via email to

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