]> git.donarmstrong.com Git - lilypond.git/blob - lib/duration-iter.cc
9472c0217d512044927fc81587f43a78768e85b3
[lilypond.git] / lib / duration-iter.cc
1 /*
2   duration-convert.cc -- implement Duration_convert
3
4   source file of the LilyPond music typesetter
5
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"
13
14 Duration_iterator::Duration_iterator ()
15 {
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;
19 }
20
21 Duration 
22 Duration_iterator::operator ++(int)
23 {
24   return forward_dur ();
25 }
26
27 Duration
28 Duration_iterator::operator ()()
29 {
30   return dur ();
31 }
32
33 Duration_iterator::operator bool ()
34 {
35   return ok ();
36 }
37
38 Duration
39 Duration_iterator::dur ()
40 {
41   return cursor_dur_;
42 }
43
44 Duration
45 Duration_iterator::forward_dur ()
46 {
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
57                 
58      */
59   assert (ok ());
60
61   Duration dur = cursor_dur_;
62
63   if (!cursor_dur_.dots_i_ && !cursor_dur_.plet_b ()) 
64     {
65       cursor_dur_.durlog_i_ += 1;
66       cursor_dur_.dots_i_ = 2;
67     }
68   else if (cursor_dur_.dots_i_ == 2) 
69     {
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);
74     }
75   else if (cursor_dur_.plet_b () 
76            && (cursor_dur_.plet_.iso_i_ == 2)
77            && (cursor_dur_.plet_.type_i_ == 3)) 
78     {
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;
83     }
84   else if (cursor_dur_.dots_i_ == 1) 
85     {
86       assert (!cursor_dur_.plet_b ());
87       cursor_dur_.dots_i_ = 0;
88       cursor_dur_.durlog_i_ -= 1;
89     }
90                 
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 ();
110
111   return dur;
112 }
113
114 bool
115 Duration_iterator::ok ()
116 {
117   return cursor_dur_.length_mom () <= Moment (4);
118 }