Fix type predicates/docstrings for two music properties.
[lilypond/mpolesky.git] / lily / instrument-name-engraver.cc
blob26a6fdd04d80066c3d879b4880e8d0ff4772c0d7
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2000--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
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.
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.
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/>.
20 #include "engraver.hh"
21 #include "pointer-group-interface.hh"
22 #include "side-position-interface.hh"
23 #include "axis-group-interface.hh"
24 #include "align-interface.hh"
25 #include "text-interface.hh"
26 #include "system.hh"
28 #include "translator.icc"
30 class Instrument_name_engraver : public Engraver
32 public:
33 TRANSLATOR_DECLARATIONS (Instrument_name_engraver);
35 protected:
36 Spanner *text_spanner_;
38 SCM long_text_;
39 SCM short_text_;
41 vector<Grob *> axis_groups_;
43 virtual void finalize ();
44 DECLARE_ACKNOWLEDGER (axis_group);
45 void process_music ();
46 void start_spanner ();
47 void consider_start_spanner ();
48 void stop_spanner ();
50 virtual void derived_mark () const;
53 void
54 Instrument_name_engraver::derived_mark () const
56 scm_gc_mark (long_text_);
57 scm_gc_mark (short_text_);
60 Instrument_name_engraver::Instrument_name_engraver ()
62 text_spanner_ = 0;
64 long_text_ = SCM_EOL;
65 short_text_ = SCM_EOL;
68 void
69 Instrument_name_engraver::process_music ()
71 consider_start_spanner ();
74 void
75 Instrument_name_engraver::consider_start_spanner ()
77 SCM long_text = get_property ("instrumentName");
78 SCM short_text = get_property ("shortInstrumentName");
80 if (!(Text_interface::is_markup (long_text)
81 || Text_interface::is_markup (short_text)))
83 long_text = get_property ("vocalName");
84 short_text = get_property ("shortVocalName");
87 if ((Text_interface::is_markup (long_text)
88 || Text_interface::is_markup (short_text))
89 && (!text_spanner_
90 || short_text_ != short_text
91 || long_text_ != long_text))
93 if (text_spanner_)
94 stop_spanner ();
96 short_text_ = short_text;
97 long_text_ = long_text;
99 start_spanner ();
103 void
104 Instrument_name_engraver::start_spanner ()
106 text_spanner_ = make_spanner ("InstrumentName", SCM_EOL);
108 Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
109 text_spanner_->set_bound (LEFT, col);
110 text_spanner_->set_property ("text", short_text_);
111 text_spanner_->set_property ("long-text", long_text_);
114 UGH, should handle this in Score_engraver.
116 Grob *system = unsmob_grob (get_property ("rootSystem"));
117 if (system)
118 Axis_group_interface::add_element (system, text_spanner_);
119 else
120 text_spanner_->programming_error ("cannot find root system");
123 void
124 Instrument_name_engraver::acknowledge_axis_group (Grob_info info)
126 if (dynamic_cast<Spanner *> (info.grob ())
127 && Axis_group_interface::has_axis (info.grob (), Y_AXIS)
129 /* ugh. */
131 && !info.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface"))
132 && !info.grob ()->internal_has_interface (ly_symbol2scm ("piano-pedal-interface"))
133 && !info.grob ()->internal_has_interface (ly_symbol2scm ("volta-interface"))
134 && (!Align_interface::has_interface (info.grob ())))
136 axis_groups_.push_back (info.grob ());
140 void
141 Instrument_name_engraver::finalize ()
143 if (text_spanner_)
144 stop_spanner ();
147 void
148 Instrument_name_engraver::stop_spanner ()
150 for (vsize i = 0; i < axis_groups_.size (); i++)
151 Pointer_group_interface::add_grob (text_spanner_,
152 ly_symbol2scm ("elements"),
153 axis_groups_[i]);
155 text_spanner_->set_bound (RIGHT,
156 unsmob_grob (get_property ("currentCommandColumn")));
158 Pointer_group_interface::set_ordered (text_spanner_,
159 ly_symbol2scm ("elements"),
160 false);
162 text_spanner_ = 0;
166 ADD_ACKNOWLEDGER (Instrument_name_engraver, axis_group);
168 ADD_TRANSLATOR (Instrument_name_engraver,
169 /* doc */
170 "Create a system start text for instrument or vocal names.",
172 /* create */
173 "InstrumentName ",
175 /* read */
176 "currentCommandColumn "
177 "instrumentName "
178 "shortInstrumentName "
179 "shortVocalName "
180 "vocalName ",
182 /* write */