]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
Fix some bugs in the dynamic engraver and PostScript backend
[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       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       System *system = get_root_system (text_spanner_);
91
92       /*
93         UGH, should handle this in Score_engraver.
94        */
95       if (system)
96         Axis_group_interface::add_element (system, text_spanner_);
97       else
98         text_spanner_->programming_error ("can't find root system");
99     }
100 }
101
102 #include "translator.icc"
103
104 ADD_ACKNOWLEDGER (Instrument_name_engraver, axis_group);
105
106 ADD_TRANSLATOR (Instrument_name_engraver,
107
108                 /* doc */
109                 "Creates a system start text for instrument or vocal names.",
110                 
111                 /* create */
112                 "InstrumentName ",
113                 
114                 /* accept */
115                 "",
116                 
117                 /* read */
118                 "vocNam vocalName instrument instr "
119                 "currentCommandColumn",
120
121                 /* write */ "");