]> git.donarmstrong.com Git - lilypond.git/blob - lily/ottava-engraver.cc
Run `make grand-replace'.
[lilypond.git] / lily / ottava-engraver.cc
1 /*
2   ottava-engraver.cc -- implement Ottava_spanner_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2008 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 #include "spanner.hh"
14 #include "text-interface.hh"
15 #include "item.hh"
16
17 class Ottava_spanner_engraver : public Engraver
18 {
19 public:
20   TRANSLATOR_DECLARATIONS (Ottava_spanner_engraver);
21 protected:
22   virtual void finalize ();
23
24   DECLARE_ACKNOWLEDGER (note_column);
25
26   void process_music ();
27   void stop_translation_timestep ();
28   virtual void derived_mark () const;
29 private:
30   Spanner *span_;
31   Spanner *finished_;
32
33   SCM last_ottavation_;
34
35   void typeset_all ();
36 };
37
38 void
39 Ottava_spanner_engraver::derived_mark () const
40 {
41   scm_gc_mark (last_ottavation_);
42 }
43
44 Ottava_spanner_engraver::Ottava_spanner_engraver ()
45 {
46   finished_ = 0;
47   span_ = 0;
48   last_ottavation_ = SCM_EOL;
49 }
50
51 void
52 Ottava_spanner_engraver::process_music ()
53 {
54   SCM ott = get_property ("ottavation");
55   if (ott != last_ottavation_)
56     {
57       finished_ = span_;
58       span_ = 0;
59       if (Text_interface::is_markup (ott))
60         {
61           span_ = make_spanner ("OttavaBracket", SCM_EOL);
62           span_->set_property ("text", ott);
63
64           SCM offset (get_property ("middleCOffset"));
65           if (robust_scm2double (offset, 0) > 0)
66             span_->set_property ("direction", scm_from_int (DOWN));
67         }
68     }
69   last_ottavation_ = ott;
70 }
71
72 void
73 Ottava_spanner_engraver::acknowledge_note_column (Grob_info info)
74 {
75   Item *it = info.item ();
76   if (span_ && it)
77     {
78       Side_position_interface::add_support (span_, it);
79
80       if (!span_->get_bound (LEFT))
81         span_->set_bound (LEFT, it);
82       span_->set_bound (RIGHT, it);
83     }
84 }
85
86 void
87 Ottava_spanner_engraver::typeset_all ()
88 {
89   if (finished_)
90     {
91       Direction d = LEFT;
92       do
93         {
94           if (!finished_->get_bound (RIGHT))
95             {
96               Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
97               finished_->set_bound (d, e);
98             }
99         }
100       while (flip (&d) != LEFT);
101
102       finished_ = 0;
103     }
104 }
105
106 void
107 Ottava_spanner_engraver::stop_translation_timestep ()
108 {
109   if (span_ && !span_->get_bound (LEFT))
110     {
111       Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
112       span_->set_bound (LEFT, e);
113     }
114
115   typeset_all ();
116 }
117
118 void
119 Ottava_spanner_engraver::finalize ()
120 {
121   typeset_all ();
122   if (span_)
123     finished_ = span_;
124   typeset_all ();
125   last_ottavation_ = SCM_EOL;
126 }
127
128 #include "translator.icc"
129
130 ADD_ACKNOWLEDGER (Ottava_spanner_engraver, note_column);
131
132 ADD_TRANSLATOR (Ottava_spanner_engraver,
133                 /* doc */
134                 "Create a text spanner when the ottavation property changes.",
135
136                 /* create */
137                 "OttavaBracket ",
138
139                 /* read */
140                 "ottavation "
141                 "originalMiddleCPosition "
142                 "currentMusicalColumn ",
143                 
144                 /* write */
145                 ""
146                 );