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