]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-check-iterator.cc
e4d26f8a1a3db33a2f359c9d196c517a361e1a02
[lilypond.git] / lily / bar-check-iterator.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2001--2014  Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "context.hh"
21 #include "input.hh"
22 #include "international.hh"
23 #include "music.hh"
24 #include "simple-music-iterator.hh"
25
26 /*
27   Check bar checks. We do this outside the engravers so that you can
28   race through the score using skipTypesetting to correct durations.
29 */
30 class Bar_check_iterator : Simple_music_iterator
31 {
32 public:
33   virtual void process (Moment);
34   Bar_check_iterator ();
35   DECLARE_SCHEME_CALLBACK (constructor, ());
36 };
37
38 IMPLEMENT_CTOR_CALLBACK (Bar_check_iterator);
39
40 Bar_check_iterator::Bar_check_iterator ()
41 {
42 }
43
44 void
45 Bar_check_iterator::process (Moment m)
46 {
47   Simple_music_iterator::process (m);
48   if (!m.to_bool ())
49     {
50       Context *tr = get_outlet ();
51
52       SCM check = tr->get_property ("ignoreBarChecks");
53       if (to_boolean (check))
54         return;
55
56       SCM mp = tr->get_property ("measurePosition");
57       SCM sync = tr->get_property ("barCheckSynchronize");
58
59       Moment *where = unsmob_moment (mp);
60       if (!where)
61         return;
62
63       if (where->main_part_)
64         {
65           bool warn = true;
66           if (to_boolean (sync))
67             {
68               SCM mp;
69               tr = tr->where_defined (ly_symbol2scm ("measurePosition"), &mp);
70               Moment zero;
71               tr->set_property ("measurePosition", zero.smobbed_copy ());
72             }
73           else
74             {
75               SCM lf = tr->get_property ("barCheckLastFail");
76               if (unsmob_moment (lf)
77                   && *unsmob_moment (lf) == *where)
78                 warn = false;
79               else
80                 tr->set_property ("barCheckLastFail", mp);
81             }
82
83           if (warn)
84             get_music ()->origin ()->warning (_f ("barcheck failed at: %s",
85                                                   where->to_string ()));
86         }
87     }
88 }