X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmoment.cc;h=adcecff767140095dd22e5fbb5aa3d8a5453fdb5;hb=5bbfc22fce036b9b69df5e420de93e11da23c05e;hp=815f3f95297fd4ecb1837a403665b90a45708b16;hpb=332da9f4d25f9f63a3222efc87fae06b0c7abbdd;p=lilypond.git diff --git a/lily/moment.cc b/lily/moment.cc index 815f3f9529..adcecff767 100644 --- a/lily/moment.cc +++ b/lily/moment.cc @@ -1,9 +1,20 @@ -/* - moment.cc -- implement Moment +/* + This file is part of LilyPond, the GNU music typesetter. + + Copyright (C) 1999--2014 Han-Wen Nienhuys + + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - source file of the GNU LilyPond music typesetter + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - (c) 1999--2004 Han-Wen Nienhuys + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ #include "moment.hh" @@ -17,7 +28,7 @@ Moment::Moment () Moment::Moment (int m) { main_part_ = Rational (m); - grace_part_ = Rational ( 0); + grace_part_ = Rational (0); } Moment::Moment (Rational m, Rational g) @@ -33,6 +44,7 @@ Moment::Moment (Rational m) } #include "ly-smobs.icc" + IMPLEMENT_SIMPLE_SMOBS (Moment); IMPLEMENT_TYPE_P (Moment, "ly:moment?"); @@ -45,13 +57,13 @@ Moment::mark_smob (SCM) int Moment::print_smob (SCM s, SCM port, scm_print_state *) { - Moment *r = (Moment *) SCM_CELL_WORD_1 (s); - + Moment *r = (Moment *) SCM_CELL_WORD_1 (s); + scm_puts ("#to_string (); - scm_puts ((char *)str.to_str0 (), port); + string str = r->to_string (); + scm_puts ((char *)str.c_str (), port); scm_puts (">", port); - + return 1; } @@ -59,131 +71,31 @@ SCM Moment::as_scheme () const { return scm_list_5 (ly_symbol2scm ("ly:make-moment"), - scm_from_int (main_part_.num()), - scm_from_int (main_part_.den()), - scm_from_int (grace_part_.num()), - scm_from_int (grace_part_.den())); -} - -/* TODO: add optional factor argument. */ -LY_DEFINE (ly_make_moment, "ly:make-moment", - 2, 2, 0, (SCM n, SCM d, SCM gn, SCM gd), - "Create the rational number with main timing @var{n}/@var{d}, " - "and optional grace timin @var{gn}/@var{gd}.\n" - "\n" - "\n" - "Moment is a point in musical time. " - "It is consists of a pair of rationals (@var{m},@var{g}), " - "where @var{m} is the timing for the main\n" - "notes, and @var{g} the timing for grace notes. " - "In absence of grace notes, @var{g} is zero.\n") -{ - SCM_ASSERT_TYPE (scm_is_integer (n), n, SCM_ARG1, __FUNCTION__, "integer"); - SCM_ASSERT_TYPE (scm_is_integer (d), d, SCM_ARG2, __FUNCTION__, "integer"); - - int grace_num = 0; - if (gn != SCM_UNDEFINED) - { - SCM_ASSERT_TYPE (scm_is_integer (gn), gn, SCM_ARG3, __FUNCTION__, "integer"); - grace_num = scm_to_int (gn); - } - - int grace_den = 1; - if (gd != SCM_UNDEFINED) - { - SCM_ASSERT_TYPE (scm_is_integer (gd), gd, SCM_ARG4, __FUNCTION__, "integer"); - grace_den = scm_to_int (gd); - } - - return Moment (Rational (scm_to_int (n), scm_to_int (d)), - Rational (grace_num, grace_den)).smobbed_copy (); -} - -LY_DEFINE (ly_add_moment, "ly:add-moment", - 2, 0, 0, (SCM a, SCM b), - "Add two moments.") -{ - Moment *ma = unsmob_moment (a); - Moment *mb = unsmob_moment (b); - SCM_ASSERT_TYPE (ma, a, SCM_ARG1, __FUNCTION__, "moment"); - SCM_ASSERT_TYPE (mb, b, SCM_ARG2, __FUNCTION__, "moment"); - return (*ma + *mb).smobbed_copy (); -} - -LY_DEFINE (ly_mul_moment,"ly:mul-moment", - 2, 0, 0, (SCM a, SCM b), - "Multiply two moments.") -{ - Moment *ma = unsmob_moment (a); - Moment *mb = unsmob_moment (b); - SCM_ASSERT_TYPE (ma, a, SCM_ARG1, __FUNCTION__, "moment"); - SCM_ASSERT_TYPE (mb, b, SCM_ARG2, __FUNCTION__, "moment"); - return (*ma * *mb).smobbed_copy (); -} - -LY_DEFINE (ly_div_moment,"ly:div-moment", - 2, 0, 0, (SCM a, SCM b), - "Divide two moments.") -{ - Moment *ma = unsmob_moment (a); - Moment *mb = unsmob_moment (b); - SCM_ASSERT_TYPE (ma, a, SCM_ARG1, __FUNCTION__, "moment"); - SCM_ASSERT_TYPE (mb, b, SCM_ARG2, __FUNCTION__, "moment"); - return (*ma / *mb).smobbed_copy (); -} - -LY_DEFINE (ly_moment_main_numerator,"ly:moment-main-numerator", - 1, 0, 0, (SCM mom), - "Extract numerator from main timing.") -{ - Moment *ma = unsmob_moment (mom); - SCM_ASSERT_TYPE (ma, mom, SCM_ARG1, __FUNCTION__, "moment"); - - return scm_from_int (ma->main_part_.numerator ()); -} - -LY_DEFINE (ly_moment_main_denominator,"ly:moment-main-denominator", - 1, 0, 0, (SCM mom), - "Extract denominator from main timing.") -{ - Moment *ma = unsmob_moment (mom); - SCM_ASSERT_TYPE (ma, mom, SCM_ARG1, __FUNCTION__, "moment"); - - return scm_from_int (ma->main_part_.denominator ()); -} - -LY_DEFINE (ly_moment_less_p,"ly:moment