]> git.donarmstrong.com Git - lilypond.git/blob - lib/include/duration.hh
partial: 0.0.39-1.jcn
[lilypond.git] / lib / include / duration.hh
1 //
2 // duration.hh -- declare Duration, Plet, Duration_convert Duration_iterator
3 //
4 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
5
6 // split into 4?
7
8 #ifndef DURATION_HH
9 #define DURATION_HH
10
11 // ugh, to get me in lily lib
12 extern bool no_triplets_bo_g;
13
14 /// (dur)
15 struct Duration {
16         // actually i hate it when other people use default arguments,
17         // because it makes you easily loose track of what-s really
18         // happening; in the routine-s implementation you-re not aware
19         // of this defaultness (who sets this stupid value?).
20         Duration( int type_i = 1, int dots_i = 0, Plet* plet_p = 0 );
21         Duration( Duration const& dur_c_r );
22         ~Duration();
23
24         Duration const& operator =( Duration const& dur_c_r );
25
26         void set_plet( Plet* plet_l ); // handiger: newt zelf
27
28 //          int i_;     // balltype -> type!
29         int type_i_;
30         int dots_i_;
31         Plet* plet_p_;
32 };
33
34 /// (plet)
35 struct Plet {
36         Plet( int replace_i, int type_i );
37         Plet( Plet const& plet_c_r );
38
39 //          int i_;
40         int iso_i_;  // 2/3; 2 is not duration, maar of count!
41         int type_i_;
42 };
43
44 /**
45         Duration_convert handles all conversions to -n fro Duration (dur).
46         That is including (integer + division) representation for MIDI,
47         and conversion from unexact time representation (best guess :-).
48
49         A Moment (mom) is a Rational that holds the time fraction 
50         compared to a whole note (before also called wholes).
51
52         SUGGESTION: currently a moment in time is called moment too;
53         let-s typedef Rational When too, so that we get 
54         When Staff_column::when(), Moment Voice_element::mom().
55 */
56 struct Duration_convert {
57         /// Most used division in MIDI, all fine with me.
58         static int const division_1_c_i = 384;
59
60         /// Return (integer, division) representation.
61         static int dur2_i( Duration dur, int division_1_i = division_1_c_i );
62         
63         /// Return Moment representation (fraction of whole note).
64         static Moment dur2_mom( Duration dur );
65
66         /// Return Mudela string representation.
67         static String dur2_str( Duration dur );
68
69         /// Return Moment from (integer, division) representation.
70         static Moment i2_mom( int i, int division_1_i = division_1_c_i );
71
72         /// Return Moment (fraction of whole) representation, best guess.
73         static Duration mom2_dur( Moment mom );
74
75         /// Return plet factor (not a Moment: should use Rational?).
76         static Moment plet_factor_mom( Duration dur );
77
78         /** Return synchronisation factor for mom, so that
79             mom2_dur( mom / sync_f ) will return the duration dur.              
80         */ 
81         static Real sync_f( Duration dur, Moment mom );
82 };
83
84 /// (iter_dur)
85 struct Duration_iterator {
86         /// start at shortest: 128:2/3
87         Duration_iterator();
88
89         // **** what about these three here ?
90         /// return forward_dur();
91         Duration operator ++(int); 
92
93         /// return ok()
94         operator bool(); 
95
96         /// return dur()
97         Duration operator ()(); 
98         // ****
99
100         /// return current dur
101         Duration dur();
102
103         /// return dur(), step to next
104         Duration forward_dur();
105
106         /// durations left?
107         bool ok();
108
109 private:
110         Duration cursor_dur_;
111 };
112
113 #endif // DURATION_HH
114