]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
* lily/instrument-name-engraver.cc (start_spanner): new
[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 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   start_spanner ();
52 }
53
54 void
55 Instrument_name_engraver::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       text_spanner_ = make_spanner ("InstrumentName", SCM_EOL);
77           
78       Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
79       text_spanner_->set_bound (LEFT, col);
80       text_spanner_->set_property ("text", short_text);
81       text_spanner_->set_property ("long-text", long_text);
82
83       short_text_ = short_text;
84       long_text_ = long_text;
85     }
86 }
87
88 void
89 Instrument_name_engraver::acknowledge_axis_group (Grob_info info)
90 {
91   if (text_spanner_ 
92       && dynamic_cast<Spanner *> (info.grob ())
93       && Axis_group_interface::has_axis (info.grob (), Y_AXIS)
94       && (!Align_interface::has_interface (info.grob ())))
95     {
96       axis_groups_.push_back (info.grob ());
97     }
98 }
99
100 void
101 Instrument_name_engraver::finalize ()
102 {
103   if (text_spanner_)
104     {
105       stop_spanner ();
106     }
107 }
108
109 void
110 Instrument_name_engraver::stop_spanner ()
111 {
112   for (vsize i = 0; i < axis_groups_.size (); i++)
113     Pointer_group_interface::add_grob (text_spanner_, ly_symbol2scm ("elements"), axis_groups_[i]);
114   
115   text_spanner_->set_bound (RIGHT,
116                             unsmob_grob (get_property ("currentCommandColumn")));
117
118   Pointer_group_interface::set_ordered (text_spanner_, ly_symbol2scm ("elements"), false);
119
120   System *system = get_root_system (text_spanner_);
121
122   /*
123     UGH, should handle this in Score_engraver.
124   */
125   if (system)
126     Axis_group_interface::add_element (system, text_spanner_);
127   else
128     text_spanner_->programming_error ("can't find root system");
129
130   text_spanner_ = 0;
131 }
132
133 #include "translator.icc"
134
135 ADD_ACKNOWLEDGER (Instrument_name_engraver, axis_group);
136
137 ADD_TRANSLATOR (Instrument_name_engraver,
138
139                 /* doc */
140                 "Creates a system start text for instrument or vocal names.",
141                 
142                 /* create */
143                 "InstrumentName ",
144                 
145                 /* accept */
146                 "",
147                 
148                 /* read */
149                 "currentCommandColumn "
150                 "shortInstrumentName "
151                 "instrumentName "
152                 "shortVocalName "
153                 "vocalName "
154                 ,
155
156                 /* write */ "");