]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-check-iterator.cc
46479892ef67e5e8c1ae52221970db058dc1ccc6
[lilypond.git] / lily / bar-check-iterator.cc
1 /*
2   bar-check-iterator.cc -- implement Bar_check_iterator
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2001--2005  Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "simple-music-iterator.hh"
10 #include "event.hh"
11 #include "context.hh"
12
13 /*
14   Check bar checks. We do this outside the engravers so that you can
15   race through the score using skipTypesetting to correct durations.
16 */
17 class Bar_check_iterator : Simple_music_iterator
18 {
19 public:
20   virtual void process (Moment);
21   Bar_check_iterator ();
22   DECLARE_SCHEME_CALLBACK (constructor, ());
23 };
24
25 IMPLEMENT_CTOR_CALLBACK (Bar_check_iterator);
26
27 Bar_check_iterator::Bar_check_iterator ()
28 {
29 }
30
31 void
32 Bar_check_iterator::process (Moment m)
33 {
34   Simple_music_iterator::process (m);
35   if (!m.to_bool ())
36     {
37       Context *tr = get_outlet ();
38
39       SCM check = tr->get_property ("ignoreBarChecks");
40       if (to_boolean (check))
41         return;
42       
43       SCM mp = tr->get_property ("measurePosition");
44       SCM sync = tr->get_property ("barCheckSynchronize");
45
46       Moment *where = unsmob_moment (mp);
47       if (!where)
48         return;
49
50       if (where->main_part_)
51         {
52           bool warn = true;
53           if (to_boolean (sync))
54             {
55               tr = tr->where_defined (ly_symbol2scm ("measurePosition"));
56               Moment zero;
57               tr->set_property ("measurePosition", zero.smobbed_copy ());
58             }
59           else
60             {
61               SCM lf = tr->get_property ("barCheckLastFail");
62               if (unsmob_moment (lf)
63                   && *unsmob_moment (lf) == *where)
64                 warn = false;
65               else
66                 tr->set_property ("barCheckLastFail", mp);
67             }
68
69           if (warn)
70             get_music ()->origin ()->warning (_f ("barcheck failed at: %s",
71                                                   where->to_string ()));
72         }
73     }
74 }