]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol-engraver.cc
Merge branch 'master' of /home/jcharles/GIT/Lily/. into translation
[lilypond.git] / lily / staff-symbol-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
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.
10
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.
15
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/>.
18 */
19
20 #include "engraver.hh"
21 #include "international.hh"
22 #include "spanner.hh"
23 #include "stream-event.hh"
24 #include "warn.hh"
25
26 #include "translator.icc"
27
28 class Staff_symbol_engraver : public Engraver
29 {
30 public:
31   TRANSLATOR_DECLARATIONS (Staff_symbol_engraver);
32
33 protected:
34   Drul_array<Stream_event *> span_events_;
35   Spanner *span_;
36   Spanner *finished_span_;
37   bool first_start_;
38
39 protected:
40   virtual void start_spanner ();
41   virtual void stop_spanner ();
42
43   void stop_translation_timestep ();
44   virtual ~Staff_symbol_engraver ();
45   void acknowledge_grob (Grob_info);
46   void listen_staff_span (Stream_event *);
47   virtual void finalize ();
48   void process_music ();
49   virtual void derived_mark () const;
50 };
51
52 void
53 Staff_symbol_engraver::derived_mark () const
54 {
55   for (LEFT_and_RIGHT (d))
56     {
57       if (span_events_[d])
58         scm_gc_mark (span_events_[d]->self_scm ());
59     }
60 }
61
62 Staff_symbol_engraver::~Staff_symbol_engraver ()
63 {
64   if (span_)
65     {
66       // Somehow finalize() was not called?
67       programming_error ("Have a pending spanner in destructor.");
68     }
69 }
70
71 Staff_symbol_engraver::Staff_symbol_engraver ()
72 {
73   finished_span_ = 0;
74   first_start_ = true;
75   span_ = 0;
76   span_events_.set (0, 0);
77 }
78
79 void
80 Staff_symbol_engraver::listen_staff_span (Stream_event *ev)
81 {
82   Direction d = to_dir (ev->get_property ("span-direction"));
83   if (d)
84     ASSIGN_EVENT_ONCE (span_events_[d], ev);
85   else
86     programming_error ("staff-span event has no direction");
87 }
88
89 void
90 Staff_symbol_engraver::process_music ()
91 {
92   if (span_events_[STOP])
93     {
94       finished_span_ = span_;
95       span_ = 0;
96       if (first_start_)
97         first_start_ = false;
98     }
99
100   if (span_events_[START]
101       || (first_start_ && !span_events_[STOP]))
102     start_spanner ();
103 }
104
105 void
106 Staff_symbol_engraver::start_spanner ()
107 {
108   if (!span_)
109     {
110       span_ = make_spanner ("StaffSymbol", SCM_EOL);
111       span_->set_bound (LEFT,
112                         unsmob<Grob> (get_property ("currentCommandColumn")));
113     }
114 }
115
116 void
117 Staff_symbol_engraver::stop_spanner ()
118 {
119   if (!finished_span_)
120     return;
121
122   if (!finished_span_->get_bound (RIGHT))
123     finished_span_->set_bound (RIGHT, unsmob<Grob> (get_property ("currentCommandColumn")));
124
125   announce_end_grob (finished_span_,
126                      span_events_[STOP]
127                      ? span_events_[STOP]->self_scm ()
128                      : SCM_EOL);
129
130   finished_span_ = 0;
131 }
132
133 void
134 Staff_symbol_engraver::stop_translation_timestep ()
135 {
136   if ((span_events_[START] || first_start_)
137       && span_)
138     first_start_ = false;
139
140   span_events_.set (0, 0);
141   stop_spanner ();
142 }
143
144 void
145 Staff_symbol_engraver::finalize ()
146 {
147   finished_span_ = span_;
148   span_ = 0;
149   stop_spanner ();
150 }
151
152 /*
153   Todo: staff-symbol-referencer iface.
154 */
155 void
156 Staff_symbol_engraver::acknowledge_grob (Grob_info s)
157 {
158   if (span_ || finished_span_)
159     {
160       Spanner *my = span_ ? span_ : finished_span_;
161       s.grob ()->set_object ("staff-symbol", my->self_scm ());
162     }
163 }
164
165
166 void
167 Staff_symbol_engraver::boot ()
168 {
169   ADD_LISTENER (Staff_symbol_engraver, staff_span);
170   ADD_ACKNOWLEDGER (Staff_symbol_engraver, grob);
171 }
172
173 ADD_TRANSLATOR (Staff_symbol_engraver,
174                 /* doc */
175                 "Create the constellation of five (default) staff lines.",
176
177                 /* create */
178                 "StaffSymbol ",
179
180                 /* read */
181                 "",
182
183                 /* write */
184                 ""
185                );