]> git.donarmstrong.com Git - lilypond.git/blob - lily/ottava-engraver.cc
* flower
[lilypond.git] / lily / ottava-engraver.cc
1 /*
2   text-spanner-engraver.cc -- implement Ottava_spanner_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2005 Han-Wen Nienhuys
7 */
8
9 #include "protected-scm.hh"
10 #include "note-column.hh"
11 #include "side-position-interface.hh"
12 #include "engraver.hh"
13
14 class Ottava_spanner_engraver : public Engraver
15 {
16 public:
17   TRANSLATOR_DECLARATIONS (Ottava_spanner_engraver);
18 protected:
19   virtual void finalize ();
20   virtual void acknowledge_grob (Grob_info);
21   virtual void process_music ();
22   virtual void stop_translation_timestep ();
23   virtual void derived_mark () const;
24 private:
25   Spanner *span_;
26   Spanner *finished_;
27
28   SCM last_ottavation_;
29
30   void typeset_all ();
31 };
32
33 void
34 Ottava_spanner_engraver::derived_mark () const
35 {
36   scm_gc_mark (last_ottavation_);
37 }
38
39 Ottava_spanner_engraver::Ottava_spanner_engraver ()
40 {
41   finished_ = 0;
42   span_ = 0;
43   last_ottavation_ = SCM_EOL;
44 }
45
46 void
47 Ottava_spanner_engraver::process_music ()
48 {
49   SCM ott = get_property ("ottavation");
50   if (ott != last_ottavation_)
51     {
52       finished_ = span_;
53       span_ = 0;
54       if (scm_is_string (ott))
55         {
56           span_ = make_spanner ("OttavaBracket", SCM_EOL);
57           span_->set_property ("text", ott);
58
59           SCM c0 (get_property ("middleCPosition"));
60           SCM oc0 (get_property ("originalCentralCPosition"));
61           if (scm_less_p (oc0, c0) == SCM_BOOL_T)
62             span_->set_property ("direction", scm_int2num (DOWN));
63         }
64     }
65   last_ottavation_ = ott;
66 }
67
68 void
69 Ottava_spanner_engraver::acknowledge_grob (Grob_info info)
70 {
71   Item *it = dynamic_cast<Item *> (info.grob_);
72   if (span_ && it && Note_column::has_interface (info.grob_))
73     {
74       Side_position_interface::add_support (span_, it);
75
76       if (!span_->get_bound (LEFT))
77         span_->set_bound (LEFT, it);
78       span_->set_bound (RIGHT, it);
79     }
80 }
81
82 void
83 Ottava_spanner_engraver::typeset_all ()
84 {
85   if (finished_)
86     {
87       Direction d = LEFT;
88       do
89         {
90           if (!finished_->get_bound (RIGHT))
91             {
92               Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
93               finished_->set_bound (d, e);
94             }
95         }
96       while (flip (&d) != LEFT);
97
98       finished_ = 0;
99     }
100 }
101
102 void
103 Ottava_spanner_engraver::stop_translation_timestep ()
104 {
105   if (span_ && !span_->get_bound (LEFT))
106     {
107       Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
108       span_->set_bound (LEFT, e);
109     }
110
111   typeset_all ();
112 }
113
114 void
115 Ottava_spanner_engraver::finalize ()
116 {
117   typeset_all ();
118   if (span_)
119     finished_ = span_;
120   typeset_all ();
121   last_ottavation_ = SCM_EOL;
122 }
123
124 ADD_TRANSLATOR (Ottava_spanner_engraver,
125                 /* descr */ "Create a text spanner when the ottavation property changes..",
126                 /* creats*/ "OttavaBracket",
127                 /* accepts */ "",
128                 /* acks  */ "note-column-interface",
129                 /* reads */ "ottavation",
130                 /* write */ "");