lilypond-1.3.69
[lilypond.git] / lily / bar-engraver.cc
blob3451841d663c42de5537a248c35bedb481ff5906
1 /*
2 bar-engraver.cc -- implement Bar_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
10 #include "bar.hh"
11 #include "score-engraver.hh"
12 #include "bar-engraver.hh"
13 #include "musical-request.hh"
14 #include "multi-measure-rest.hh"
15 #include "command-request.hh"
16 #include "timing-engraver.hh"
17 #include "engraver-group-engraver.hh"
18 #include "warn.hh"
19 #include "item.hh"
21 Bar_engraver::Bar_engraver()
23 bar_p_ =0;
24 do_post_move_processing();
27 void
28 Bar_engraver::create_bar ()
30 if (!bar_p_)
32 bar_p_ = new Item (get_property ("basicBarProperties"));
34 SCM default_type = get_property ("defaultBarType");
35 if (gh_string_p (default_type))
37 bar_p_->set_elt_property ("glyph", default_type); // ugh
40 announce_element (Score_element_info (bar_p_, 0));
44 /**
45 Make a barline. If there are both |: and :| requested, merge them
46 to :|:.
48 void
49 Bar_engraver::request_bar (String requested_type)
51 if (!now_mom ())
53 SCM prop = get_property ("barAtLineStart");
54 if (!to_boolean (prop))
55 return;
57 bool bar_existed = bar_p_;
58 create_bar ();
59 if (bar_existed && requested_type == "")
61 return;
64 String current = ly_scm2string (bar_p_->get_elt_property ("glyph"));
66 if ((requested_type == "|:" && current== ":|")
67 || (requested_type == ":|" && current == "|:"))
68 requested_type = ":|:";
71 bar_p_->set_elt_property ("glyph",
72 ly_str02scm (requested_type.ch_C ()));
75 void
76 Bar_engraver::do_creation_processing ()
80 void
81 Bar_engraver::do_removal_processing ()
83 if (bar_p_)
85 typeset_element (bar_p_);
86 bar_p_ =0;
90 void
91 Bar_engraver::do_process_music()
93 Translator * t = daddy_grav_l ()->get_simple_translator ("Timing_engraver");
95 Timing_engraver * te = dynamic_cast<Timing_engraver*>(t);
96 String which = (te) ? te->which_bar () : "";
98 if (which.length_i ())
100 create_bar();
101 bar_p_->set_elt_property ("glyph", ly_str02scm (which.ch_C ()));
104 if (!bar_p_)
106 Score_engraver * e = 0;
107 Translator * t = daddy_grav_l ();
108 for (; !e && t; t = t->daddy_trans_l_)
110 e = dynamic_cast<Score_engraver*> (t);
113 if (!e)
114 programming_error ("No score engraver!");
115 else
116 e->forbid_breaks ();
121 void
122 Bar_engraver::do_pre_move_processing()
124 if (bar_p_)
126 typeset_element (bar_p_);
127 bar_p_ =0;
131 ADD_THIS_TRANSLATOR(Bar_engraver);