]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/moment.hh
63048a3a75dd1cac329ce4bf5c2ccb607bcf8823
[lilypond.git] / lily / include / moment.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1999--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef MOMENT_HH
21 #define MOMENT_HH
22
23 #include "smobs.hh"
24 #include "rational.hh"
25
26 /**
27    Musical timing (Main-timing, grace-timing) with glue for
28    Guilification;
29 */
30 class Moment : public Simple_smob<Moment>
31 {
32 public:
33   static SCM equal_p (SCM, SCM);
34   int print_smob (SCM, scm_print_state *);
35   static const char type_p_name_[];
36   Moment ();
37   Moment (int m);
38
39   Moment (Rational, Rational);
40   Moment (Rational m);
41
42   Moment operator - () const;
43
44   void operator += (Moment const &m);
45   void operator -= (Moment const &m);
46
47   void operator *= (Moment const &m);
48   void operator /= (Moment const &m);
49   void operator %= (Moment const &m);
50
51   Rational main_part_;
52   Rational grace_part_;
53
54   void set_infinite (int k);
55
56   bool to_bool () const;
57   I64 den () const;
58   I64 num () const;
59   /*
60     Deliver a copy of THIS as a smobified SCM
61   */
62   string to_string () const;
63   static int compare (Moment const &, Moment const &);
64   SCM as_scheme () const;
65 };
66
67 IMPLEMENT_ARITHMETIC_OPERATOR (Moment, +);
68 IMPLEMENT_ARITHMETIC_OPERATOR (Moment, -);
69 IMPLEMENT_ARITHMETIC_OPERATOR (Moment, / );
70 IMPLEMENT_ARITHMETIC_OPERATOR (Moment, *);
71 IMPLEMENT_ARITHMETIC_OPERATOR (Moment, % );
72
73 int compare (Moment const &, Moment const &);
74 INSTANTIATE_COMPARE (Moment const &, Moment::compare);
75
76 Moment robust_scm2moment (SCM, Moment);
77
78 #ifdef STREAM_SUPPORT
79 ostream &operator << (ostream &, Moment const &);
80 #endif
81
82 bool moment_less (SCM a, SCM b);
83
84 #endif /* MOMENT_HH */