Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / staff-symbol-engraver.cc
blob55e118245f2c793ac5b2ff92e995595e639d586e
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "engraver.hh"
21 #include "international.hh"
22 #include "spanner.hh"
23 #include "stream-event.hh"
24 #include "warn.hh"
26 #include "translator.icc"
28 class Staff_symbol_engraver : public Engraver
30 public:
31 TRANSLATOR_DECLARATIONS (Staff_symbol_engraver);
33 protected:
34 Drul_array<Stream_event *> span_events_;
35 Spanner *span_;
36 Spanner *finished_span_;
37 bool first_start_;
39 protected:
40 virtual void start_spanner ();
41 virtual void stop_spanner ();
43 void stop_translation_timestep ();
44 virtual ~Staff_symbol_engraver ();
45 DECLARE_ACKNOWLEDGER (grob);
46 DECLARE_TRANSLATOR_LISTENER (staff_span);
47 virtual void finalize ();
48 void process_music ();
51 Staff_symbol_engraver::~Staff_symbol_engraver ()
53 if (span_)
55 // Somehow finalize() was not called?
56 programming_error ("Have a pending spanner in destructor.");
60 Staff_symbol_engraver::Staff_symbol_engraver ()
62 finished_span_ = 0;
63 first_start_ = true;
64 span_ = 0;
65 span_events_.set (0, 0);
68 IMPLEMENT_TRANSLATOR_LISTENER (Staff_symbol_engraver, staff_span);
69 void
70 Staff_symbol_engraver::listen_staff_span (Stream_event *ev)
72 Direction d = to_dir (ev->get_property ("span-direction"));
73 if (d)
74 ASSIGN_EVENT_ONCE (span_events_[d], ev);
75 else
76 programming_error ("staff-span event has no direction");
79 void
80 Staff_symbol_engraver::process_music ()
82 if (span_events_[STOP])
84 finished_span_ = span_;
85 span_ = 0;
86 if (first_start_)
87 first_start_ = false;
90 if (span_events_[START]
91 || (first_start_ && !span_events_[STOP]))
92 start_spanner ();
95 void
96 Staff_symbol_engraver::start_spanner ()
98 if (!span_)
100 span_ = make_spanner ("StaffSymbol", SCM_EOL);
101 span_->set_bound (LEFT,
102 unsmob_grob (get_property ("currentCommandColumn")));
106 void
107 Staff_symbol_engraver::stop_spanner ()
109 if (!finished_span_)
110 return;
112 if (!finished_span_->get_bound (RIGHT))
113 finished_span_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
115 announce_end_grob (finished_span_,
116 span_events_[STOP]
117 ? span_events_[STOP]->self_scm ()
118 : SCM_EOL);
120 finished_span_ = 0;
123 void
124 Staff_symbol_engraver::stop_translation_timestep ()
126 if ((span_events_[START] || first_start_)
127 && span_)
128 first_start_ = false;
130 span_events_.set (0, 0);
131 stop_spanner ();
134 void
135 Staff_symbol_engraver::finalize ()
137 finished_span_ = span_;
138 span_ = 0;
139 stop_spanner ();
143 Todo: staff-symbol-referencer iface.
145 void
146 Staff_symbol_engraver::acknowledge_grob (Grob_info s)
148 if (span_ || finished_span_)
150 Spanner *my = span_ ? span_ : finished_span_;
151 s.grob ()->set_object ("staff-symbol", my->self_scm ());
155 ADD_ACKNOWLEDGER (Staff_symbol_engraver, grob);
157 ADD_TRANSLATOR (Staff_symbol_engraver,
158 /* doc */
159 "Create the constellation of five (default) staff lines.",
161 /* create */
162 "StaffSymbol ",
164 /* read */
167 /* write */