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