]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
(process_music): kludge: add
[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           Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
57           text_spanner_->set_bound (LEFT,
58                                     unsmob_grob (get_property ("currentCommandColumn")));
59           Axis_group_interface::add_element (col, text_spanner_);
60           text_spanner_->set_property ("text", short_text);
61           text_spanner_->set_property ("long-text", long_text);
62         }
63     }
64 }
65
66 void
67 Instrument_name_engraver::acknowledge_axis_group (Grob_info info)
68 {
69   if (text_spanner_ 
70       && dynamic_cast<Spanner *> (info.grob ())
71       && Axis_group_interface::has_axis (info.grob (), Y_AXIS)
72       && (!Align_interface::has_interface (info.grob ())))
73     {
74       Grob *staff = info.grob();
75       Pointer_group_interface::add_grob (text_spanner_, ly_symbol2scm ("elements"), staff);
76       Side_position_interface::add_support (text_spanner_, staff);
77     }
78 }
79
80 void
81 Instrument_name_engraver::finalize ()
82 {
83   if (text_spanner_)
84     {
85       text_spanner_->set_bound (RIGHT,
86                                 unsmob_grob (get_property ("currentCommandColumn")));
87
88       Pointer_group_interface::set_ordered (text_spanner_, ly_symbol2scm ("elements"), false);
89     }
90 }
91
92 #include "translator.icc"
93
94 ADD_ACKNOWLEDGER (Instrument_name_engraver, axis_group);
95
96 ADD_TRANSLATOR (Instrument_name_engraver,
97
98                 /* doc */
99                 "Creates a system start text for instrument or vocal names.",
100                 
101                 /* create */
102                 "InstrumentName ",
103                 
104                 /* accept */ "",
105                 
106                 /* read */
107                 "vocNam vocalName instrument instr "
108                 "currentCommandColumn",
109
110                 /* write */ "");