]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
patch::: 1.3.18.jcn3
[lilypond.git] / lily / bar-engraver.cc
1 /*
2   bar-engraver.cc -- implement Bar_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997, 1998, 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include "score-engraver.hh"
11 #include "bar-engraver.hh"
12 #include "staff-bar.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
20 ADD_THIS_TRANSLATOR (Bar_engraver);
21
22 Bar_engraver::Bar_engraver()
23 {
24   bar_p_ =0;
25   do_post_move_processing();
26 }
27
28
29
30
31 void
32 Bar_engraver::create_bar ()
33 {
34   if (!bar_p_)
35     {
36       bar_p_ = new Staff_bar;
37       bar_p_->set_elt_property ("break-aligned", SCM_BOOL_T);
38
39       // urg: "" != empty...
40       SCM default_type = get_property ("defaultBarType", 0);
41       if (gh_string_p (default_type))
42         {
43           bar_p_->set_elt_property ("default-glyph", default_type); // gu.h
44         }
45
46 #if 0
47       /*
48         urg.  Why did I implement this? And did I implement this so
49         clumsily?  */
50       SCM prop = get_property ("barAtLineStart", 0);
51       if (to_boolean (prop))
52         {
53           bar_p_->set_elt_property ("at-line-start", SCM_BOOL_T);
54         }
55 #endif
56       announce_element (Score_element_info (bar_p_, 0));
57     }
58 }
59
60 /**
61    Make a barline.  If there are both |: and :| requested, merge them
62    to :|:.
63
64 */
65 void
66 Bar_engraver::request_bar (String requested_type)
67 {
68   if (!now_mom ())
69     {
70       SCM prop = get_property ("barAtLineStart", 0);
71       if (!to_boolean (prop))
72         return;
73     }
74   bool  bar_existed = bar_p_;
75   create_bar ();
76   if (bar_existed && requested_type == "")
77     {
78       return;
79     }
80
81   String current = ly_scm2string (bar_p_->get_elt_property ("default-glyph"));
82   
83   if ((requested_type == "|:" && current== ":|")
84     || (requested_type == ":|" && current == "|:"))
85     requested_type = ":|:";
86
87   
88   bar_p_->set_elt_property ("default-glyph",
89                             ly_str02scm (requested_type.ch_C ()));
90 }
91
92 void 
93 Bar_engraver::do_creation_processing ()
94 {
95 }
96
97 void
98 Bar_engraver::do_removal_processing ()
99 {
100   if (bar_p_) 
101     {
102       typeset_element (bar_p_);
103       bar_p_ =0;
104     }
105 }
106
107 void
108 Bar_engraver::do_process_requests()
109 {  
110   Translator * t = daddy_grav_l  ()->get_simple_translator ("Timing_engraver");
111
112   Timing_engraver * te = dynamic_cast<Timing_engraver*>(t);
113   String which = (te) ? te->which_bar () : "";
114
115   if (which.length_i ())
116     {
117       create_bar();
118       bar_p_->set_elt_property ("default-glyph",  ly_str02scm (which.ch_C ()));
119     }
120   
121   if (!bar_p_)
122     {
123       Score_engraver * e = 0;
124       Translator * t  =  daddy_grav_l ();
125       for (; !e && t;  t = t->daddy_trans_l_)
126         {
127           e = dynamic_cast<Score_engraver*> (t);
128         }
129       
130       if (!e)
131         programming_error ("No score engraver!");
132       else
133         e->forbid_breaks ();
134     }
135 }
136
137
138 void 
139 Bar_engraver::do_pre_move_processing()
140 {
141   if (bar_p_) 
142     {
143       typeset_element (bar_p_);
144       bar_p_ =0;
145     }
146 }
147