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