LSR: Update.
[lilypond/mpolesky.git] / lily / trill-spanner-engraver.cc
blobd00a0978dd3be59b6ddac74e3193dacdf04253bf
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2000--2010 Jan Nieuwenhuizen <janneke@gnu.org>
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/>.
21 C&P from text-spanner.cc
23 - todo: ending should be detected automatically? a new note
24 automatically is the end of the trill?
27 #include "engraver.hh"
29 #include "international.hh"
30 #include "note-column.hh"
31 #include "pointer-group-interface.hh"
32 #include "side-position-interface.hh"
33 #include "stream-event.hh"
34 #include "spanner.hh"
36 #include "translator.icc"
38 class Trill_spanner_engraver : public Engraver
40 public:
41 TRANSLATOR_DECLARATIONS (Trill_spanner_engraver);
42 protected:
43 virtual void finalize ();
44 DECLARE_TRANSLATOR_LISTENER (trill_span);
45 DECLARE_ACKNOWLEDGER (note_column);
47 void stop_translation_timestep ();
48 void process_music ();
50 private:
51 Spanner *span_;
52 Spanner *finished_;
53 Stream_event *current_event_;
54 Drul_array<Stream_event *> event_drul_;
55 void typeset_all ();
58 Trill_spanner_engraver::Trill_spanner_engraver ()
60 finished_ = 0;
61 current_event_ = 0;
62 span_ = 0;
63 event_drul_.set (0, 0);
66 IMPLEMENT_TRANSLATOR_LISTENER (Trill_spanner_engraver, trill_span);
67 void
68 Trill_spanner_engraver::listen_trill_span (Stream_event *ev)
70 Direction d = to_dir (ev->get_property ("span-direction"));
71 ASSIGN_EVENT_ONCE (event_drul_[d], ev);
74 void
75 Trill_spanner_engraver::acknowledge_note_column (Grob_info info)
77 if (span_)
79 Pointer_group_interface::add_grob (span_,
80 ly_symbol2scm ("note-columns"),
81 info.grob());
82 if (!span_->get_bound (LEFT))
83 add_bound_item (span_, info.grob ());
85 else if (finished_)
87 Pointer_group_interface::add_grob (finished_, ly_symbol2scm ("note-columns"),
88 info.grob());
89 if (!finished_->get_bound (RIGHT))
90 add_bound_item (finished_, info.grob ());
94 void
95 Trill_spanner_engraver::process_music ()
97 if (span_
98 && (event_drul_[STOP] || event_drul_[START]))
100 Stream_event *ender = event_drul_[STOP];
101 if (!ender)
102 ender = event_drul_[START];
103 finished_ = span_;
104 announce_end_grob (finished_, ender->self_scm ());
105 span_ = 0;
106 current_event_ = 0;
109 if (event_drul_[START])
111 current_event_ = event_drul_[START];
112 span_ = make_spanner ("TrillSpanner", event_drul_[START]->self_scm ());
113 Side_position_interface::set_axis (span_, Y_AXIS);
117 void
118 Trill_spanner_engraver::typeset_all ()
120 if (finished_)
122 if (!finished_->get_bound (RIGHT))
124 Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
125 finished_->set_bound (RIGHT, e);
127 finished_ = 0;
131 void
132 Trill_spanner_engraver::stop_translation_timestep ()
134 if (span_ && !span_->get_bound (LEFT))
136 Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
137 span_->set_bound (LEFT, e);
140 typeset_all ();
141 event_drul_.set (0, 0);
144 void
145 Trill_spanner_engraver::finalize ()
147 typeset_all ();
148 if (span_)
150 Grob *e = unsmob_grob (get_property ("currentCommandColumn"));
151 span_->set_bound (RIGHT, e);
155 ADD_ACKNOWLEDGER (Trill_spanner_engraver, note_column);
157 ADD_TRANSLATOR (Trill_spanner_engraver,
158 /* doc */
159 "Create trill spanner from an event.",
161 /* create */
162 "TrillSpanner ",
164 /* read */
165 "currentCommandColumn "
166 "currentMusicalColumn ",
168 /* write */