]> git.donarmstrong.com Git - lilypond.git/blob - lily/relative-octave-check.cc
* scm/music-functions.scm (has-request-chord): don't use
[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 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 */
9
10 #include "music.hh"
11 #include "input.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
21 MAKE_SCHEME_CALLBACK(Relative_octave_check, relative_callback, 2)
22 SCM
23 Relative_octave_check::relative_callback (SCM music, SCM last_pitch)
24 {
25   Pitch p = *unsmob_pitch (last_pitch);
26   Music *m = unsmob_music (music); 
27   Pitch *check_p = unsmob_pitch (m->get_property ("pitch"));
28   
29   int delta_oct = 0;
30   if (check_p)
31     {
32       Pitch no_octave (-1,
33                        check_p->get_notename (),
34                        check_p->get_alteration ());
35
36       Pitch result = no_octave.to_relative_octave (p);
37
38       if (result != *check_p)
39         {
40           String s = _("Failed octave check, got: ");
41           s += result.to_string ();
42           
43           m->origin ()->warning (s);
44           
45           delta_oct = check_p->get_octave () - result.get_octave ();
46         }
47     }
48   
49   return Pitch (p.get_octave () + delta_oct,
50                 p.get_notename (), p.get_alteration ()).smobbed_copy ();
51 }