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