]> git.donarmstrong.com Git - lilypond.git/blob - lily/misc.cc
* lily/include/midi-item.hh (class Midi_track): idem.
[lilypond.git] / lily / misc.cc
1 /*
2   misc.cc -- implement various stuff
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10
11 #include "misc.hh"
12 #include "std-string.hh"
13
14 /*
15   Return the 2-log, rounded down
16 */
17 int
18 intlog2 (int d)
19 {
20   assert (d);
21   int i = 0;
22   while ((d != 1))
23     {
24       d /= 2;
25       i++;
26     }
27
28   assert (! (d / 2));
29   return i;
30 }
31
32 double
33 log_2 (double x)
34 {
35   return log (x) / log (2.0);
36 }
37
38 vector<string>
39 split_string (string str, char c)
40 {
41   vector<string> a;
42   ssize i = str.find (c);
43   while (i != NPOS)
44     {
45       string s = str.substr (0, i);
46       a.push_back (s);
47       while (str[++i] == c)
48         ;
49       str = str.substr (i);
50       i = str.find (c);
51     }
52   if (str.length ())
53     a.push_back (str);
54   return a;
55 }
56
57 #if 0
58 vector<string>
59 split_string (string s, char c)
60 {
61   vector<string> rv;
62   while (s.length ())
63     {
64       ssize i = s.find (c);
65
66       if (i == 0)
67         {
68           s = s.substr (1, s.length () -1);
69           continue;
70         }
71
72       if (i == NPOS)
73         i = s.length ();
74
75       rv.push_back (s.substr (0, i));
76       s = s.substr (i, s.length () - i);
77     }
78
79   return rv;
80 }
81 #endif
82
83
84 Real
85 directed_round (Real f, Direction d)
86 {
87   if (d < 0)
88     return floor (f);
89   else
90     return ceil (f);
91 }
92