]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
patch::: 1.3.54.hwn2
[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_->property_alist_ = get_property ("basicBarlineProperties");
33       
34       // urg: "" != empty...
35       /*
36         TODO: use symbol.
37        */
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       announce_element (Score_element_info (bar_p_, 0));
45     }
46 }
47
48 /**
49    Make a barline.  If there are both |: and :| requested, merge them
50    to :|:.
51
52 */
53 void
54 Bar_engraver::request_bar (String requested_type)
55 {
56   if (!now_mom ())
57     {
58       SCM prop = get_property ("barAtLineStart");
59       if (!to_boolean (prop))
60         return;
61     }
62   bool  bar_existed = bar_p_;
63   create_bar ();
64   if (bar_existed && requested_type == "")
65     {
66       return;
67     }
68
69   String current = ly_scm2string (bar_p_->get_elt_property ("glyph"));
70   
71   if ((requested_type == "|:" && current== ":|")
72     || (requested_type == ":|" && current == "|:"))
73     requested_type = ":|:";
74
75   
76   bar_p_->set_elt_property ("glyph",
77                             ly_str02scm (requested_type.ch_C ()));
78 }
79
80 void 
81 Bar_engraver::do_creation_processing ()
82 {
83 }
84
85 void
86 Bar_engraver::do_removal_processing ()
87 {
88   if (bar_p_) 
89     {
90       typeset_element (bar_p_);
91       bar_p_ =0;
92     }
93 }
94
95 void
96 Bar_engraver::do_process_music()
97 {  
98   Translator * t = daddy_grav_l  ()->get_simple_translator ("Timing_engraver");
99
100   Timing_engraver * te = dynamic_cast<Timing_engraver*>(t);
101   String which = (te) ? te->which_bar () : "";
102
103   if (which.length_i ())
104     {
105       create_bar();
106       bar_p_->set_elt_property ("glyph",  ly_str02scm (which.ch_C ()));
107     }
108   
109   if (!bar_p_)
110     {
111       Score_engraver * e = 0;
112       Translator * t  =  daddy_grav_l ();
113       for (; !e && t;  t = t->daddy_trans_l_)
114         {
115           e = dynamic_cast<Score_engraver*> (t);
116         }
117       
118       if (!e)
119         programming_error ("No score engraver!");
120       else
121         e->forbid_breaks ();
122     }
123 }
124
125
126 void 
127 Bar_engraver::do_pre_move_processing()
128 {
129   if (bar_p_) 
130     {
131       typeset_element (bar_p_);
132       bar_p_ =0;
133     }
134 }
135
136 ADD_THIS_TRANSLATOR(Bar_engraver);
137
138
139