]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / instrument-name-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2000--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
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 "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"
26 #include "system.hh"
27 #include "text-interface.hh"
28
29 #include "translator.icc"
30
31 using std::vector;
32
33 class Instrument_name_engraver : public Engraver
34 {
35 public:
36   TRANSLATOR_DECLARATIONS (Instrument_name_engraver);
37
38 protected:
39   Spanner *text_spanner_;
40
41   SCM long_text_;
42   SCM short_text_;
43
44   vector<Grob *> axis_groups_;
45   vector<Grob *> backup_axis_groups_;
46
47   virtual void finalize ();
48   DECLARE_ACKNOWLEDGER (axis_group);
49   void process_music ();
50   void start_spanner ();
51   void consider_start_spanner ();
52   void stop_spanner ();
53
54   virtual void derived_mark () const;
55 };
56
57 void
58 Instrument_name_engraver::derived_mark () const
59 {
60   scm_gc_mark (long_text_);
61   scm_gc_mark (short_text_);
62 }
63
64 Instrument_name_engraver::Instrument_name_engraver ()
65 {
66   text_spanner_ = 0;
67
68   long_text_ = SCM_EOL;
69   short_text_ = SCM_EOL;
70 }
71
72 void
73 Instrument_name_engraver::process_music ()
74 {
75   consider_start_spanner ();
76 }
77
78 void
79 Instrument_name_engraver::consider_start_spanner ()
80 {
81   SCM long_text = get_property ("instrumentName");
82   SCM short_text = get_property ("shortInstrumentName");
83
84   if (!(Text_interface::is_markup (long_text)
85         || Text_interface::is_markup (short_text)))
86     {
87       long_text = get_property ("vocalName");
88       short_text = get_property ("shortVocalName");
89     }
90
91   if ((Text_interface::is_markup (long_text)
92        || Text_interface::is_markup (short_text))
93       && (!text_spanner_
94           || !scm_is_eq (short_text_, short_text)
95           || !scm_is_eq (long_text_, long_text)))
96     {
97       if (text_spanner_)
98         stop_spanner ();
99
100       short_text_ = short_text;
101       long_text_ = long_text;
102
103       start_spanner ();
104     }
105 }
106
107 void
108 Instrument_name_engraver::start_spanner ()
109 {
110   text_spanner_ = make_spanner ("InstrumentName", SCM_EOL);
111
112   Grob *col = unsmob<Grob> (get_property ("currentCommandColumn"));
113   text_spanner_->set_bound (LEFT, col);
114   text_spanner_->set_property ("text", short_text_);
115   text_spanner_->set_property ("long-text", long_text_);
116
117   /*
118     UGH, should handle this in Score_engraver.
119   */
120   Grob *system = unsmob<Grob> (get_property ("rootSystem"));
121   if (system)
122     Axis_group_interface::add_element (system, text_spanner_);
123   else
124     text_spanner_->programming_error ("cannot find root system");
125 }
126
127 void
128 Instrument_name_engraver::acknowledge_axis_group (Grob_info info)
129 {
130   if (dynamic_cast<Spanner *> (info.grob ())
131       && Axis_group_interface::has_axis (info.grob (), Y_AXIS)
132
133       /* ugh. */
134
135       && !info.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface"))
136       && !info.grob ()->internal_has_interface (ly_symbol2scm ("piano-pedal-interface"))
137       && !info.grob ()->internal_has_interface (ly_symbol2scm ("volta-interface"))
138       && (!has_interface<Align_interface> (info.grob ())))
139     {
140       if (Page_layout_problem::is_spaceable (info.grob ()))
141         axis_groups_.push_back (info.grob ());
142       else
143         // By default, don't include non-spaceable staves in the
144         // support of an instrument name.  However, if the only staves
145         // are non-spaceable, we'll fall back to using them.
146         backup_axis_groups_.push_back (info.grob ());
147     }
148 }
149
150 void
151 Instrument_name_engraver::finalize ()
152 {
153   if (text_spanner_)
154     stop_spanner ();
155 }
156
157 void
158 Instrument_name_engraver::stop_spanner ()
159 {
160   if (axis_groups_.empty ())
161     axis_groups_ = backup_axis_groups_;
162
163   for (vsize i = 0; i < axis_groups_.size (); i++)
164     Pointer_group_interface::add_grob (text_spanner_,
165                                        ly_symbol2scm ("elements"),
166                                        axis_groups_[i]);
167
168   text_spanner_->set_bound (RIGHT,
169                             unsmob<Grob> (get_property ("currentCommandColumn")));
170
171   Pointer_group_interface::set_ordered (text_spanner_,
172                                         ly_symbol2scm ("elements"),
173                                         false);
174
175   text_spanner_ = 0;
176 }
177
178 ADD_ACKNOWLEDGER (Instrument_name_engraver, axis_group);
179
180 ADD_TRANSLATOR (Instrument_name_engraver,
181                 /* doc */
182                 "Create a system start text for instrument or vocal names.",
183
184                 /* create */
185                 "InstrumentName ",
186
187                 /* read */
188                 "currentCommandColumn "
189                 "instrumentName "
190                 "shortInstrumentName "
191                 "shortVocalName "
192                 "vocalName ",
193
194                 /* write */
195                 ""
196                );