]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
Merge branch 'lilypond/translation' of ssh://git.sv.gnu.org/srv/git/lilypond into...
[lilypond.git] / lily / instrument-name-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2000--2010 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 "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"
27
28 #include "translator.icc"
29
30 class Instrument_name_engraver : public Engraver
31 {
32 public:
33   TRANSLATOR_DECLARATIONS (Instrument_name_engraver);
34
35 protected:
36   Spanner *text_spanner_;
37
38   SCM long_text_;
39   SCM short_text_;
40
41   vector<Grob *> axis_groups_;
42   
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 ();
49 };
50
51 Instrument_name_engraver::Instrument_name_engraver ()
52 {
53   text_spanner_ = 0;
54
55   long_text_ = SCM_EOL;
56   short_text_ = SCM_EOL;
57 }
58
59 void
60 Instrument_name_engraver::process_music ()
61 {
62   consider_start_spanner ();
63 }
64
65 void
66 Instrument_name_engraver::consider_start_spanner ()
67 {
68   SCM long_text = get_property ("instrumentName");
69   SCM short_text = get_property ("shortInstrumentName");
70
71   if (!(Text_interface::is_markup (long_text)
72         || Text_interface::is_markup (short_text)))
73     {
74       long_text = get_property ("vocalName");
75       short_text = get_property ("shortVocalName");
76     }
77
78   if ((Text_interface::is_markup (long_text)
79        || Text_interface::is_markup (short_text))
80       && (!text_spanner_
81           || short_text_ != short_text
82           || long_text_ != long_text))
83     {
84       if (text_spanner_)
85         stop_spanner ();
86
87       short_text_ = short_text;
88       long_text_ = long_text;
89
90       start_spanner ();
91     }
92 }
93
94 void
95 Instrument_name_engraver::start_spanner ()
96 {
97   text_spanner_ = make_spanner ("InstrumentName", SCM_EOL);
98
99   Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
100   text_spanner_->set_bound (LEFT, col);
101   text_spanner_->set_property ("text", short_text_);
102   text_spanner_->set_property ("long-text", long_text_);
103
104   /*
105     UGH, should handle this in Score_engraver.
106   */
107   Grob *system = unsmob_grob (get_property ("rootSystem"));
108   if (system)
109     Axis_group_interface::add_element (system, text_spanner_);
110   else
111     text_spanner_->programming_error ("cannot find root system");
112 }
113
114 void
115 Instrument_name_engraver::acknowledge_axis_group (Grob_info info)
116 {
117   if (dynamic_cast<Spanner *> (info.grob ())
118       && Axis_group_interface::has_axis (info.grob (), Y_AXIS)
119
120       /* ugh. */
121
122       && !info.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface"))
123       && !info.grob ()->internal_has_interface (ly_symbol2scm ("piano-pedal-interface"))
124       && !info.grob ()->internal_has_interface (ly_symbol2scm ("volta-interface"))
125       && (!Align_interface::has_interface (info.grob ())))
126     {
127       axis_groups_.push_back (info.grob ());
128     }
129 }
130
131 void
132 Instrument_name_engraver::finalize ()
133 {
134   if (text_spanner_)
135     stop_spanner ();
136 }
137
138 void
139 Instrument_name_engraver::stop_spanner ()
140 {
141   for (vsize i = 0; i < axis_groups_.size (); i++)
142     Pointer_group_interface::add_grob (text_spanner_,
143                                        ly_symbol2scm ("elements"),
144                                        axis_groups_[i]);
145   
146   text_spanner_->set_bound (RIGHT,
147                             unsmob_grob (get_property ("currentCommandColumn")));
148
149   Pointer_group_interface::set_ordered (text_spanner_,
150                                         ly_symbol2scm ("elements"),
151                                         false);
152
153   text_spanner_ = 0;
154 }
155
156
157 ADD_ACKNOWLEDGER (Instrument_name_engraver, axis_group);
158
159 ADD_TRANSLATOR (Instrument_name_engraver,
160                 /* doc */
161                 "Create a system start text for instrument or vocal names.",
162                 
163                 /* create */
164                 "InstrumentName ",
165                 
166                 /* read */
167                 "currentCommandColumn "
168                 "instrumentName "
169                 "shortInstrumentName "
170                 "shortVocalName "
171                 "vocalName ",
172
173                 /* write */
174                 ""
175                 );