]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
Merge branch 'lilypond/translation' of ssh://git.sv.gnu.org/srv/git/lilypond into...
[lilypond.git] / lily / bar-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
5   Jan Nieuwenhuizen <janneke@gnu.org>
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "bar-line.hh"
22 #include "context.hh"
23 #include "score-engraver.hh"
24 #include "warn.hh"
25 #include "item.hh"
26 #include "spanner.hh"
27
28 #include "translator.icc"
29
30 /*
31   generate bars. Either user ("|:"), or default (new measure)
32 */
33 class Bar_engraver : public Engraver
34 {
35 public:
36   TRANSLATOR_DECLARATIONS (Bar_engraver);
37   void request_bar (string type_string);
38
39 protected:
40   void stop_translation_timestep ();
41   void process_acknowledged ();
42
43   DECLARE_END_ACKNOWLEDGER (spanner);
44
45 private:
46   void create_bar ();
47
48   Item *bar_;
49   vector<Spanner*> spanners_;
50 };
51
52 Bar_engraver::Bar_engraver ()
53 {
54   bar_ = 0;
55 }
56
57 void
58 Bar_engraver::create_bar ()
59 {
60   if (!bar_)
61     {
62       bar_ = make_item ("BarLine", SCM_EOL);
63       SCM gl = get_property ("whichBar");
64       if (scm_equal_p (gl, bar_->get_property ("glyph")) != SCM_BOOL_T)
65         bar_->set_property ("glyph", gl);
66     }
67 }
68
69 /*
70   Bar_engraver should come *after* any engravers that
71   modify whichBar
72
73   This is a little hairy : whichBar may be set by
74   Repeat_acknowledge_engraver::process_music, which is at score
75   context. This means that grobs could should be created after
76   process_music. We do stuff process_acknowledged (), just to be
77   on the safe side.
78 */
79
80 void
81 Bar_engraver::process_acknowledged ()
82 {
83   if (!bar_ && scm_is_string (get_property ("whichBar")))
84     create_bar ();
85
86   if (bar_)
87     for (vsize i = 0; i < spanners_.size (); i++)
88       spanners_[i]->set_bound (RIGHT, bar_);
89 }
90
91 /*
92   lines may only be broken if there is a barline in all staves
93 */
94 void
95 Bar_engraver::stop_translation_timestep ()
96 {
97   if (!bar_)
98     context ()->get_score_context ()->set_property ("forbidBreak", SCM_BOOL_T);
99
100   bar_ = 0;
101   spanners_.clear ();
102 }
103
104 void
105 Bar_engraver::acknowledge_end_spanner (Grob_info gi)
106 {
107   Grob *g = gi.grob ();
108
109   if (to_boolean (g->get_property ("to-barline")))
110     spanners_.push_back (dynamic_cast<Spanner*> (g));
111 }
112
113 ADD_END_ACKNOWLEDGER (Bar_engraver, spanner);
114
115 ADD_TRANSLATOR (Bar_engraver,
116                 /* doc */
117                 "Create barlines.  This engraver is controlled through the"
118                 " @code{whichBar} property.  If it has no bar line to create,"
119                 " it will forbid a linebreak at this point.",
120
121                 /* create */
122                 "BarLine ",
123
124                 /* read */
125                 "whichBar ",
126
127                 /* write */
128                 "forbidBreak "
129                 );