]> git.donarmstrong.com Git - lilypond.git/blob - lily/episema-engraver.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / episema-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2010--2015 Neil Puttock <n.puttock@gmail.com>
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 "note-column.hh"
23 #include "pointer-group-interface.hh"
24 #include "side-position-interface.hh"
25 #include "spanner.hh"
26 #include "stream-event.hh"
27
28 #include "translator.icc"
29
30 using std::vector;
31
32 class Episema_engraver : public Engraver
33 {
34 public:
35   TRANSLATOR_DECLARATIONS (Episema_engraver);
36 protected:
37   virtual void finalize ();
38   DECLARE_TRANSLATOR_LISTENER (episema);
39   DECLARE_ACKNOWLEDGER (note_column);
40   DECLARE_ACKNOWLEDGER (note_head);
41   void stop_translation_timestep ();
42   void process_music ();
43
44 private:
45   Spanner *span_;
46   Spanner *finished_;
47   Stream_event *current_event_;
48   Drul_array<Stream_event *> event_drul_;
49   vector<Grob *> note_columns_;
50   void typeset_all ();
51 };
52
53 Episema_engraver::Episema_engraver ()
54 {
55   finished_ = 0;
56   current_event_ = 0;
57   span_ = 0;
58   event_drul_.set (0, 0);
59 }
60
61 IMPLEMENT_TRANSLATOR_LISTENER (Episema_engraver, episema);
62 void
63 Episema_engraver::listen_episema (Stream_event *ev)
64 {
65   Direction d = to_dir (ev->get_property ("span-direction"));
66   // Must not ASSIGN_EVENT_ONCE here, since episema
67   // can be typeset over a single neume
68   event_drul_[d] = ev;
69 }
70
71 void
72 Episema_engraver::process_music ()
73 {
74   if (event_drul_[START])
75     {
76       if (current_event_)
77         event_drul_[START]->origin ()->warning (_ ("already have an episema"));
78       else
79         {
80           current_event_ = event_drul_[START];
81           span_ = make_spanner ("Episema", event_drul_[START]->self_scm ());
82
83           event_drul_[START] = 0;
84         }
85     }
86   if (event_drul_[STOP])
87     {
88       if (!span_)
89         event_drul_[STOP]
90         ->origin ()->warning (_ ("cannot find start of episema"));
91       else
92         {
93           finished_ = span_;
94           announce_end_grob (finished_, SCM_EOL);
95           span_ = 0;
96           current_event_ = 0;
97           note_columns_.clear ();
98         }
99     }
100 }
101
102 void
103 Episema_engraver::typeset_all ()
104 {
105   if (finished_)
106     {
107       if (!finished_->get_bound (RIGHT))
108         {
109           Grob *col = (note_columns_.size ()
110                        ? note_columns_.back ()
111                        : unsmob<Grob> (get_property ("currentMusicalColumn")));
112           finished_->set_bound (RIGHT, col);
113         }
114       finished_ = 0;
115     }
116 }
117
118 void
119 Episema_engraver::stop_translation_timestep ()
120 {
121   if (span_ && !span_->get_bound (LEFT))
122     {
123       Grob *col = (note_columns_.size ()
124                    ? note_columns_.front ()
125                    : unsmob<Grob> (get_property ("currentMusicalColumn")));
126       span_->set_bound (LEFT, col);
127     }
128
129   typeset_all ();
130   event_drul_.set (0, 0);
131 }
132
133 void
134 Episema_engraver::finalize ()
135 {
136   typeset_all ();
137   if (span_)
138     {
139       current_event_->origin ()->warning (_ ("unterminated episema"));
140       span_->suicide ();
141       span_ = 0;
142     }
143 }
144
145 void
146 Episema_engraver::acknowledge_note_column (Grob_info info)
147 {
148   note_columns_.push_back (info.grob ());
149 }
150
151 void
152 Episema_engraver::acknowledge_note_head (Grob_info info)
153 {
154   if (span_)
155     {
156       Side_position_interface::add_support (span_, info.grob ());
157       add_bound_item (span_, info.grob ());
158     }
159   else if (finished_)
160     {
161       Side_position_interface::add_support (finished_, info.grob ());
162       add_bound_item (finished_, info.grob ());
163     }
164 }
165
166 ADD_ACKNOWLEDGER (Episema_engraver, note_column);
167 ADD_ACKNOWLEDGER (Episema_engraver, note_head);
168
169 ADD_TRANSLATOR (Episema_engraver,
170                 /* doc */
171                 "Create an @emph{Editio Vaticana}-style episema line.",
172
173                 /* create */
174                 "Episema ",
175
176                 /* read */
177                 "",
178
179                 /* write */
180                 ""
181                );