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