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