]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
* lily/parenthesis-engraver.cc (acknowledge_grob): don't do
[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
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   virtual void finalize ();
28   DECLARE_ACKNOWLEDGER (axis_group);
29   void process_music ();
30 };
31
32 Instrument_name_engraver::Instrument_name_engraver ()
33 {
34   text_spanner_ = 0;
35 }
36
37 void
38 Instrument_name_engraver::process_music ()
39 {
40   if (!text_spanner_)
41     {
42       SCM long_text = get_property ("instrument");
43       SCM short_text = get_property ("instr");
44
45       if (!(Text_interface::is_markup (long_text)
46             || Text_interface::is_markup (short_text)))
47         {
48           long_text = get_property ("vocalName");
49           short_text = get_property ("vocNam");
50         }
51   
52       if (Text_interface::is_markup (long_text)
53           || Text_interface::is_markup (short_text))
54         {
55           text_spanner_ = make_spanner ("InstrumentName", SCM_EOL);
56           text_spanner_->set_bound (LEFT,
57                                     unsmob_grob (get_property ("currentCommandColumn")));
58           text_spanner_->set_property ("text", short_text);
59           text_spanner_->set_property ("long-text", long_text);
60         }
61     }
62 }
63
64 void
65 Instrument_name_engraver::acknowledge_axis_group (Grob_info info)
66 {
67   if (text_spanner_ 
68       && dynamic_cast<Spanner *> (info.grob ())
69       && Axis_group_interface::has_axis (info.grob (), Y_AXIS)
70       && (!Align_interface::has_interface (info.grob ())))
71     {
72       Grob *staff = info.grob();
73       Pointer_group_interface::add_grob (text_spanner_, ly_symbol2scm ("elements"), staff);
74       Side_position_interface::add_support (text_spanner_, staff);
75     }
76 }
77
78 void
79 Instrument_name_engraver::finalize ()
80 {
81   if (text_spanner_)
82     {
83       text_spanner_->set_bound (RIGHT,
84                                 unsmob_grob (get_property ("currentCommandColumn")));
85     }
86 }
87
88 #include "translator.icc"
89
90 ADD_ACKNOWLEDGER (Instrument_name_engraver, axis_group);
91
92 ADD_TRANSLATOR (Instrument_name_engraver,
93
94                 /* doc */
95                 "Creates a system start text for instrument or vocal names.",
96                 
97                 /* create */
98                 "InstrumentName ",
99                 
100                 /* accept */ "",
101                 
102                 /* read */
103                 "vocNam vocalName instrument instr "
104                 "currentCommandColumn",
105
106                 /* write */ "");