lilypond-1.5.33
[lilypond.git] / lib / duration-iter.cc
blobabb467d1c1fad5dea73d44e73117c570ee2f28a1
1 /*
2 duration-convert.cc -- implement Duration_convert
4 source file of the LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9 #include <assert.h>
10 #include "duration-convert.hh"
11 #include "warn.hh"
12 #include "duration-iter.hh"
14 Duration_iterator::Duration_iterator ()
16 cursor_dur_.durlog_i_ = 7;
17 if (Duration_convert::no_smaller_than_i_s)
18 cursor_dur_.durlog_i_ = Duration_convert::no_smaller_than_i_s;
21 Duration
22 Duration_iterator::operator ++(int)
24 return forward_dur ();
27 Duration
28 Duration_iterator::operator ()()
30 return dur ();
33 Duration_iterator::operator bool ()
35 return ok ();
38 Duration
39 Duration_iterator::dur ()
41 return cursor_dur_;
44 Duration
45 Duration_iterator::forward_dur ()
47 /* should do smart table? guessing:
48 duration wholes
49 16 0.0625
50 32.. 0.0703
51 8:2/3 0.0833
52 16. 0.0938
53 8 0.1250
54 16.. 0.1406
55 4:2/3 0.1667
56 8. 0.1875
59 assert (ok ());
61 Duration dur = cursor_dur_;
63 if (!cursor_dur_.dots_i_ && !cursor_dur_.plet_b ())
65 cursor_dur_.durlog_i_ += 1;
66 cursor_dur_.dots_i_ = 2;
68 else if (cursor_dur_.dots_i_ == 2)
70 assert (!cursor_dur_.plet_b ());
71 cursor_dur_.dots_i_ = 0;
72 cursor_dur_.durlog_i_ -=2;
73 cursor_dur_.set_plet (2, 3);
75 else if (cursor_dur_.plet_b ()
76 && (cursor_dur_.plet_.iso_i_ == 2)
77 && (cursor_dur_.plet_.type_i_ == 3))
79 assert (!cursor_dur_.dots_i_);
80 cursor_dur_.set_plet (1, 1);
81 cursor_dur_.durlog_i_ += 1;
82 cursor_dur_.dots_i_ = 1;
84 else if (cursor_dur_.dots_i_ == 1)
86 assert (!cursor_dur_.plet_b ());
87 cursor_dur_.dots_i_ = 0;
88 cursor_dur_.durlog_i_ -= 1;
91 if (Duration_convert::no_triplets_b_s
92 && cursor_dur_.plet_b () && ok ())
93 forward_dur ();
94 if (Duration_convert::no_double_dots_b_s
95 && (cursor_dur_.dots_i_ == 2) && ok ())
96 forward_dur ();
97 if (Duration_convert::no_smaller_than_i_s
98 && (cursor_dur_.durlog_i_ > Duration_convert::no_smaller_than_i_s) && ok ())
99 forward_dur ();
100 if (Duration_convert::no_smaller_than_i_s
101 && cursor_dur_.dots_i_
102 && (cursor_dur_.durlog_i_ >= Duration_convert::no_smaller_than_i_s)
103 && ok ())
104 forward_dur ();
105 if (Duration_convert::no_smaller_than_i_s
106 && (cursor_dur_.dots_i_ == 2)
107 && (cursor_dur_.durlog_i_ >= Duration_convert::no_smaller_than_i_s / 2)
108 && ok ())
109 forward_dur ();
111 return dur;
114 bool
115 Duration_iterator::ok ()
117 return cursor_dur_.length_mom () <= Rational (4);