]> git.donarmstrong.com Git - lilypond.git/blob - midi2ly/duration-iter.cc
patch::: 1.3.79.jcn1
[lilypond.git] / midi2ly / duration-iter.cc
1 /*
2   duration-convert.cc -- implement Duration_convert
3
4   source file of the LilyPond music typesetter
5
6   (c)  1997--2000 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::dur ()
29 {
30   return cursor_dur_;
31 }
32
33 Duration
34 Duration_iterator::forward_dur ()
35 {
36   /* should do smart table? guessing: 
37      duration wholes
38      16         0.0625
39      32..       0.0703
40      8:2/3      0.0833
41      16.        0.0938
42      8  0.1250
43      16..       0.1406
44      4:2/3      0.1667
45      8. 0.1875
46                 
47      */
48   assert (ok ());
49
50   Duration dur = this->dur ();
51
52   if (!cursor_dur_.dots_i_ && !cursor_dur_.plet_b ()) 
53     {
54       cursor_dur_.durlog_i_ += 1;
55       cursor_dur_.dots_i_ = 2;
56     }
57   else if (cursor_dur_.dots_i_ == 2) 
58     {
59       assert (!cursor_dur_.plet_b ());
60       cursor_dur_.dots_i_ = 0;
61       cursor_dur_.durlog_i_ -=2;
62       cursor_dur_.set_plet (2, 3);
63     }
64   else if (cursor_dur_.plet_b () 
65            && (cursor_dur_.plet_.iso_i_ == 2)
66            && (cursor_dur_.plet_.type_i_ == 3)) 
67     {
68       assert (!cursor_dur_.dots_i_);
69       cursor_dur_.set_plet (1, 1);
70       cursor_dur_.durlog_i_ += 1;
71       cursor_dur_.dots_i_ = 1;
72     }
73   else if (cursor_dur_.dots_i_ == 1) 
74     {
75       assert (!cursor_dur_.plet_b ());
76       cursor_dur_.dots_i_ = 0;
77       cursor_dur_.durlog_i_ -= 1;
78     }
79                 
80   if (Duration_convert::no_tuplets_b_s
81       && cursor_dur_.plet_b () && ok ())
82     forward_dur ();
83   if (Duration_convert::no_double_dots_b_s 
84       && (cursor_dur_.dots_i_ == 2) && ok ())
85     forward_dur ();
86   if (Duration_convert::no_smaller_than_i_s
87       && (cursor_dur_.durlog_i_ > Duration_convert::no_smaller_than_i_s) && ok ())
88     forward_dur ();
89   if (Duration_convert::no_smaller_than_i_s
90       && cursor_dur_.dots_i_
91       && (cursor_dur_.durlog_i_ >= Duration_convert::no_smaller_than_i_s)
92       && ok ())
93     forward_dur ();
94   if (Duration_convert::no_smaller_than_i_s
95       && (cursor_dur_.dots_i_ == 2)
96       && (cursor_dur_.durlog_i_ >= Duration_convert::no_smaller_than_i_s / 2)
97       && ok ())
98     forward_dur ();
99
100   return dur;
101 }
102
103 bool
104 Duration_iterator::ok ()
105 {
106   return cursor_dur_.length_mom () <= Rational (4);
107 }