]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/drul-array.hh
47c4847c4048825f0d65904a0431a2e861779410
[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--2007 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 &at (Direction d)
23   {
24     assert (d == 1 || d == -1);
25     return array_[ (d + 1) / 2];
26   }
27   T const &at (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 at (d);
35   }
36   T const& operator [] (Direction d) const
37   {
38     return at (d);
39   }
40   Drul_array ()
41   {
42   }
43   Drul_array (T const &t1, T const &t2)
44   {
45     set (t1, t2);
46   }
47   void set (T const &t1, T const &t2)
48   {
49     array_[0] = t1;
50     array_[1] = t2;
51   }
52 };
53
54 template<class T>
55 void
56 scale_drul (Drul_array<T> *dr, T x)
57 {
58   dr->at (LEFT) *= x;
59   dr->at (RIGHT) *= x;
60 }
61
62 inline Real
63 linear_combination (Drul_array<Real> const &d, Real x)
64 {
65   return ((1.0 - x) * Real (d.at (LEFT))
66           + (x + 1.0) * Real (d.at (RIGHT))) * 0.5;
67 }
68
69 #endif /* DRUL_ARRAY_HH */