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