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