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