lilypond-1.1.27
[lilypond.git] / hdr / duration.hh
blobff92cf23f3082d418434d93b7675c9474242f894
1 //
2 // duration.hh -- declare Duration, Plet, Duration_convert Duration_iterator
3 //
4 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
6 // split into 4?
8 #ifndef DURATION_HH
9 #define DURATION_HH
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();
21 Duration const& operator =( Duration const& dur_c_r );
23 void set_plet( Plet* plet_l ); // handiger: newt zelf
25 // int i_; // balltype -> type!
26 int type_i_;
27 int dots_i_;
28 Plet* plet_p_;
31 /// (plet)
32 struct Plet {
33 Plet( int replace_i, int type_i );
34 Plet( Plet const& plet_c_r );
36 // int i_;
37 int iso_i_; // 2/3; 2 is not duration, maar of count!
38 int type_i_;
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 :-).
46 A Moment (mom) is a Rational that holds the time fraction
47 compared to a whole note (before also called wholes).
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().
53 struct Duration_convert {
54 /// Most used division in MIDI, all fine with me.
55 static int const division_1_c_i = 384;
57 /// Return (integer, division) representation.
58 static int dur2_i( Duration dur, int division_1_i = division_1_c_i );
60 /// Return Moment representation (fraction of whole note).
61 static Moment dur2_mom( Duration dur );
63 /// Return Mudela string representation.
64 static String dur2_str( Duration dur );
66 /// Return Moment from (integer, division) representation.
67 static Moment i2_mom( int i, int division_1_i = division_1_c_i );
69 /// Return Moment (fraction of whole) representation, best guess.
70 static Duration mom2_dur( Moment mom );
72 /// Return plet factor (not a Moment: should use Rational?).
73 static Moment plet_factor_mom( Duration dur );
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 );
81 /// (iter_dur)
82 struct Duration_iterator {
83 /// start at shortest: 128:2/3
84 Duration_iterator();
86 // **** what about these three here ?
87 /// return forward_dur();
88 Duration operator ++(int);
90 /// return ok()
91 operator bool();
93 /// return dur()
94 Duration operator ()();
95 // ****
97 /// return current dur
98 Duration dur();
100 /// return dur(), step to next
101 Duration forward_dur();
103 /// durations left?
104 bool ok();
106 private:
107 Duration cursor_dur_;
110 #endif // DURATION_HH