]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
Merge with git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond.git
[lilypond.git] / lily / instrument-name-engraver.cc
1 /*
2   instrument-name-engraver.cc -- implement Instrument_name_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "engraver.hh"
10 #include "spanner.hh"
11 #include "pointer-group-interface.hh"
12 #include "side-position-interface.hh"
13 #include "axis-group-interface.hh"
14 #include "align-interface.hh"
15 #include "text-interface.hh"
16 #include "system.hh"
17
18 #include "translator.icc"
19
20 class Instrument_name_engraver : public Engraver
21 {
22 public:
23   TRANSLATOR_DECLARATIONS (Instrument_name_engraver);
24
25 protected:
26   Spanner *text_spanner_;
27
28   SCM long_text_;
29   SCM short_text_;
30
31   vector<Grob*> axis_groups_;
32   
33   virtual void finalize ();
34   DECLARE_ACKNOWLEDGER (axis_group);
35   void process_music ();
36   void start_spanner ();
37   void consider_start_spanner ();
38   void stop_spanner ();
39 };
40
41 Instrument_name_engraver::Instrument_name_engraver ()
42 {
43   text_spanner_ = 0;
44
45   long_text_ = SCM_EOL;
46   short_text_ = SCM_EOL;
47 }
48
49 void
50 Instrument_name_engraver::process_music ()
51 {
52   consider_start_spanner ();
53 }
54
55 void
56 Instrument_name_engraver::consider_start_spanner ()
57 {
58   SCM long_text = get_property ("instrumentName");
59   SCM short_text = get_property ("shortInstrumentName");
60
61   if (!(Text_interface::is_markup (long_text)
62         || Text_interface::is_markup (short_text)))
63     {
64       long_text = get_property ("vocalName");
65       short_text = get_property ("shortVocalName");
66     }
67   
68   if ((Text_interface::is_markup (long_text)
69        || Text_interface::is_markup (short_text))
70       && (!text_spanner_
71           || short_text_ != short_text
72           || long_text_ != long_text))
73     {
74       if (text_spanner_)
75         stop_spanner ();
76
77       
78       short_text_ = short_text;
79       long_text_ = long_text;
80
81       start_spanner ();
82     }
83 }
84
85 void
86 Instrument_name_engraver::start_spanner ()
87 {
88   text_spanner_ = make_spanner ("InstrumentName", SCM_EOL);
89           
90   Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
91   text_spanner_->set_bound (LEFT, col);
92   text_spanner_->set_property ("text", short_text_);
93   text_spanner_->set_property ("long-text", long_text_);
94
95   /*
96     UGH, should handle this in Score_engraver.
97   */
98   Grob *system = unsmob_grob (get_property ("rootSystem"));
99   if (system)
100     Axis_group_interface::add_element (system, text_spanner_);
101   else
102     text_spanner_->programming_error ("can't find root system");
103 }
104
105
106 void
107 Instrument_name_engraver::acknowledge_axis_group (Grob_info info)
108 {
109   if (dynamic_cast<Spanner *> (info.grob ())
110       && Axis_group_interface::has_axis (info.grob (), Y_AXIS)
111
112       /* ugh. */
113
114       && !info.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface"))
115       && !info.grob ()->internal_has_interface (ly_symbol2scm ("piano-pedal-interface"))
116       && (!Align_interface::has_interface (info.grob ())))
117     {
118       axis_groups_.push_back (info.grob ());
119     }
120 }
121
122 void
123 Instrument_name_engraver::finalize ()
124 {
125   if (text_spanner_)
126     {
127       stop_spanner ();
128     }
129 }
130
131 void
132 Instrument_name_engraver::stop_spanner ()
133 {
134   for (vsize i = 0; i < axis_groups_.size (); i++)
135     Pointer_group_interface::add_grob (text_spanner_, ly_symbol2scm ("elements"), axis_groups_[i]);
136   
137   text_spanner_->set_bound (RIGHT,
138                             unsmob_grob (get_property ("currentCommandColumn")));
139
140   Pointer_group_interface::set_ordered (text_spanner_, ly_symbol2scm ("elements"), false);
141
142   text_spanner_ = 0;
143 }
144
145 #include "translator.icc"
146
147 ADD_ACKNOWLEDGER (Instrument_name_engraver, axis_group);
148
149 ADD_TRANSLATOR (Instrument_name_engraver,
150
151                 /* doc */
152                 "Creates a system start text for instrument or vocal names.",
153                 
154                 /* create */
155                 "InstrumentName ",
156                 
157                 /* read */
158                 "currentCommandColumn "
159                 "shortInstrumentName "
160                 "instrumentName "
161                 "shortVocalName "
162                 "vocalName "
163                 ,
164
165                 /* write */ "");