]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol-engraver.cc
* lily/ledger-line-engraver.cc (stop_translation_timestep): new
[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     {
60       span_ = make_spanner ("StaffSymbol", SCM_EOL);
61       span_->set_bound (LEFT,
62                         unsmob_grob (get_property ("currentCommandColumn")));
63     }
64 }
65
66 void
67 Staff_symbol_engraver::stop_spanner ()
68 {
69   if (finished_span_ && !finished_span_->get_bound (RIGHT))
70     finished_span_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
71   finished_span_ = 0;
72 }
73
74 void
75 Staff_symbol_engraver::stop_translation_timestep ()
76 {
77   if ((span_events_[START] || first_start_)
78       && span_)
79     {
80       first_start_ = false;
81     }
82
83   span_events_[START] = 0;
84   span_events_[STOP] = 0;
85   stop_spanner ();
86 }
87
88 void
89 Staff_symbol_engraver::finalize ()
90 {
91   finished_span_ = span_;
92   span_ = 0;
93   stop_spanner ();
94 }
95
96 /*
97   Todo: staff-symbol-referencer iface.
98 */
99 void
100 Staff_symbol_engraver::acknowledge_grob (Grob_info s)
101 {
102   /*
103     Perhaps should try to take SeparationItem as bound of the staff
104     symbol?
105   */
106   if (span_ || finished_span_)
107     {
108       Spanner *my = span_ ? span_ : finished_span_;
109       s.grob ()->set_object ("staff-symbol", my->self_scm ());
110     }
111 }
112
113 #include "translator.icc"
114
115 ADD_ACKNOWLEDGER (Staff_symbol_engraver, grob);
116
117 ADD_TRANSLATOR (Staff_symbol_engraver,
118                 /* doc */ "Create the constellation of five (default) "
119                 "staff lines.",
120                 /* create */ "StaffSymbol",
121                 /* accept */ "staff-span-event",
122                 /* read */ "",
123                 /* write */ "");