]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/misc.hh
206e74e3eae5da6de3ad169041ea8a72128103ba
[lilypond.git] / lily / include / misc.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2015 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 MISC_HH
21 #define MISC_HH
22
23 #include <cstdlib>
24
25 #include "std-vector.hh"
26 #include "interval.hh"
27
28 double log_2 (double x);
29 int intlog2 (int d);
30
31 inline int
32 sign (int i)
33 {
34   if (i < 0)
35     return -1;
36   else if (i)
37     return 1;
38   else return 0;
39 }
40
41 inline int
42 shift_left (int value, int shiftamount)
43 {
44   if (shiftamount < 0) return (value >> -shiftamount);
45   else return (value << shiftamount);
46 }
47
48 inline Real
49 linear_interpolate (Real x, Real x1, Real x2, Real y1, Real y2)
50 {
51   return (x2 - x) / (x2 - x1) * y1
52          + (x - x1) / (x2 - x1) * y2;
53 }
54
55 inline Real
56 normalize (Real x, Real x1, Real x2)
57 {
58   return (x - x1) / (x2 - x1);
59 }
60
61 Real directed_round (Real f, Direction d);
62
63 Real peak_around (Real epsilon, Real threshold, Real x);
64 Real convex_amplifier (Real standard_x, Real increase_factor, Real x);
65 std::string camel_case_to_lisp_identifier (const std::string &in);
66
67 #endif
68