]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/drul-array.hh
Run grand-replace (issue 3765)
[lilypond.git] / flower / include / drul-array.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef DRUL_ARRAY_HH
21 #define DRUL_ARRAY_HH
22
23 #include "direction.hh"
24 #include "real.hh"
25
26 /**
27    Left/right or Up/down arrays. Drul is nicer sounding than udlr
28 */
29 template<class T>
30 struct Drul_array
31 {
32   T array_[2];
33   T &at (Direction d)
34   {
35     assert (d == 1 || d == -1);
36     return array_[ (d + 1) / 2];
37   }
38   T const &at (Direction d) const
39   {
40     assert (d == 1 || d == -1);
41     return array_[ (d + 1) / 2];
42   }
43   T &operator [] (Direction d)
44   {
45     return at (d);
46   }
47   T const &operator [] (Direction d) const
48   {
49     return at (d);
50   }
51   Drul_array ()
52   {
53   }
54   Drul_array (T const &t1, T const &t2)
55   {
56     set (t1, t2);
57   }
58   void set (T const &t1, T const &t2)
59   {
60     array_[0] = t1;
61     array_[1] = t2;
62   }
63 };
64
65 template<class T>
66 void
67 scale_drul (Drul_array<T> *dr, T x)
68 {
69   dr->at (LEFT) *= x;
70   dr->at (RIGHT) *= x;
71 }
72
73 inline Real
74 linear_combination (Drul_array<Real> const &d, Real x)
75 {
76   return ((1.0 - x) * Real (d.at (LEFT))
77           + (x + 1.0) * Real (d.at (RIGHT))) * 0.5;
78 }
79
80 #endif /* DRUL_ARRAY_HH */