]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
* lily/simple-spacer.cc (get_line_configuration): 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 #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   virtual void finalize ();
29   DECLARE_ACKNOWLEDGER (axis_group);
30   void process_music ();
31 };
32
33 Instrument_name_engraver::Instrument_name_engraver ()
34 {
35   text_spanner_ = 0;
36 }
37
38 void
39 Instrument_name_engraver::process_music ()
40 {
41   if (!text_spanner_)
42     {
43       SCM long_text = get_property ("instrument");
44       SCM short_text = get_property ("instr");
45
46       if (!(Text_interface::is_markup (long_text)
47             || Text_interface::is_markup (short_text)))
48         {
49           long_text = get_property ("vocalName");
50           short_text = get_property ("vocNam");
51         }
52   
53       if (Text_interface::is_markup (long_text)
54           || Text_interface::is_markup (short_text))
55         {
56           text_spanner_ = make_spanner ("InstrumentName", SCM_EOL);
57           
58           Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
59           text_spanner_->set_bound (LEFT, col);
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     }
77 }
78
79 void
80 Instrument_name_engraver::finalize ()
81 {
82   if (text_spanner_)
83     {
84       text_spanner_->set_bound (RIGHT,
85                                 unsmob_grob (get_property ("currentCommandColumn")));
86
87       Pointer_group_interface::set_ordered (text_spanner_, ly_symbol2scm ("elements"), false);
88
89       System *system = get_root_system (text_spanner_);
90
91       /*
92         UGH, should handle this in Score_engraver.
93        */
94       if (system)
95         Axis_group_interface::add_element (system, text_spanner_);
96       else
97         text_spanner_->programming_error ("can't find root system");
98     }
99 }
100
101 #include "translator.icc"
102
103 ADD_ACKNOWLEDGER (Instrument_name_engraver, axis_group);
104
105 ADD_TRANSLATOR (Instrument_name_engraver,
106
107                 /* doc */
108                 "Creates a system start text for instrument or vocal names.",
109                 
110                 /* create */
111                 "InstrumentName ",
112                 
113                 /* accept */
114                 "",
115                 
116                 /* read */
117                 "vocNam vocalName instrument instr "
118                 "currentCommandColumn",
119
120                 /* write */ "");