]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
* lily/text-engraver.cc (process_acknowledged_grobs): use new
[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--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
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"
19
20 class Instrument_name_engraver : public Engraver
21 {
22   Item *text_;
23   Grob *delim_ ;
24   
25   void create_text (SCM s);
26 public:
27   TRANSLATOR_DECLARATIONS(Instrument_name_engraver);
28
29   virtual void initialize ();
30   virtual void acknowledge_grob (Grob_info);
31   virtual void stop_translation_timestep ();
32 };
33
34
35
36 Instrument_name_engraver::Instrument_name_engraver ()
37 {
38   text_ = 0;
39   delim_ =0;
40 }
41
42
43 void
44 Instrument_name_engraver::initialize ()
45 {
46   daddy_trans_->set_property ("instrumentSupport", SCM_EOL); 
47 }
48
49 void
50 Instrument_name_engraver::stop_translation_timestep ()
51 {
52   if (text_)
53     {
54       text_->set_grob_property ("side-support-elements",
55                                 get_property ("instrumentSupport"));
56       typeset_grob (text_);
57       text_ = 0;
58     }
59 }
60
61 void
62 Instrument_name_engraver::create_text (SCM txt)
63 {
64   if (!text_)
65     {
66       text_ = new Item (get_property ("InstrumentName"));
67       
68       if (text_->get_grob_property ("text") != txt)
69         text_->set_grob_property ("text", txt);
70
71       if (new_markup_p (txt))
72         text_->set_grob_property ("molecule-callback", new_markup_brewer());
73       
74       if (delim_)
75         text_->set_parent (delim_, Y_AXIS);
76       
77       announce_grob (text_, SCM_EOL);
78     }
79 }
80
81 void
82 Instrument_name_engraver::acknowledge_grob (Grob_info i)
83 {
84   if (Bar_line::has_interface (i.grob_))
85     {
86       SCM s = get_property ("instrument");
87   
88       if (now_mom () > Moment (0))
89         s = get_property ("instr");
90
91       /*
92         FIXME: use get_markup () to check type.
93       */
94       if (gh_string_p (s) || gh_pair_p (s))
95         create_text (s);
96     }
97
98   if (dynamic_cast<Spanner*> (i.grob_)
99       && i.grob_->internal_has_interface (ly_symbol2scm ("dynamic-interface")))
100     return;
101
102   /*
103     Hang the instrument names on the staves, but not on the alignment
104     groups enclosing that staff. The alignment has no real location,
105     but is only a vehicle for the placement routine it contains, and
106     therefore the location of its refpoint won't be very useful.
107     
108
109     We could also just use stavesFound, but lets keep this working
110     without staffs as well.
111
112   */
113   if (dynamic_cast<Spanner*> (i.grob_)
114       && ((Axis_group_interface::has_interface (i.grob_)
115            && Axis_group_interface::axis_b (i.grob_, Y_AXIS)))
116       && !Align_interface::has_interface (i.grob_))
117     {
118       SCM nl = gh_cons (i.grob_->self_scm (),
119                         get_property ("instrumentSupport"));
120
121       daddy_trans_->set_property ("instrumentSupport", nl);
122     }
123 }
124
125
126
127
128 ENTER_DESCRIPTION(Instrument_name_engraver,
129 /* descr */       " Prints the name of the instrument (specified by "
130 " @code{Staff.instrument} and @code{Staff.instr}) "
131 "at the left of the staff. ",
132 /* creats*/       "InstrumentName",
133 /* accepts */     "",
134 /* acks  */      "bar-line-interface axis-group-interface",
135 /* reads */       "instrument instr",
136 /* write */       "");