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