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