]> git.donarmstrong.com Git - lilypond.git/blob - lily/spanner-break-forbid-engraver.cc
Merge branch 'lilypond/translation' of ssh://git.sv.gnu.org/srv/git/lilypond into...
[lilypond.git] / lily / spanner-break-forbid-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2007--2010 Han-Wen Nienhuys <hanwen@lilypond.org>
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
21
22 #include "engraver.hh"
23 #include "international.hh"
24 #include "spanner.hh"
25 #include "stream-event.hh"
26 #include "warn.hh"
27 #include "context.hh"
28
29 #include "translator.icc"
30
31 class Spanner_break_forbid_engraver : public Engraver
32 {
33   TRANSLATOR_DECLARATIONS (Spanner_break_forbid_engraver);
34   vector<Spanner*> running_spanners_;
35 protected:
36   DECLARE_ACKNOWLEDGER (unbreakable_spanner);
37   DECLARE_END_ACKNOWLEDGER (unbreakable_spanner);
38
39   void process_music ();
40 };
41
42
43 void
44 Spanner_break_forbid_engraver::process_music ()
45 {
46   if (running_spanners_.size ())
47     {
48       context ()->get_score_context ()->set_property ("forbidBreak", SCM_BOOL_T);
49     }
50 }
51
52 void
53 Spanner_break_forbid_engraver::acknowledge_end_unbreakable_spanner (Grob_info gi)
54 {
55   vector<Spanner*>::iterator i = find (running_spanners_.begin (), running_spanners_.end (),
56                                        gi.spanner ());
57   if (i != running_spanners_.end ())
58     running_spanners_.erase (i);
59 }
60
61 void
62 Spanner_break_forbid_engraver::acknowledge_unbreakable_spanner (Grob_info gi)
63 {
64   if (!to_boolean (gi.grob ()->get_property ("breakable")))
65     running_spanners_.push_back (gi.spanner ());
66 }
67
68 Spanner_break_forbid_engraver::Spanner_break_forbid_engraver ()
69 {
70 }
71
72
73 ADD_END_ACKNOWLEDGER (Spanner_break_forbid_engraver, unbreakable_spanner);
74 ADD_ACKNOWLEDGER (Spanner_break_forbid_engraver, unbreakable_spanner);
75 ADD_TRANSLATOR (Spanner_break_forbid_engraver,
76                 /* doc */
77                 "Forbid breaks in certain spanners.",
78
79                 /* create */
80                 "",
81
82                 /* read */
83                 "",
84
85                 /* write */
86                 ""
87                 );