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