(staff_eligible): new function.
[lilypond.git] / lily / instrument-name-engraver.cc
blob40dcbca8461cdc1a3ef07c8aa6592f41ca8553df
1 /*
2 instrument-name-engraver.cc -- implement Instrument_name_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "engraver.hh"
11 #include "item.hh"
12 #include "bar-line.hh"
13 #include "system-start-delimiter.hh"
14 #include "side-position-interface.hh"
15 #include "align-interface.hh"
16 #include "axis-group-interface.hh"
17 #include "translator-group.hh"
18 #include "text-item.hh"
20 class Instrument_name_engraver : public Engraver
22 Item *text_;
23 Grob *delim_ ;
25 void create_text ();
26 public:
27 TRANSLATOR_DECLARATIONS(Instrument_name_engraver);
29 virtual void initialize ();
30 virtual void acknowledge_grob (Grob_info);
31 virtual void stop_translation_timestep ();
32 virtual void process_music ();
37 Instrument_name_engraver::Instrument_name_engraver ()
39 text_ = 0;
40 delim_ =0;
44 void
45 Instrument_name_engraver::initialize ()
47 daddy_trans_->set_property ("instrumentSupport", SCM_EOL);
50 void
51 Instrument_name_engraver::stop_translation_timestep ()
53 if (text_)
55 text_->set_grob_property ("side-support-elements",
56 get_property ("instrumentSupport"));
57 typeset_grob (text_);
58 text_ = 0;
62 void
63 Instrument_name_engraver::create_text ()
65 if (!text_)
67 SCM txt = get_property ("instrument");
69 if (now_mom () > Moment (0))
70 txt = get_property ("instr");
72 UGH.
74 if (txt == SCM_EOL)
75 return ;
77 text_ = new Item (get_property ("InstrumentName"));
79 if (text_->get_grob_property ("text") != txt)
80 text_->set_grob_property ("text", txt);
82 if (delim_)
83 text_->set_parent (delim_, Y_AXIS);
85 announce_grob (text_, SCM_EOL);
89 void
90 Instrument_name_engraver::acknowledge_grob (Grob_info i)
92 if (Bar_line::has_interface (i.grob_))
94 create_text();
97 if (dynamic_cast<Spanner*> (i.grob_)
98 && i.grob_->internal_has_interface (ly_symbol2scm ("dynamic-interface")))
99 return;
102 Hang the instrument names on the staves, but not on the alignment
103 groups enclosing that staff. The alignment has no real location,
104 but is only a vehicle for the placement routine it contains, and
105 therefore the location of its refpoint won't be very useful.
107 We could also just use stavesFound, but lets keep this working
108 without staffs as well.
110 if (dynamic_cast<Spanner*> (i.grob_)
111 && ((Axis_group_interface::has_interface (i.grob_)
112 && Axis_group_interface::axis_b (i.grob_, Y_AXIS)))
113 && !Align_interface::has_interface (i.grob_))
115 SCM nl = gh_cons (i.grob_->self_scm (),
116 get_property ("instrumentSupport"));
118 daddy_trans_->set_property ("instrumentSupport", nl);
122 void
123 Instrument_name_engraver::process_music ()
126 Also create text if barlines in other groups. This allows
127 a name to be attached to lyrics or chords.
129 if (gh_string_p (get_property ("whichBar")))
130 create_text();
133 ENTER_DESCRIPTION(Instrument_name_engraver,
134 /* descr */ " Prints the name of the instrument (specified by "
135 " @code{Staff.instrument} and @code{Staff.instr}) "
136 "at the left of the staff. ",
137 /* creats*/ "InstrumentName",
138 /* accepts */ "",
139 /* acks */ "bar-line-interface axis-group-interface",
140 /* reads */ "instrument instr",
141 /* write */ "");