(Which properties to
[lilypond.git] / lily / ottava-engraver.cc
blobcd207cc872da052aeca3c8553c441a0a4cb83766
1 /*
2 text-spanner-engraver.cc -- implement Ottava_spanner_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2004 Han-Wen Nienhuys
7 */
9 #include "protected-scm.hh"
10 #include "note-column.hh"
11 #include "item.hh"
12 #include "side-position-interface.hh"
13 #include "engraver.hh"
15 class Ottava_spanner_engraver : public Engraver
17 public:
18 TRANSLATOR_DECLARATIONS (Ottava_spanner_engraver);
19 protected:
20 virtual void finalize ();
21 virtual void acknowledge_grob (Grob_info);
22 virtual void process_music ();
23 virtual void stop_translation_timestep ();
24 private:
25 Spanner *span_;
26 Spanner *finished_;
28 Protected_scm last_ottavation_;
30 void typeset_all ();
34 Ottava_spanner_engraver::Ottava_spanner_engraver ()
36 finished_ = 0;
37 span_ =0;
38 last_ottavation_ = SCM_EOL;
41 void
42 Ottava_spanner_engraver::process_music ()
44 SCM ott = get_property ("ottavation");
45 if (ott != last_ottavation_)
47 finished_= span_;
48 span_ = 0;
49 if (gh_string_p (ott))
51 span_ = make_spanner ("OttavaBracket");
52 span_->set_property ("text", ott);
53 announce_grob (span_, SCM_EOL);
55 SCM c0 (get_property ("middleCPosition"));
56 SCM oc0 (get_property ("originalCentralCPosition"));
57 if (scm_less_p (oc0, c0) == SCM_BOOL_T)
58 span_->set_property ("direction", gh_int2scm (DOWN));
61 last_ottavation_ = ott;
64 void
65 Ottava_spanner_engraver::acknowledge_grob (Grob_info info)
67 Item *it = dynamic_cast<Item*> (info.grob_);
68 if (span_ && it && Note_column::has_interface (info.grob_))
70 Side_position_interface::add_support (span_, it);
72 if (!span_->get_bound (LEFT))
73 span_->set_bound (LEFT, it);
74 span_->set_bound (RIGHT, it);
78 void
79 Ottava_spanner_engraver::typeset_all ()
81 if (finished_)
83 Direction d = LEFT;
86 if (!finished_->get_bound (RIGHT))
88 Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
89 finished_->set_bound (d, e);
92 while (flip (&d) != LEFT);
94 typeset_grob (finished_);
95 finished_ = 0;
99 void
100 Ottava_spanner_engraver::stop_translation_timestep ()
102 if (span_ && !span_->get_bound (LEFT))
104 Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
105 span_->set_bound (LEFT, e);
108 typeset_all ();
111 void
112 Ottava_spanner_engraver::finalize ()
114 typeset_all ();
115 if (span_)
116 finished_ = span_;
117 typeset_all ();
118 last_ottavation_ = SCM_EOL;
121 ENTER_DESCRIPTION (Ottava_spanner_engraver,
122 /* descr */ "Create a text spanner when the ottavation property changes..",
123 /* creats*/ "OttavaBracket",
124 /* accepts */ "",
125 /* acks */ "note-column-interface",
126 /* reads */ "ottavation",
127 /* write */ "");