]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/parser.yy
Use new arguments of make_duration
[lilypond.git] / lily / parser.yy
index 55a6ad41a6a7c023fc48e0050399b360c7da6abd..ae00eb64a2b8c673af628161aa9674628063efa7 100644 (file)
@@ -232,7 +232,7 @@ SCM loc_on_music (Lily_parser *parser, Input loc, SCM arg);
 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
 SCM make_chord_step (SCM step, Rational alter);
 SCM make_simple_markup (SCM a);
-SCM make_duration (SCM t, int dots = 0);
+SCM make_duration (SCM t, int dots = 0, SCM factor = SCM_UNDEFINED);
 bool is_regular_identifier (SCM id, bool multiple=false);
 SCM try_string_variants (SCM pred, SCM str);
 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
@@ -3208,26 +3208,13 @@ steno_duration:
                }
        }
        | DURATION_IDENTIFIER dots      {
-               Duration *d = unsmob<Duration> ($1);
-               Duration k (d->duration_log (),
-                            d->dot_count () + scm_to_int ($2));
-               k = k.compressed (d->factor ());
-                scm_remember_upto_here_1 ($1);
-               $$ = k.smobbed_copy ();
+               $$ = make_duration ($1, scm_to_int ($2));
        }
        ;
 
 multiplied_duration:
-       steno_duration {
-               $$ = $1;
-       }
-       | multiplied_duration '*' UNSIGNED {
-               $$ = unsmob<Duration> ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
-       }
-       | multiplied_duration '*' FRACTION {
-               Rational  m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
-
-               $$ = unsmob<Duration> ($$)->compressed (m).smobbed_copy ();
+       steno_duration multipliers {
+               $$ = make_duration ($1, 0, $2);
        }
        ;
 
@@ -3240,6 +3227,28 @@ dots:
        }
        ;
 
+multipliers:
+       /* empty */
+       {
+               $$ = SCM_UNDEFINED;
+       }
+       | multipliers '*' UNSIGNED
+       {
+               if (!SCM_UNBNDP ($1))
+                       $$ = scm_product ($1, $3);
+               else
+                       $$ = $3;
+       }
+       | multipliers '*' FRACTION
+       {
+               if (!SCM_UNBNDP ($1))
+                       $$ = scm_product ($1, scm_divide (scm_car ($3),
+                                                         scm_cdr ($3)));
+               else
+                       $$ = scm_divide (scm_car ($3), scm_cdr ($3));
+       }
+       ;
+
 tremolo_type:
        ':'     {
                $$ = scm_from_int (parser->default_tremolo_type_);
@@ -4086,6 +4095,14 @@ make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
                        n->set_property ("pitch", simple);
                        return n->unprotect ();
                }
+               SCM d = simple;
+               if (scm_is_integer (simple))
+                       d = make_duration (simple);
+               if (unsmob<Duration> (d)) {
+                       Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
+                       n->set_property ("duration", d);
+                       return n->unprotect ();
+               }
                return simple;
        } else if (parser->lexer_->is_lyric_state ()) {
                if (Text_interface::is_markup (simple))
@@ -4118,13 +4135,29 @@ make_simple_markup (SCM a)
 }
 
 SCM
-make_duration (SCM d, int dots)
+make_duration (SCM d, int dots, SCM factor)
 {
-       int t = scm_to_int (d);
-       if (t > 0 && (t & (t-1)) == 0)
-               return Duration (intlog2 (t), dots).smobbed_copy ();
-       else
-               return SCM_UNDEFINED;
+       Duration k;
+
+       if (Duration *dur = unsmob<Duration> (d)) {
+               if (!dots && SCM_UNBNDP (factor))
+                       return d;
+               k = *dur;
+               if (dots)
+                       k = Duration (k.duration_log (), k.dot_count () + dots)
+                               .compressed (k.factor ());
+       } else {
+               int t = scm_to_int (d);
+               if (t > 0 && (t & (t-1)) == 0)
+                       k = Duration (intlog2 (t), dots);
+               else
+                       return SCM_UNDEFINED;
+       }
+
+       if (!SCM_UNBNDP (factor))
+               k = k.compressed (ly_scm2rational (factor));
+
+       return k.smobbed_copy ();
 }
 
 SCM