]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
Web-ja: update introduction
[lilypond.git] / lily / bar-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2015 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 "context.hh"
22 #include "score-engraver.hh"
23 #include "warn.hh"
24 #include "item.hh"
25 #include "spanner.hh"
26
27 #include "translator.icc"
28
29 /*
30   generate bars. Either user ("|:"), or default (new measure)
31 */
32 class Bar_engraver : public Engraver
33 {
34 public:
35   TRANSLATOR_DECLARATIONS (Bar_engraver);
36
37 protected:
38   void stop_translation_timestep ();
39   void process_acknowledged ();
40
41   void acknowledge_end_spanner (Grob_info);
42
43 private:
44   void create_bar ();
45
46   Item *bar_;
47   vector<Spanner *> spanners_;
48 };
49
50 Bar_engraver::Bar_engraver (Context *c)
51   : Engraver (c)
52 {
53   bar_ = 0;
54 }
55
56 void
57 Bar_engraver::create_bar ()
58 {
59   if (!bar_)
60     {
61       bar_ = make_item ("BarLine", SCM_EOL);
62       SCM gl = get_property ("whichBar");
63       if (!ly_is_equal (gl, bar_->get_property ("glyph")))
64         bar_->set_property ("glyph", gl);
65     }
66 }
67
68 /*
69   Bar_engraver should come *after* any engravers that
70   modify whichBar
71
72   This is a little hairy : whichBar may be set by
73   Repeat_acknowledge_engraver::process_music, which is at score
74   context. This means that grobs could should be created after
75   process_music. We do stuff process_acknowledged (), just to be
76   on the safe side.
77 */
78
79 void
80 Bar_engraver::process_acknowledged ()
81 {
82   if (!bar_ && scm_is_string (get_property ("whichBar")))
83     create_bar ();
84
85   if (bar_)
86     for (vsize i = 0; i < spanners_.size (); i++)
87       spanners_[i]->set_bound (RIGHT, bar_);
88 }
89
90 /*
91   lines may only be broken if there is a barline in all staves
92 */
93 void
94 Bar_engraver::stop_translation_timestep ()
95 {
96   if (!bar_)
97     context ()->get_score_context ()->set_property ("forbidBreak", SCM_BOOL_T);
98
99   bar_ = 0;
100   spanners_.clear ();
101 }
102
103 void
104 Bar_engraver::acknowledge_end_spanner (Grob_info gi)
105 {
106   Grob *g = gi.grob ();
107
108   if (to_boolean (g->get_property ("to-barline")))
109     spanners_.push_back (dynamic_cast<Spanner *> (g));
110 }
111
112
113 void
114 Bar_engraver::boot ()
115 {
116   ADD_END_ACKNOWLEDGER (Bar_engraver, spanner);
117 }
118
119 ADD_TRANSLATOR (Bar_engraver,
120                 /* doc */
121                 "Create barlines.  This engraver is controlled through the"
122                 " @code{whichBar} property.  If it has no bar line to create,"
123                 " it will forbid a linebreak at this point.  This engraver"
124                 " is required to trigger the creation of clefs at the start"
125                 " of systems.",
126
127                 /* create */
128                 "BarLine ",
129
130                 /* read */
131                 "whichBar ",
132
133                 /* write */
134                 "forbidBreak "
135                );