Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / ottava-engraver.cc
blobfd59b33b8e83a7e158d1420ff149342c58fad534
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2000--2011 Han-Wen Nienhuys
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 "item.hh"
22 #include "note-column.hh"
23 #include "protected-scm.hh"
24 #include "side-position-interface.hh"
25 #include "spanner.hh"
26 #include "text-interface.hh"
29 class Ottava_spanner_engraver : public Engraver
31 public:
32 TRANSLATOR_DECLARATIONS (Ottava_spanner_engraver);
33 protected:
34 virtual void finalize ();
36 DECLARE_ACKNOWLEDGER (note_column);
38 void process_music ();
39 void stop_translation_timestep ();
40 virtual void derived_mark () const;
41 private:
42 Spanner *span_;
43 Spanner *finished_;
45 SCM last_ottavation_;
47 void typeset_all ();
50 void
51 Ottava_spanner_engraver::derived_mark () const
53 scm_gc_mark (last_ottavation_);
56 Ottava_spanner_engraver::Ottava_spanner_engraver ()
58 finished_ = 0;
59 span_ = 0;
60 last_ottavation_ = SCM_EOL;
63 void
64 Ottava_spanner_engraver::process_music ()
66 SCM ott = get_property ("ottavation");
67 if (ott != last_ottavation_)
69 finished_ = span_;
70 span_ = 0;
71 if (Text_interface::is_markup (ott))
73 span_ = make_spanner ("OttavaBracket", SCM_EOL);
74 span_->set_property ("text", ott);
76 SCM offset (get_property ("middleCOffset"));
77 if (robust_scm2double (offset, 0) > 0)
78 span_->set_property ("direction", scm_from_int (DOWN));
81 last_ottavation_ = ott;
84 void
85 Ottava_spanner_engraver::acknowledge_note_column (Grob_info info)
87 Item *it = info.item ();
88 if (span_ && it)
90 Side_position_interface::add_support (span_, it);
92 if (!span_->get_bound (LEFT))
93 span_->set_bound (LEFT, it);
94 span_->set_bound (RIGHT, it);
98 void
99 Ottava_spanner_engraver::typeset_all ()
101 if (finished_)
103 Direction d = LEFT;
106 if (!finished_->get_bound (RIGHT))
108 Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
109 finished_->set_bound (d, e);
112 while (flip (&d) != LEFT);
114 finished_ = 0;
118 void
119 Ottava_spanner_engraver::stop_translation_timestep ()
121 if (span_ && !span_->get_bound (LEFT))
123 Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
124 span_->set_bound (LEFT, e);
127 typeset_all ();
130 void
131 Ottava_spanner_engraver::finalize ()
133 typeset_all ();
134 if (span_)
135 finished_ = span_;
136 typeset_all ();
137 last_ottavation_ = SCM_EOL;
140 #include "translator.icc"
142 ADD_ACKNOWLEDGER (Ottava_spanner_engraver, note_column);
144 ADD_TRANSLATOR (Ottava_spanner_engraver,
145 /* doc */
146 "Create a text spanner when the ottavation property changes.",
148 /* create */
149 "OttavaBracket ",
151 /* read */
152 "middleCOffset "
153 "ottavation "
154 "currentMusicalColumn ",
156 /* write */