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