]> git.donarmstrong.com Git - lilypond.git/blob - lib/include/duration-convert.hh
release: 0.1.43
[lilypond.git] / lib / include / duration-convert.hh
1 /*
2           duration-convert.hh -- declare 
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9
10 #ifndef DURATION_CONVERT_HH
11 #define DURATION_CONVERT_HH
12 #include "duration.hh"
13 #include "string.hh"
14 //#include "array.hh"
15 #include "varray.hh"
16
17 /**
18         Duration_convert handles all conversions to -n fro Duration (dur).
19         That is including (integer + division) representation for MIDI,
20         and conversion from unexact time representation (best guess :-).
21
22         A Moment (mom) is a Rational that holds the time fraction 
23         compared to a whole note (before also called wholes).
24
25         SUGGESTION: currently a moment in time is called moment too;
26         let-s typedef Rational When too, so that we get 
27         When Staff_column::when (), Moment Voice_element::mom ().
28
29         [todo]
30         move all statics to real members, instantiate Duration_convert
31         object (s).
32 */
33 struct Duration_convert {
34         
35     /* Urgh. statics.
36      */
37     static bool const midi_as_plet_b_s = true;
38     static bool no_quantify_b_s;
39     static bool no_double_dots_b_s;
40     static bool no_triplets_b_s;
41     static int no_smaller_than_i_s;
42     static Array<Duration> dur_array_s;
43
44 //      /// Most used division in MIDI, all fine with me.
45 //      static int const division_1_c_i = 384;
46
47 //      /// Return (integer, division) representation.
48 //      static int dur2_i (Duration dur, int division_1_i = division_1_c_i );
49
50     /// Return number of ticks in (ticks, division_1) representation
51     static int dur2ticks_i (Duration dur );
52         
53     /// Return the type_i representation of note length i
54     static int i2_type (int i);
55
56     /// Return the note length corresponding to the type_i representation
57     /// Return 0 if longer than whole note.
58     static int type2_i (int type);
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 duration from Moment (fraction of whole) representation.
73     static Duration mom2_dur (Moment mom );
74
75     /// Return standardised duration, best guess if not exact.
76     static Duration mom2standardised_dur (Moment mom );
77   
78     /// Return plet factor (not a Moment: should use Rational?).
79     static Moment plet_factor_mom (Duration dur );
80
81     static void set_array ();
82
83     /** Return synchronisation factor for mom, so that
84       mom2_dur (mom / sync_f ) will return the duration dur.            
85       */ 
86     static Real sync_f (Duration dur, Moment mom );
87
88     /// Return exact duration, in midi-ticks if not-exact.
89     static Duration ticks2_dur (int ticks_i );
90
91     /// Return standardised duration, best guess if not exact.
92     static Duration ticks2standardised_dur (int ticks_i );
93 };
94
95 /// (iter_dur)
96 struct Duration_iterator {
97     /// start at shortest: 128:2/3
98     Duration_iterator ();
99
100     // **** what about these three here ?
101     /// return forward_dur ();
102     Duration operator ++(int); 
103
104     /// return ok ()
105     operator bool (); 
106
107     /// return dur ()
108     Duration operator ()(); 
109     // ****
110
111     /// return current dur
112     Duration dur ();
113
114     /// return dur (), step to next
115     Duration forward_dur ();
116
117     /// durations left?
118     bool ok ();
119
120 private:
121     Duration cursor_dur_;
122 };
123
124
125 #endif // DURATION_CONVERT_HH