]> git.donarmstrong.com Git - lilypond.git/blob - lib/duration.cc
release: 0.0.58
[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 Moment
47 Duration::length() const
48 {
49     return Duration_convert::dur2_mom(*this);
50 }
51
52 void
53 Duration::set_plet(int i, int t)
54 {
55     plet_.iso_i_ = i; 
56     plet_.type_i_ = t;
57 }
58
59 void
60 Duration::set_ticks( int ticks_i )
61 {
62         assert( !type_i_ );
63         assert( !dots_i_ );
64         ticks_i_ = ticks_i;
65 }
66
67 String
68 Duration::str()const
69 {
70     return Duration_convert::dur2_str(*this);
71 }
72
73 Plet::Plet()
74 {
75     type_i_ = 1;
76     iso_i_ = 1;
77 }
78
79 Plet::Plet( int iso_i, int type_i )
80 {
81         iso_i_ = iso_i;
82         type_i_ = type_i;
83 }
84
85 Moment
86 Plet::mom()const
87 {
88     return  Moment( iso_i_, type_i_ );
89 }
90
91 bool
92 Duration::plet_b()
93 {
94     return !plet_.unit_b();
95 }
96
97 bool
98 Plet::unit_b()const
99 {
100     return type_i_ == 1 && iso_i_ == 1;
101 }
102