2 misc.cc -- implement various stuff
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
15 Return the 2-log, rounded down
35 return log (x) / log (2.0);
39 directed_round (Real f, Direction d)
50 0 at threshold, 1 at 0, with 1/x falloff.
53 peak_around (Real epsilon, Real threshold, Real x)
57 return max (- epsilon * (x - threshold) / ((x + epsilon) * threshold), 0.0);
61 0 at 0, 1 at standard_x, and increasing thereafter.
64 convex_amplifier (Real standard_x, Real increase_factor, Real x)
66 return (exp (increase_factor * x / standard_x) - 1.0) / (exp (increase_factor) - 1.0);
70 camel_case_to_lisp_identifier (string in)
74 /* don't add '-' before first character */
75 out.push_back (char (tolower (in[0])));
77 for (size_t inpos = 1; inpos < in.size (); inpos++)
79 if (isupper (in[inpos]))
81 out.push_back ( char(tolower (in[inpos])));
84 string result (&out[0], out.size ());
85 replace_all (&result, '_', '-');
91 utf8_char_len (char current)
96 if ((current & 0xF0) == 0xF0)
99 else if ((current & 0xE0) == 0xE0)
102 else if ((current & 0xC0) == 0xC0)
104 else if (current & 0x80)
105 programming_error ("invalid UTF-8 string");