]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol-engraver.cc
Merge branch 'lilypond/translation' of ssh://git.sv.gnu.org/srv/git/lilypond into...
[lilypond.git] / lily / staff-symbol-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2010 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   DECLARE_ACKNOWLEDGER (grob);
46   DECLARE_TRANSLATOR_LISTENER (staff_span);
47   virtual void finalize ();
48   void process_music ();
49 };
50
51 Staff_symbol_engraver::~Staff_symbol_engraver ()
52 {
53   assert (!span_);
54 }
55
56 Staff_symbol_engraver::Staff_symbol_engraver ()
57 {
58   finished_span_ = 0;
59   first_start_ = true;
60   span_ = 0;
61   span_events_[LEFT] = 0;
62   span_events_[RIGHT] = 0;
63 }
64
65 IMPLEMENT_TRANSLATOR_LISTENER (Staff_symbol_engraver, staff_span);
66 void
67 Staff_symbol_engraver::listen_staff_span (Stream_event *ev)
68 {
69   Direction d = to_dir (ev->get_property ("span-direction"));
70   if (d)
71     ASSIGN_EVENT_ONCE (span_events_[d], ev);
72   else
73     programming_error (_ ("staff-span event has no direction"));
74 }
75
76 void
77 Staff_symbol_engraver::process_music ()
78 {
79   if (span_events_[STOP])
80     {
81       finished_span_ = span_;
82       span_ = 0;
83       if (first_start_)
84         first_start_ = false;
85     }
86
87   if (span_events_[START]
88       || (first_start_ && !span_events_[STOP]))
89     start_spanner ();
90 }
91
92 void
93 Staff_symbol_engraver::start_spanner ()
94 {
95   if (!span_)
96     {
97       span_ = make_spanner ("StaffSymbol", SCM_EOL);
98       span_->set_bound (LEFT,
99                         unsmob_grob (get_property ("currentCommandColumn")));
100     }
101 }
102
103 void
104 Staff_symbol_engraver::stop_spanner ()
105 {
106   if (!finished_span_)
107     return;
108
109   if (!finished_span_->get_bound (RIGHT))
110     finished_span_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
111   
112   announce_end_grob (finished_span_,
113                      span_events_[STOP]
114                      ? span_events_[STOP]->self_scm ()
115                      : SCM_EOL);
116   
117   finished_span_ = 0;
118 }
119
120 void
121 Staff_symbol_engraver::stop_translation_timestep ()
122 {
123   if ((span_events_[START] || first_start_)
124       && span_)
125     {
126       first_start_ = false;
127     }
128
129   span_events_[START] = 0;
130   span_events_[STOP] = 0;
131   stop_spanner ();
132 }
133
134 void
135 Staff_symbol_engraver::finalize ()
136 {
137   finished_span_ = span_;
138   span_ = 0;
139   stop_spanner ();
140 }
141
142 /*
143   Todo: staff-symbol-referencer iface.
144 */
145 void
146 Staff_symbol_engraver::acknowledge_grob (Grob_info s)
147 {
148   /*
149     Perhaps should try to take SeparationItem as bound of the staff
150     symbol?
151   */
152   if (span_ || finished_span_)
153     {
154       Spanner *my = span_ ? span_ : finished_span_;
155       s.grob ()->set_object ("staff-symbol", my->self_scm ());
156     }
157 }
158
159 ADD_ACKNOWLEDGER (Staff_symbol_engraver, grob);
160
161 ADD_TRANSLATOR (Staff_symbol_engraver,
162                 /* doc */
163                 "Create the constellation of five (default) staff lines.",
164
165                 /* create */
166                 "StaffSymbol ",
167
168                 /* read */
169                 "",
170
171                 /* write */
172                 ""
173                 );