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