]> git.donarmstrong.com Git - lilypond.git/blob - lib/duration.cc
release: 0.0.62
[lilypond.git] / lib / duration.cc
1 /*
2   duration.cc -- implement Duration, Plet, 
3
4   source file of the LilyPond music typesetter
5
6   copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
7
8   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
9 */
10
11 #include "proto.hh"
12 #include "plist.hh"
13 #include "string.hh"
14 #include "source-file.hh"
15 #include "source.hh"
16 #include "moment.hh"
17 #include "duration.hh"
18 #include "duration-convert.hh"
19
20 // statics Duration
21 int Duration::division_1_i_s = 384 * 4;
22
23
24 Duration::Duration( int type_i, int dots_i = 0)
25 {
26 // this breaks mi2mu quite effectively
27 //    assert(duration_type_b(type_i));
28         type_i_ = type_i;
29         dots_i_ = dots_i;
30         ticks_i_ = 0;
31 }
32
33 bool
34 Duration::duration_type_b(int t)
35 {
36     int bit_i=0;
37     while (t > 0)
38     {
39         int rem = t % 2;
40         t /= 2;
41         bit_i += (rem == 1);
42     }
43     return bit_i == 1;
44 }
45
46 // ugh, what's this?
47 // i should be called "mom()", ... or at least "length_mom()"
48 Moment
49 Duration::length() const
50 {
51     return Duration_convert::dur2_mom(*this);
52 }
53
54 void
55 Duration::set_plet(int i, int t)
56 {
57     plet_.iso_i_ = i; 
58     plet_.type_i_ = t;
59 }
60
61 void
62 Duration::set_ticks( int ticks_i )
63 {
64         assert( !type_i_ );
65         assert( !dots_i_ );
66         ticks_i_ = ticks_i;
67 }
68
69 String
70 Duration::str()const
71 {
72     return Duration_convert::dur2_str(*this);
73 }
74
75 Plet::Plet()
76 {
77     type_i_ = 1;
78     iso_i_ = 1;
79 }
80
81 Plet::Plet( int iso_i, int type_i )
82 {
83         iso_i_ = iso_i;
84         type_i_ = type_i;
85 }
86
87 Moment
88 Plet::mom()const
89 {
90     return  Moment( iso_i_, type_i_ );
91 }
92
93 bool
94 Duration::plet_b()
95 {
96     return !plet_.unit_b();
97 }
98
99 bool
100 Plet::unit_b()const
101 {
102     return type_i_ == 1 && iso_i_ == 1;
103 }
104