X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fduration-scheme.cc;h=7d0788ea3eef5c4aa42e5b67d1e9dde2be60c1b8;hb=97a0169312a260933246ab224e4f8b0969871dd5;hp=0aec4a15ca0ae4c48acf7f97a15c4ef7ed4ae649;hpb=f93e4199873c91ae32f0e84a610d14853dc379df;p=lilypond.git diff --git a/lily/duration-scheme.cc b/lily/duration-scheme.cc index 0aec4a15ca..7d0788ea3e 100644 --- a/lily/duration-scheme.cc +++ b/lily/duration-scheme.cc @@ -1,7 +1,7 @@ /* This file is part of LilyPond, the GNU music typesetter. - Copyright (C) 1997--2011 Jan Nieuwenhuizen + Copyright (C) 1997--2015 Jan Nieuwenhuizen Han-Wen Nienhuys LilyPond is free software: you can redistribute it and/or modify @@ -25,8 +25,8 @@ MAKE_SCHEME_CALLBACK (Duration, less_p, 2); SCM Duration::less_p (SCM p1, SCM p2) { - Duration *a = unsmob_duration (p1); - Duration *b = unsmob_duration (p2); + Duration *a = unsmob (p1); + Duration *b = unsmob (p2); if (compare (*a, *b) < 0) return SCM_BOOL_T; @@ -41,8 +41,8 @@ LY_DEFINE (ly_duration_less_p, "ly:duration (p1); + Duration *b = unsmob (p2); if (Duration::compare (*a, *b) < 0) return SCM_BOOL_T; @@ -57,8 +57,8 @@ LY_DEFINE (ly_make_duration, "ly:make-duration", " eighth note, etc. The number of dots after the note is given by" " the optional argument @var{dotcount}.\n" "\n" - "The duration factor is optionally given by @var{num} and" - " @var{den}.\n" + "The duration factor is optionally given by integers @var{num} and" + " @var{den}, alternatively by a single rational number.\n" "\n" "A duration is a musical duration, i.e., a length of time" " described by a power of two (whole, half, quarter, etc.) and a" @@ -67,24 +67,24 @@ LY_DEFINE (ly_make_duration, "ly:make-duration", LY_ASSERT_TYPE (scm_is_integer, length, 1); int dots = 0; - if (dotcount != SCM_UNDEFINED) + if (!SCM_UNBNDP (dotcount)) { LY_ASSERT_TYPE (scm_is_integer, dotcount, 2); dots = scm_to_int (dotcount); } bool compress = false; - if (num != SCM_UNDEFINED) + if (!SCM_UNBNDP (num)) { - LY_ASSERT_TYPE (scm_is_number, num, 3); + LY_ASSERT_TYPE (ly_is_rational, num, 3); compress = true; } else num = scm_from_int (1); - if (den != SCM_UNDEFINED) + if (!SCM_UNBNDP (den)) { - LY_ASSERT_TYPE (scm_is_number, den, 4); + LY_ASSERT_TYPE (scm_is_integer, den, 4); compress = true; } else @@ -92,7 +92,7 @@ LY_DEFINE (ly_make_duration, "ly:make-duration", Duration p (scm_to_int (length), dots); if (compress) - p = p.compressed (Rational (scm_to_int (num), scm_to_int (den))); + p = p.compressed (ly_scm2rational (scm_divide (num, den))); return p.smobbed_copy (); } @@ -102,7 +102,7 @@ LY_DEFINE (ly_duration_log, "ly:duration-log", "Extract the duration log from @var{dur}.") { LY_ASSERT_SMOB (Duration, dur, 1); - return scm_from_int (unsmob_duration (dur)->duration_log ()); + return scm_from_int (unsmob (dur)->duration_log ()); } LY_DEFINE (ly_duration_dot_count, "ly:duration-dot-count", @@ -110,7 +110,7 @@ LY_DEFINE (ly_duration_dot_count, "ly:duration-dot-count", "Extract the dot count from @var{dur}.") { LY_ASSERT_SMOB (Duration, dur, 1); - return scm_from_int (unsmob_duration (dur)->dot_count ()); + return scm_from_int (unsmob (dur)->dot_count ()); } LY_DEFINE (ly_intlog2, "ly:intlog2", @@ -127,7 +127,7 @@ LY_DEFINE (ly_duration_length, "ly:duration-length", "The length of the duration as a @code{moment}.") { LY_ASSERT_SMOB (Duration, dur, 1); - return Moment (unsmob_duration (dur)->get_length ()).smobbed_copy (); + return Moment (unsmob (dur)->get_length ()).smobbed_copy (); } LY_DEFINE (ly_duration_2_string, "ly:duration->string", @@ -135,7 +135,7 @@ LY_DEFINE (ly_duration_2_string, "ly:duration->string", "Convert @var{dur} to a string.") { LY_ASSERT_SMOB (Duration, dur, 1); - return ly_string2scm (unsmob_duration (dur)->to_string ()); + return ly_string2scm (unsmob (dur)->to_string ()); } LY_DEFINE (ly_duration_factor, "ly:duration-factor", @@ -144,6 +144,19 @@ LY_DEFINE (ly_duration_factor, "ly:duration-factor", " Return it as a pair.") { LY_ASSERT_SMOB (Duration, dur, 1); - Rational r = unsmob_duration (dur)->factor (); + Rational r = unsmob (dur)->factor (); return scm_cons (scm_from_int64 (r.num ()), scm_from_int64 (r.den ())); } + +// This is likely what ly:duration-factor should have been in the +// first place. +LY_DEFINE (ly_duration_scale, "ly:duration-scale", + 1, 0, 0, (SCM dur), + "Extract the compression factor from @var{dur}." + " Return it as a rational.") +{ + LY_ASSERT_SMOB (Duration, dur, 1); + Rational r = unsmob (dur)->factor (); + + return ly_rational2scm (r); +}