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