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