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