Nitpick: ly:spanner-bound grob name slur -> spanner.
[lilypond.git] / lily / ottava-engraver.cc
blobf4a8a8b91c839bbaefeea66eabf1aedd81844ec7
1 /*
2 ottava-engraver.cc -- implement Ottava_spanner_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2009 Han-Wen Nienhuys
7 */
9 #include "protected-scm.hh"
10 #include "note-column.hh"
11 #include "side-position-interface.hh"
12 #include "engraver.hh"
13 #include "spanner.hh"
14 #include "text-interface.hh"
15 #include "item.hh"
17 class Ottava_spanner_engraver : public Engraver
19 public:
20 TRANSLATOR_DECLARATIONS (Ottava_spanner_engraver);
21 protected:
22 virtual void finalize ();
24 DECLARE_ACKNOWLEDGER (note_column);
26 void process_music ();
27 void stop_translation_timestep ();
28 virtual void derived_mark () const;
29 private:
30 Spanner *span_;
31 Spanner *finished_;
33 SCM last_ottavation_;
35 void typeset_all ();
38 void
39 Ottava_spanner_engraver::derived_mark () const
41 scm_gc_mark (last_ottavation_);
44 Ottava_spanner_engraver::Ottava_spanner_engraver ()
46 finished_ = 0;
47 span_ = 0;
48 last_ottavation_ = SCM_EOL;
51 void
52 Ottava_spanner_engraver::process_music ()
54 SCM ott = get_property ("ottavation");
55 if (ott != last_ottavation_)
57 finished_ = span_;
58 span_ = 0;
59 if (Text_interface::is_markup (ott))
61 span_ = make_spanner ("OttavaBracket", SCM_EOL);
62 span_->set_property ("text", ott);
64 SCM offset (get_property ("middleCOffset"));
65 if (robust_scm2double (offset, 0) > 0)
66 span_->set_property ("direction", scm_from_int (DOWN));
69 last_ottavation_ = ott;
72 void
73 Ottava_spanner_engraver::acknowledge_note_column (Grob_info info)
75 Item *it = info.item ();
76 if (span_ && it)
78 Side_position_interface::add_support (span_, it);
80 if (!span_->get_bound (LEFT))
81 span_->set_bound (LEFT, it);
82 span_->set_bound (RIGHT, it);
86 void
87 Ottava_spanner_engraver::typeset_all ()
89 if (finished_)
91 Direction d = LEFT;
94 if (!finished_->get_bound (RIGHT))
96 Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
97 finished_->set_bound (d, e);
100 while (flip (&d) != LEFT);
102 finished_ = 0;
106 void
107 Ottava_spanner_engraver::stop_translation_timestep ()
109 if (span_ && !span_->get_bound (LEFT))
111 Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
112 span_->set_bound (LEFT, e);
115 typeset_all ();
118 void
119 Ottava_spanner_engraver::finalize ()
121 typeset_all ();
122 if (span_)
123 finished_ = span_;
124 typeset_all ();
125 last_ottavation_ = SCM_EOL;
128 #include "translator.icc"
130 ADD_ACKNOWLEDGER (Ottava_spanner_engraver, note_column);
132 ADD_TRANSLATOR (Ottava_spanner_engraver,
133 /* doc */
134 "Create a text spanner when the ottavation property changes.",
136 /* create */
137 "OttavaBracket ",
139 /* read */
140 "ottavation "
141 "originalMiddleCPosition "
142 "currentMusicalColumn ",
144 /* write */