]> git.donarmstrong.com Git - lilypond.git/blob - lily/relative-octave-check.cc
Merge with git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond.git
[lilypond.git] / lily / relative-octave-check.cc
1 /*
2   relative-octave-check.cc -- implement Relative_octave_check
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "input.hh"
10 #include "international.hh"
11 #include "music.hh"
12 #include "pitch.hh"
13
14 class Relative_octave_check
15 {
16 public:
17   DECLARE_SCHEME_CALLBACK (relative_callback, (SCM, SCM));
18 };
19
20 MAKE_SCHEME_CALLBACK (Relative_octave_check, relative_callback, 2)
21   SCM
22 Relative_octave_check::relative_callback (SCM music, SCM last_pitch)
23 {
24   Pitch p = *unsmob_pitch (last_pitch);
25   Music *m = unsmob_music (music);
26   Pitch *check_p = unsmob_pitch (m->get_property ("pitch"));
27
28   int delta_oct = 0;
29   if (check_p)
30     {
31       Pitch no_octave (-1,
32                        check_p->get_notename (),
33                        check_p->get_alteration ());
34
35       Pitch result = no_octave.to_relative_octave (p);
36
37       if (result != *check_p)
38         {
39           string s = _ ("Failed octave check, got: ");
40           s += result.to_string ();
41
42           m->origin ()->warning (s);
43
44           delta_oct = check_p->get_octave () - result.get_octave ();
45         }
46     }
47
48   return Pitch (p.get_octave () + delta_oct,
49                 p.get_notename (), p.get_alteration ()).smobbed_copy ();
50 }