]> git.donarmstrong.com Git - lilypond.git/blob - lily/episema-engraver.cc
Web-ja: update introduction
[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 class Episema_engraver : public Engraver
31 {
32 public:
33   TRANSLATOR_DECLARATIONS (Episema_engraver);
34 protected:
35   virtual void finalize ();
36   void listen_episema (Stream_event *);
37   void acknowledge_note_column (Grob_info);
38   void acknowledge_note_head (Grob_info);
39   void stop_translation_timestep ();
40   void process_music ();
41
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 ();
49 };
50
51 Episema_engraver::Episema_engraver (Context *c)
52   : Engraver (c)
53 {
54   finished_ = 0;
55   current_event_ = 0;
56   span_ = 0;
57   event_drul_.set (0, 0);
58 }
59
60 void
61 Episema_engraver::listen_episema (Stream_event *ev)
62 {
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;
67 }
68
69 void
70 Episema_engraver::process_music ()
71 {
72   if (event_drul_[START])
73     {
74       if (current_event_)
75         event_drul_[START]->origin ()->warning (_ ("already have an episema"));
76       else
77         {
78           current_event_ = event_drul_[START];
79           span_ = make_spanner ("Episema", event_drul_[START]->self_scm ());
80
81           event_drul_[START] = 0;
82         }
83     }
84   if (event_drul_[STOP])
85     {
86       if (!span_)
87         event_drul_[STOP]
88         ->origin ()->warning (_ ("cannot find start of episema"));
89       else
90         {
91           finished_ = span_;
92           announce_end_grob (finished_, SCM_EOL);
93           span_ = 0;
94           current_event_ = 0;
95           note_columns_.clear ();
96         }
97     }
98 }
99
100 void
101 Episema_engraver::typeset_all ()
102 {
103   if (finished_)
104     {
105       if (!finished_->get_bound (RIGHT))
106         {
107           Grob *col = (note_columns_.size ()
108                        ? note_columns_.back ()
109                        : unsmob<Grob> (get_property ("currentMusicalColumn")));
110           finished_->set_bound (RIGHT, col);
111         }
112       finished_ = 0;
113     }
114 }
115
116 void
117 Episema_engraver::stop_translation_timestep ()
118 {
119   if (span_ && !span_->get_bound (LEFT))
120     {
121       Grob *col = (note_columns_.size ()
122                    ? note_columns_.front ()
123                    : unsmob<Grob> (get_property ("currentMusicalColumn")));
124       span_->set_bound (LEFT, col);
125     }
126
127   typeset_all ();
128   event_drul_.set (0, 0);
129 }
130
131 void
132 Episema_engraver::finalize ()
133 {
134   typeset_all ();
135   if (span_)
136     {
137       current_event_->origin ()->warning (_ ("unterminated episema"));
138       span_->suicide ();
139       span_ = 0;
140     }
141 }
142
143 void
144 Episema_engraver::acknowledge_note_column (Grob_info info)
145 {
146   note_columns_.push_back (info.grob ());
147 }
148
149 void
150 Episema_engraver::acknowledge_note_head (Grob_info info)
151 {
152   if (span_)
153     {
154       Side_position_interface::add_support (span_, info.grob ());
155       add_bound_item (span_, info.grob ());
156     }
157   else if (finished_)
158     {
159       Side_position_interface::add_support (finished_, info.grob ());
160       add_bound_item (finished_, info.grob ());
161     }
162 }
163
164
165 void
166 Episema_engraver::boot ()
167 {
168   ADD_LISTENER (Episema_engraver, episema);
169   ADD_ACKNOWLEDGER (Episema_engraver, note_column);
170   ADD_ACKNOWLEDGER (Episema_engraver, note_head);
171 }
172
173 ADD_TRANSLATOR (Episema_engraver,
174                 /* doc */
175                 "Create an @emph{Editio Vaticana}-style episema line.",
176
177                 /* create */
178                 "Episema ",
179
180                 /* read */
181                 "",
182
183                 /* write */
184                 ""
185                );