]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol-engraver.cc
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / lily / staff-symbol-engraver.cc
1 /*
2   staff-symbol-engraver.cc -- implement Staff_symbol_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "staff-symbol-engraver.hh"
10 #include "spanner.hh"
11
12 Staff_symbol_engraver::~Staff_symbol_engraver ()
13 {
14   assert (!span_);
15 }
16
17 Staff_symbol_engraver::Staff_symbol_engraver ()
18 {
19   finished_span_ = 0;
20   first_start_ = true;
21   span_ = 0;
22   span_events_[LEFT] = 0;
23   span_events_[RIGHT] = 0;
24 }
25
26 bool
27 Staff_symbol_engraver::try_music (Music *music)
28 {
29   Direction d = to_dir (music->get_property ("span-direction"));
30   if (d)
31     {
32       span_events_[d] = music;
33       return true;
34     }
35
36   return false;
37 }
38
39 void
40 Staff_symbol_engraver::process_music ()
41 {
42   if (span_events_[STOP])
43     {
44       finished_span_ = span_;
45       span_ = 0;
46       if (first_start_)
47         first_start_ = false;
48     }
49
50   if (span_events_[START]
51       || (first_start_ && !span_events_[STOP]))
52     start_spanner ();
53 }
54
55 void
56 Staff_symbol_engraver::start_spanner ()
57 {
58   if (!span_)
59     span_ = make_spanner ("StaffSymbol", SCM_EOL);
60 }
61
62 void
63 Staff_symbol_engraver::stop_spanner ()
64 {
65   if (finished_span_ && !finished_span_->get_bound (RIGHT))
66     finished_span_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
67   finished_span_ = 0;
68 }
69
70 void
71 Staff_symbol_engraver::stop_translation_timestep ()
72 {
73   if ((span_events_[START] || first_start_)
74       && span_
75       && !span_->get_bound (LEFT))
76     {
77       span_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn")));
78       first_start_ = false;
79     }
80
81   span_events_[START] = 0;
82   span_events_[STOP] = 0;
83   stop_spanner ();
84 }
85
86 void
87 Staff_symbol_engraver::finalize ()
88 {
89   finished_span_ = span_;
90   span_ = 0;
91   stop_spanner ();
92 }
93
94 /*
95   Todo: staff-symbol-referencer iface.
96 */
97 void
98 Staff_symbol_engraver::acknowledge_grob (Grob_info s)
99 {
100   /*
101     Perhaps should try to take SeparationItem as bound of the staff
102     symbol?
103   */
104   if (span_ || finished_span_)
105     {
106       Spanner *my = span_ ? span_ : finished_span_;
107       s.grob ()->set_object ("staff-symbol", my->self_scm ());
108     }
109 }
110
111 #include "translator.icc"
112 ADD_ACKNOWLEDGER (Staff_symbol_engraver, grob);
113 ADD_TRANSLATOR (Staff_symbol_engraver,
114                 /* doc */ "Create the constellation of five (default) "
115                 "staff lines.",
116                 /* create */ "StaffSymbol",
117                 /* accept */ "staff-span-event",
118                 /* read */ "",
119                 /* write */ "");