]> git.donarmstrong.com Git - lilypond.git/blob - lib/include/duration.hh
release: 0.0.41
[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         void set_ticks( int ticks_i );
28
29         static int division_1_i_s;
30 //          int i_;     // balltype -> type!
31         int type_i_;
32         int dots_i_;
33         Plet* plet_p_;
34         int ticks_i_;
35 };
36
37 /// (plet)
38 struct Plet {
39         Plet( int replace_i, int type_i );
40         Plet( Plet const& plet_c_r );
41
42 //          int i_;
43         int iso_i_;  // 2/3; 2 is not duration, maar of count!
44         int type_i_;
45 };
46
47 /**
48         Duration_convert handles all conversions to -n fro Duration (dur).
49         That is including (integer + division) representation for MIDI,
50         and conversion from unexact time representation (best guess :-).
51
52         A Moment (mom) is a Rational that holds the time fraction 
53         compared to a whole note (before also called wholes).
54
55         SUGGESTION: currently a moment in time is called moment too;
56         let-s typedef Rational When too, so that we get 
57         When Staff_column::when(), Moment Voice_element::mom().
58 */
59 struct Duration_convert {
60         static bool be_blonde_b_s;
61         static bool no_double_dots_b_s;
62         static bool no_triplets_b_s;
63         static int no_smaller_than_i_s;
64
65 //      /// Most used division in MIDI, all fine with me.
66 //      static int const division_1_c_i = 384;
67
68 //      /// Return (integer, division) representation.
69 //      static int dur2_i( Duration dur, int division_1_i = division_1_c_i );
70
71         /// Return number of ticks in (ticks, division_1) representation
72         static int dur2ticks_i( Duration dur );
73         
74         /// Return Moment representation (fraction of whole note).
75         static Moment dur2_mom( Duration dur );
76
77         /// Return Mudela string representation.
78         static String dur2_str( Duration dur );
79
80 //      /// Return Moment from (integer, division) representation.
81 //      static Moment i2_mom( int i, int division_1_i = division_1_c_i );
82
83 //      /// Return Moment (fraction of whole) representation, best guess.
84 //      static Duration mom2_dur( Moment mom );
85
86         /// Return plet factor (not a Moment: should use Rational?).
87         static Moment plet_factor_mom( Duration dur );
88
89         /** Return synchronisation factor for mom, so that
90             mom2_dur( mom / sync_f ) will return the duration dur.              
91         */ 
92         static Real sync_f( Duration dur, Moment mom );
93
94         /// Return exact duration, in midi-ticks if not-exact.
95         static Duration ticks2_dur( int ticks_i );
96
97         /// Return standardised duration, best guess if not exact.
98         static Duration ticks2standardised_dur( int ticks_i );
99 };
100
101 /// (iter_dur)
102 struct Duration_iterator {
103         /// start at shortest: 128:2/3
104         Duration_iterator();
105
106         // **** what about these three here ?
107         /// return forward_dur();
108         Duration operator ++(int); 
109
110         /// return ok()
111         operator bool(); 
112
113         /// return dur()
114         Duration operator ()(); 
115         // ****
116
117         /// return current dur
118         Duration dur();
119
120         /// return dur(), step to next
121         Duration forward_dur();
122
123         /// durations left?
124         bool ok();
125
126 private:
127         Duration cursor_dur_;
128 };
129
130 #endif // DURATION_HH
131