]> git.donarmstrong.com Git - lilypond.git/blob - lily/ottava-engraver.cc
6296e8c8a2092c9adaf2732a9150d8d81c6e9f69
[lilypond.git] / lily / ottava-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2000--2014 Han-Wen Nienhuys
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "engraver.hh"
21 #include "item.hh"
22 #include "note-column.hh"
23 #include "protected-scm.hh"
24 #include "side-position-interface.hh"
25 #include "spanner.hh"
26 #include "text-interface.hh"
27
28 class Ottava_spanner_engraver : public Engraver
29 {
30 public:
31   TRANSLATOR_DECLARATIONS (Ottava_spanner_engraver);
32 protected:
33   virtual void finalize ();
34
35   DECLARE_ACKNOWLEDGER (note_column);
36
37   void process_music ();
38   void stop_translation_timestep ();
39   virtual void derived_mark () const;
40 private:
41   Spanner *span_;
42   Spanner *finished_;
43
44   SCM last_ottavation_;
45
46   void typeset_all ();
47 };
48
49 void
50 Ottava_spanner_engraver::derived_mark () const
51 {
52   scm_gc_mark (last_ottavation_);
53 }
54
55 Ottava_spanner_engraver::Ottava_spanner_engraver ()
56 {
57   finished_ = 0;
58   span_ = 0;
59   last_ottavation_ = SCM_EOL;
60 }
61
62 void
63 Ottava_spanner_engraver::process_music ()
64 {
65   SCM ott = get_property ("ottavation");
66   if (ott != last_ottavation_)
67     {
68       finished_ = span_;
69       span_ = 0;
70       if (Text_interface::is_markup (ott))
71         {
72           span_ = make_spanner ("OttavaBracket", SCM_EOL);
73           span_->set_property ("text", ott);
74
75           SCM offset (get_property ("middleCOffset"));
76           if (robust_scm2double (offset, 0) > 0)
77             span_->set_property ("direction", scm_from_int (DOWN));
78         }
79     }
80   last_ottavation_ = ott;
81 }
82
83 void
84 Ottava_spanner_engraver::acknowledge_note_column (Grob_info info)
85 {
86   Item *it = info.item ();
87   if (span_ && it)
88     {
89       Side_position_interface::add_support (span_, it);
90
91       if (!span_->get_bound (LEFT))
92         span_->set_bound (LEFT, it);
93       span_->set_bound (RIGHT, it);
94     }
95 }
96
97 void
98 Ottava_spanner_engraver::typeset_all ()
99 {
100   if (finished_)
101     {
102       for (LEFT_and_RIGHT (d))
103         {
104           if (!finished_->get_bound (RIGHT))
105             {
106               Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
107               finished_->set_bound (d, e);
108             }
109         }
110
111       finished_ = 0;
112     }
113 }
114
115 void
116 Ottava_spanner_engraver::stop_translation_timestep ()
117 {
118   if (span_ && !span_->get_bound (LEFT))
119     {
120       Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
121       span_->set_bound (LEFT, e);
122     }
123
124   typeset_all ();
125 }
126
127 void
128 Ottava_spanner_engraver::finalize ()
129 {
130   typeset_all ();
131   if (span_)
132     finished_ = span_;
133   typeset_all ();
134   last_ottavation_ = SCM_EOL;
135 }
136
137 #include "translator.icc"
138
139 ADD_ACKNOWLEDGER (Ottava_spanner_engraver, note_column);
140
141 ADD_TRANSLATOR (Ottava_spanner_engraver,
142                 /* doc */
143                 "Create a text spanner when the ottavation property changes.",
144
145                 /* create */
146                 "OttavaBracket ",
147
148                 /* read */
149                 "middleCOffset "
150                 "ottavation "
151                 "currentMusicalColumn ",
152
153                 /* write */
154                 ""
155                );