X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmoment.cc;h=9f3e8ed383837e3fb7059eebff437cac5423588a;hb=47db9a3883d726ca53e2133a3b2298f78dd6a32e;hp=edd24f8cd698b18128083d06e50b63c77afef365;hpb=94a1966c72301b8bd1d8bb3b8628c3f089d007cf;p=lilypond.git diff --git a/lily/moment.cc b/lily/moment.cc index edd24f8cd6..9f3e8ed383 100644 --- a/lily/moment.cc +++ b/lily/moment.cc @@ -1,220 +1,148 @@ -/* - moment.cc -- implement Moment - - source file of the GNU LilyPond music typesetter - - (c) 1999--2004 Han-Wen Nienhuys - - */ +/* + This file is part of LilyPond, the GNU music typesetter. + Copyright (C) 1999--2015 Han-Wen Nienhuys -#include "lily-guile.hh" -#include "moment.hh" -#include "warn.hh" -#include "ly-smobs.icc" + 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. -IMPLEMENT_SIMPLE_SMOBS (Moment); -IMPLEMENT_TYPE_P (Moment, "ly:moment?"); - -SCM -Moment::mark_smob (SCM) -{ - return SCM_EOL; -} + 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. + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . +*/ +#include "moment.hh" +#include "warn.hh" -int -Moment::print_smob (SCM s, SCM port, scm_print_state *) +Moment::Moment () { - Moment *r = (Moment *) ly_cdr (s); - - scm_puts ("#to_string (); - scm_puts ((char *)str.to_str0 (), port); - scm_puts (">", port); - - return 1; } -/* - TODO: add optional factor argument. -*/ -LY_DEFINE (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\n" - "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\n" - "notes, @var{g} is zero.\n" - ) +Moment::Moment (int m) { - SCM_ASSERT_TYPE (SCM_INUMP (n), n, SCM_ARG1, __FUNCTION__, "integer"); - SCM_ASSERT_TYPE (SCM_INUMP (d), d, SCM_ARG2, __FUNCTION__, "integer"); - - int grace_num = 0; - if (gn != SCM_UNDEFINED) - { - SCM_ASSERT_TYPE (SCM_INUMP (gn), gn, SCM_ARG3, __FUNCTION__, "integer"); - grace_num = ly_scm2int (gn); - } - - int grace_den = 1; - if (gd != SCM_UNDEFINED) - { - SCM_ASSERT_TYPE (SCM_INUMP (gd), gd, SCM_ARG4, __FUNCTION__, "integer"); - grace_den = ly_scm2int (gd); - } - - return Moment (Rational (ly_scm2int (n), ly_scm2int (d)), - Rational (grace_num, grace_den)).smobbed_copy (); + main_part_ = Rational (m); + grace_part_ = Rational (0); } -LY_DEFINE (add_moment,"ly:add-moment", 2,0,0, (SCM a, SCM b), - "Add two moments." - ) +Moment::Moment (Rational m, Rational g) { - 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 (); + main_part_ = m; + grace_part_ = g; } - -LY_DEFINE (mul_moment,"ly:mul-moment", 2,0,0, (SCM a, SCM b), - "Multiply two moments." - ) +Moment::Moment (Rational m) { - 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 (); + main_part_ = m; + grace_part_ = Rational (0); } +const char Moment::type_p_name_[] = "ly:moment?"; -LY_DEFINE (div_moment,"ly:div-moment", 2,0,0, (SCM a, SCM b), - "Divide two moments." - ) + +int +Moment::print_smob (SCM port, scm_print_state *) { - 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"); + scm_puts ("#", port); - return (*ma / *mb).smobbed_copy (); + return 1; } -LY_DEFINE (ly_moment_less_p,"ly:moment