]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/drul-array.hh
*** empty log message ***
[lilypond.git] / flower / include / drul-array.hh
1 /*
2   drul-array.hh -- declare Drul_array
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #ifndef DRUL_ARRAY_HH
10 #define DRUL_ARRAY_HH
11
12 #include "direction.hh"
13 #include "real.hh"
14
15 /**
16    Left/right or Up/down arrays. Drul is nicer sounding than udlr
17 */
18 template<class T>
19 struct Drul_array
20 {
21   T array_[2];
22   T &elem_ref (Direction d)
23   {
24     assert (d == 1 || d == -1);
25     return array_[ (d + 1) / 2];
26   }
27   T elem (Direction d) const
28   {
29     assert (d == 1 || d == -1);
30     return array_[ (d + 1) / 2];
31   }
32   T &operator [] (Direction d)
33   {
34     return elem_ref (d);
35   }
36   T operator [] (Direction d) const
37   {
38     return elem (d);
39   }
40   Drul_array ()
41   {
42   }
43   Drul_array (T t1, T t2)
44   {
45     array_[0] = t1;
46     array_[1] = t2;
47   }
48 };
49
50 template<class T>
51 void
52 scale_drul (Drul_array<T> *dr, T x)
53 {
54   dr->elem_ref (LEFT) *= x;
55   dr->elem_ref (RIGHT) *= x;
56 }
57
58 inline Real
59 linear_combination (Drul_array<Real> const &d, Real x)
60 {
61   return ((1.0 - x) * Real (d.elem (LEFT))
62           + (x + 1.0) * Real (d.elem (RIGHT))) * 0.5;
63 }
64
65 #endif /* DRUL_ARRAY_HH */