]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/drul-array.hh
2003 -> 2004
[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--2004 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 #include <assert.h>
17
18 /**
19   Left/right or Up/down arrays. Drul is nicer sounding than udlr
20  */
21 template<class T>
22 struct Drul_array
23 {
24   T array_[2];
25   T &elem (Direction d)
26     {
27       assert (d==1 || d== -1);
28       return array_[ (d+1)/2];
29
30     }
31   T &operator[] (Direction d)
32   {
33     return elem (d);
34   }
35   T elem (Direction d) const
36     {
37     assert (d==1 || d== -1);
38     return array_[ (d+1)/2];
39     }
40   
41   T operator[] (Direction d) const
42   {
43     return elem (d);
44   }
45   Drul_array ()
46     {}
47   Drul_array (T t1, T 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->elem (LEFT) *= x;
59   dr->elem (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.elem (LEFT))  + (x + 1.0) * Real (d.elem (RIGHT))) * 0.5;
66 }
67
68 #endif // DRUL_ARRAY_HH