X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmoment.cc;h=df1a405779a90b499375e2aa4f108370d0f3c87e;hb=85394d425536d267ed0cb71d17023849f1611180;hp=a50ce3cbd1f0004c7a4a17bf6a4f095fd64290a8;hpb=bdf4ab13203502e7ec7cf9cf5896527643a07c1f;p=lilypond.git diff --git a/lily/moment.cc b/lily/moment.cc index a50ce3cbd1..df1a405779 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. - source file of the GNU LilyPond music typesetter + Copyright (C) 1999--2012 Han-Wen Nienhuys - (c) 1999--2005 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. + + 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" @@ -33,6 +44,7 @@ Moment::Moment (Rational m) } #include "ly-smobs.icc" + IMPLEMENT_SIMPLE_SMOBS (Moment); IMPLEMENT_TYPE_P (Moment, "ly:moment?"); @@ -48,8 +60,8 @@ Moment::print_smob (SCM s, SCM port, scm_print_state *) 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,10 +71,10 @@ 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 ())); + scm_from_int64 (main_part_.num ()), + scm_from_int64 (main_part_.den ()), + scm_from_int64 (grace_part_.num ()), + scm_from_int64 (grace_part_.den ())); } SCM @@ -96,6 +108,7 @@ Moment::operator += (Moment const &src) main_part_ += src.main_part_; grace_part_ += src.grace_part_; } + void Moment::operator -= (Moment const &src) { @@ -103,9 +116,7 @@ Moment::operator -= (Moment const &src) grace_part_ -= src.grace_part_; } -/* - only take the main part of SRC for multiplication. -*/ +/* Only take the main part of SRC for multiplication. */ void Moment::operator *= (Moment const &src) { @@ -113,9 +124,7 @@ Moment::operator *= (Moment const &src) grace_part_ *= src.main_part_; } -/* - only take the main part of SRC for multiplication. -*/ +/* Only take the main part of SRC for division. */ void Moment::operator /= (Moment const &src) { @@ -123,13 +132,22 @@ Moment::operator /= (Moment const &src) grace_part_ /= src.main_part_; } -int +/* Only take the main part of SRC for division. */ +void +Moment::operator %= (Moment const &src) +{ + main_part_ %= src.main_part_; + grace_part_ %= src.main_part_; +} + +I64 Moment::den () const { + /* TODO: ensure MSB == 0 here */ return main_part_.den (); } -int +I64 Moment::num () const { return main_part_.num (); @@ -147,14 +165,12 @@ Moment::set_infinite (int k) main_part_.set_infinite (k); } -String +string Moment::to_string () const { - String s = main_part_.to_string (); + string s = main_part_.to_string (); if (grace_part_) - { - s += "G" + grace_part_.to_string (); - } + s += "G" + grace_part_.to_string (); return s; } @@ -168,8 +184,8 @@ Moment::operator - () const } #ifdef STREAM_SUPPORT -std::ostream & -operator << (std::ostream &os, Moment const &m) +ostream & +operator << (ostream &os, Moment const &m) { os << m.to_string (); return os;