Doc: CG: Improve sectioning; update nodes and menus
[lilypond/mpolesky.git] / lily / episema-engraver.cc
bloba24640f8b98f961a4dd37355e2c67c91d7ae52d2
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2010 Neil Puttock <n.puttock@gmail.com>
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 "note-column.hh"
23 #include "pointer-group-interface.hh"
24 #include "side-position-interface.hh"
25 #include "spanner.hh"
26 #include "stream-event.hh"
28 #include "translator.icc"
30 class Episema_engraver : public Engraver
32 public:
33 TRANSLATOR_DECLARATIONS (Episema_engraver);
34 protected:
35 virtual void finalize ();
36 DECLARE_TRANSLATOR_LISTENER (episema);
37 DECLARE_ACKNOWLEDGER (note_column);
38 DECLARE_ACKNOWLEDGER (note_head);
39 void stop_translation_timestep ();
40 void process_music ();
42 private:
43 Spanner *span_;
44 Spanner *finished_;
45 Stream_event *current_event_;
46 Drul_array<Stream_event *> event_drul_;
47 vector<Grob *> note_columns_;
48 void typeset_all ();
51 Episema_engraver::Episema_engraver ()
53 finished_ = 0;
54 current_event_ = 0;
55 span_ = 0;
56 event_drul_.set (0, 0);
59 IMPLEMENT_TRANSLATOR_LISTENER (Episema_engraver, episema);
60 void
61 Episema_engraver::listen_episema (Stream_event *ev)
63 Direction d = to_dir (ev->get_property ("span-direction"));
64 // Must not ASSIGN_EVENT_ONCE here, since episema
65 // can be typeset over a single neume
66 event_drul_[d] = ev;
69 void
70 Episema_engraver::process_music ()
72 if (event_drul_[START])
74 if (current_event_)
75 event_drul_[START]->origin ()->warning (_ ("already have an episema"));
76 else
78 current_event_ = event_drul_[START];
79 span_ = make_spanner ("Episema", event_drul_[START]->self_scm ());
81 event_drul_[START] = 0;
84 if (event_drul_[STOP])
86 if (!span_)
87 event_drul_[STOP]
88 ->origin ()->warning (_ ("cannot find start of episema"));
89 else
91 finished_ = span_;
92 announce_end_grob (finished_, SCM_EOL);
93 span_ = 0;
94 current_event_ = 0;
95 note_columns_.clear ();
100 void
101 Episema_engraver::typeset_all ()
103 if (finished_)
105 if (!finished_->get_bound (RIGHT))
107 Grob *col = (note_columns_.size ()
108 ? note_columns_.back ()
109 : unsmob_grob (get_property ("currentMusicalColumn")));
110 finished_->set_bound (RIGHT, col);
112 finished_ = 0;
116 void
117 Episema_engraver::stop_translation_timestep ()
119 if (span_ && !span_->get_bound (LEFT))
121 Grob *col = (note_columns_.size ()
122 ? note_columns_.front ()
123 : unsmob_grob (get_property ("currentMusicalColumn")));
124 span_->set_bound (LEFT, col);
127 typeset_all ();
128 event_drul_.set (0, 0);
131 void
132 Episema_engraver::finalize ()
134 typeset_all ();
135 if (span_)
137 current_event_->origin ()->warning (_ ("unterminated episema"));
138 span_->suicide ();
139 span_ = 0;
143 void
144 Episema_engraver::acknowledge_note_column (Grob_info info)
146 note_columns_.push_back (info.grob ());
149 void
150 Episema_engraver::acknowledge_note_head (Grob_info info)
152 if (span_)
154 Side_position_interface::add_support (span_, info.grob ());
155 add_bound_item (span_, info.grob ());
157 else if (finished_)
159 Side_position_interface::add_support (finished_, info.grob ());
160 add_bound_item (finished_, info.grob ());
164 ADD_ACKNOWLEDGER (Episema_engraver, note_column);
165 ADD_ACKNOWLEDGER (Episema_engraver, note_head);
167 ADD_TRANSLATOR (Episema_engraver,
168 /* doc */
169 "Create an @emph{Editio Vaticana}-style episema line.",
171 /* create */
172 "Episema ",
174 /* read */
177 /* write */