lilypond-devel
[Top][All Lists]
Advanced

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

Re: Allow Scheme/identifiers for duration multipliers (issue 346810043 b


From: dak
Subject: Re: Allow Scheme/identifiers for duration multipliers (issue 346810043 by address@hidden)
Date: Tue, 22 May 2018 14:32:17 -0700

Reviewers: thomasmorley651, carl.d.sorensen_gmail.com,

Message:
On 2018/05/22 21:05:59, thomasmorley651 wrote:
 From description and regtest: very nice.

Will it work for below as well?

#(define frac (inexact->exact (/ 3.0 4.0)))
{ r1*/frac }

As written no, but it depends on what you really wanted to write here.

{ r1*\frac } yes
{ r1*1/\frac } no

Description:
Allow Scheme/identifiers for duration multipliers


Also contains commit:

Regtest for computed duration multipliers

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

Affected files (+49, -0 lines):
  A input/regression/duration-multiplier-scheme.ly
  M lily/parser.yy


Index: input/regression/duration-multiplier-scheme.ly
diff --git a/input/regression/duration-multiplier-scheme.ly b/input/regression/duration-multiplier-scheme.ly
new file mode 100644
index 0000000000000000000000000000000000000000..258f8692a6799b382ab98bdd4e145131c56d852e
--- /dev/null
+++ b/input/regression/duration-multiplier-scheme.ly
@@ -0,0 +1,29 @@
+\version "2.21.0"
+
+\header {
+  texidoc = "Duration multipliers can be specified as scheme
+expressions, either as rationals or as a moment."
+}
+
+musicwithdrone = \repeat unfold 4 { c'4 e' g' c'' }
+
+musiclen = #(ly:music-length musicwithdrone)
+musicrat = #(ly:moment-main musiclen)
+
+\score {
+  <<
+    { \musicwithdrone \musicwithdrone \musicwithdrone \bar "|." }
+    { c'1 * #(ly:music-length musicwithdrone) ~
+      c'1 * \musiclen ~
+      c'1 * \musicrat
+    }
+  >>
+  \layout {
+    \context {
+      \Voice
+      \remove "Note_heads_engraver"
+      \consists "Completion_heads_engraver"
+    }
+  }
+}
+
Index: lily/parser.yy
diff --git a/lily/parser.yy b/lily/parser.yy
index 86d3deb3bd375f33256e7dacb45239f6f09506f3..3a0b2db65ce3222fad85e79548ca371a1980292f 100644
--- a/lily/parser.yy
+++ b/lily/parser.yy
@@ -3496,6 +3496,11 @@ dots:
        }
        ;

+multiplier_scm:
+       NUMBER_IDENTIFIER
+       | embedded_scm_bare
+       ;
+
 multipliers:
        /* empty */
        {
@@ -3516,6 +3521,21 @@ multipliers:
                else
                        $$ = scm_divide (scm_car ($3), scm_cdr ($3));
        }
+       | multipliers '*' multiplier_scm
+       {
+               if (Moment *mp = unsmob<Moment> ($3))
+                       $3 = ly_rational2scm (mp->main_part_);
+
+               if (!scm_is_real ($3)
+                       || scm_is_false (scm_exact_p ($3))
+                       || scm_is_true (scm_negative_p ($3)))
+               {
+                       parser->parser_error (@3, _ ("not a multiplier"));
+               } else if (SCM_UNBNDP ($1)) {
+                       $$ = $3;
+               } else
+                       $$ = scm_product ($1, $3);
+       }
        ;

 tremolo_type:





reply via email to

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