]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
000058d629622eccb64834e6516d6d124a6a56bd
[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
97 void
98 Instrument_name_engraver::acknowledge_axis_group (Grob_info info)
99 {
100   if (dynamic_cast<Spanner *> (info.grob ())
101       && Axis_group_interface::has_axis (info.grob (), Y_AXIS)
102       && (!Align_interface::has_interface (info.grob ())))
103     {
104       axis_groups_.push_back (info.grob ());
105     }
106 }
107
108 void
109 Instrument_name_engraver::finalize ()
110 {
111   if (text_spanner_)
112     {
113       stop_spanner ();
114     }
115 }
116
117 void
118 Instrument_name_engraver::stop_spanner ()
119 {
120   for (vsize i = 0; i < axis_groups_.size (); i++)
121     Pointer_group_interface::add_grob (text_spanner_, ly_symbol2scm ("elements"), axis_groups_[i]);
122   
123   text_spanner_->set_bound (RIGHT,
124                             unsmob_grob (get_property ("currentCommandColumn")));
125
126   Pointer_group_interface::set_ordered (text_spanner_, ly_symbol2scm ("elements"), false);
127
128   System *system = get_root_system (text_spanner_);
129
130   /*
131     UGH, should handle this in Score_engraver.
132   */
133   if (system)
134     Axis_group_interface::add_element (system, text_spanner_);
135   else
136     text_spanner_->programming_error ("can't find root system");
137
138   text_spanner_ = 0;
139 }
140
141 #include "translator.icc"
142
143 ADD_ACKNOWLEDGER (Instrument_name_engraver, axis_group);
144
145 ADD_TRANSLATOR (Instrument_name_engraver,
146
147                 /* doc */
148                 "Creates a system start text for instrument or vocal names.",
149                 
150                 /* create */
151                 "InstrumentName ",
152                 
153                 /* accept */
154                 "",
155                 
156                 /* read */
157                 "currentCommandColumn "
158                 "shortInstrumentName "
159                 "instrumentName "
160                 "shortVocalName "
161                 "vocalName "
162                 ,
163
164                 /* write */ "");