]> git.donarmstrong.com Git - lilypond.git/blob - lib/duration.cc
8c08c128023e1325dd422f38b71b790d680a8ff7
[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_plet(Duration d)
63 {
64     plet_.iso_i_ = d.plet_.iso_i_; 
65     plet_.type_i_ = d.plet_.type_i_;
66 }
67
68 void
69 Duration::set_ticks( int ticks_i )
70 {
71         assert( !type_i_ );
72         assert( !dots_i_ );
73         ticks_i_ = ticks_i;
74 }
75
76 String
77 Duration::str()const
78 {
79     return Duration_convert::dur2_str(*this);
80 }
81
82 Plet::Plet()
83 {
84     type_i_ = 1;
85     iso_i_ = 1;
86 }
87
88 Plet::Plet( int iso_i, int type_i )
89 {
90         iso_i_ = iso_i;
91         type_i_ = type_i;
92 }
93
94 Moment
95 Plet::mom()const
96 {
97     return  Moment( iso_i_, type_i_ );
98 }
99
100 bool
101 Duration::plet_b()
102 {
103     return !plet_.unit_b();
104 }
105
106 bool
107 Plet::unit_b()const
108 {
109     return type_i_ == 1 && iso_i_ == 1;
110 }
111