2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2000--2011 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 "align-interface.hh"
21 #include "axis-group-interface.hh"
22 #include "engraver.hh"
23 #include "page-layout-problem.hh"
24 #include "pointer-group-interface.hh"
25 #include "side-position-interface.hh"
27 #include "text-interface.hh"
29 #include "translator.icc"
31 class Instrument_name_engraver : public Engraver
34 TRANSLATOR_DECLARATIONS (Instrument_name_engraver);
37 Spanner *text_spanner_;
42 vector<Grob *> axis_groups_;
44 virtual void finalize ();
45 DECLARE_ACKNOWLEDGER (axis_group);
46 void process_music ();
47 void start_spanner ();
48 void consider_start_spanner ();
51 virtual void derived_mark () const;
55 Instrument_name_engraver::derived_mark () const
57 scm_gc_mark (long_text_);
58 scm_gc_mark (short_text_);
61 Instrument_name_engraver::Instrument_name_engraver ()
66 short_text_ = SCM_EOL;
70 Instrument_name_engraver::process_music ()
72 consider_start_spanner ();
76 Instrument_name_engraver::consider_start_spanner ()
78 SCM long_text = get_property ("instrumentName");
79 SCM short_text = get_property ("shortInstrumentName");
81 if (!(Text_interface::is_markup (long_text)
82 || Text_interface::is_markup (short_text)))
84 long_text = get_property ("vocalName");
85 short_text = get_property ("shortVocalName");
88 if ((Text_interface::is_markup (long_text)
89 || Text_interface::is_markup (short_text))
91 || short_text_ != short_text
92 || long_text_ != long_text))
97 short_text_ = short_text;
98 long_text_ = long_text;
105 Instrument_name_engraver::start_spanner ()
107 text_spanner_ = make_spanner ("InstrumentName", SCM_EOL);
109 Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
110 text_spanner_->set_bound (LEFT, col);
111 text_spanner_->set_property ("text", short_text_);
112 text_spanner_->set_property ("long-text", long_text_);
115 UGH, should handle this in Score_engraver.
117 Grob *system = unsmob_grob (get_property ("rootSystem"));
119 Axis_group_interface::add_element (system, text_spanner_);
121 text_spanner_->programming_error ("cannot find root system");
125 Instrument_name_engraver::acknowledge_axis_group (Grob_info info)
127 if (dynamic_cast<Spanner *> (info.grob ())
128 && Axis_group_interface::has_axis (info.grob (), Y_AXIS)
129 && Page_layout_problem::is_spaceable (info.grob ())
133 && !info.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface"))
134 && !info.grob ()->internal_has_interface (ly_symbol2scm ("piano-pedal-interface"))
135 && !info.grob ()->internal_has_interface (ly_symbol2scm ("volta-interface"))
136 && (!Align_interface::has_interface (info.grob ())))
138 axis_groups_.push_back (info.grob ());
143 Instrument_name_engraver::finalize ()
150 Instrument_name_engraver::stop_spanner ()
152 for (vsize i = 0; i < axis_groups_.size (); i++)
153 Pointer_group_interface::add_grob (text_spanner_,
154 ly_symbol2scm ("elements"),
157 text_spanner_->set_bound (RIGHT,
158 unsmob_grob (get_property ("currentCommandColumn")));
160 Pointer_group_interface::set_ordered (text_spanner_,
161 ly_symbol2scm ("elements"),
167 ADD_ACKNOWLEDGER (Instrument_name_engraver, axis_group);
169 ADD_TRANSLATOR (Instrument_name_engraver,
171 "Create a system start text for instrument or vocal names.",
177 "currentCommandColumn "
179 "shortInstrumentName "