]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
0f5e9bbbd1259fd3b40fb0c6d9e9b226e061a408
[lilypond.git] / lily / instrument-name-engraver.cc
1 /*   
2   new-staff-margin-engraver.cc --  implement Instrument_name_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2000--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "engraver.hh"
11 #include "item.hh"
12 #include "bar.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
19 class Instrument_name_engraver : public Engraver
20 {
21   Item *text_;
22   Grob *delim_ ;
23   
24   void create_text (SCM s);
25 public:
26   TRANSLATOR_DECLARATIONS(Instrument_name_engraver);
27
28   virtual void initialize ();
29   virtual void acknowledge_grob (Grob_info);
30   virtual void stop_translation_timestep ();
31 };
32
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_l_->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 (SCM txt)
62 {
63   if (!text_)
64     {
65       text_ = new Item (get_property ("InstrumentName"));
66       
67       if (text_->get_grob_property ("text") != txt)
68         text_->set_grob_property ("text", txt);
69      
70       if (delim_)
71         text_->set_parent (delim_, Y_AXIS);
72       
73       announce_grob (text_,0);
74     }
75 }
76
77 void
78 Instrument_name_engraver::acknowledge_grob (Grob_info i)
79 {
80   if (Bar::has_interface (i.grob_l_))
81     {
82       SCM s = get_property ("instrument");
83   
84       if (now_mom () > Moment (0))
85         s = get_property ("instr");
86
87       /*
88         FIXME: use markup_p () to check type.
89       */
90       if (gh_string_p (s) || gh_pair_p (s))
91         create_text (s);
92     }
93
94   if (dynamic_cast<Spanner*> (i.grob_l_)
95       && i.grob_l_->has_interface (ly_symbol2scm ("dynamic-interface")))
96     return;
97
98   /*
99     Hang the instrument names on the staves, but not on the alignment
100     groups enclosing that staff. The alignment has no real location,
101     but is only a vehicle for the placement routine it contains, and
102     therefore the location of its refpoint won't be very useful.
103     
104   */
105   if (dynamic_cast<Spanner*> (i.grob_l_)
106       && ((Axis_group_interface::has_interface (i.grob_l_)
107            && Axis_group_interface::axis_b (i.grob_l_, Y_AXIS)))
108       && !Align_interface::has_interface (i.grob_l_))
109     {
110       SCM nl = gh_cons (i.grob_l_->self_scm (),
111                         get_property ("instrumentSupport"));
112
113       daddy_trans_l_->set_property ("instrumentSupport", nl);
114     }
115 }
116
117
118
119
120 ENTER_DESCRIPTION(Instrument_name_engraver,
121 /* descr */       " Prints the name of the instrument (specified by
122 @code{Staff.instrument} and @code{Staff.instr})
123 at the left of the
124 staff.",
125 /* creats*/       "InstrumentName",
126 /* acks  */       "bar-line-interface axis-group-interface",
127 /* reads */       "instrument instr",
128 /* write */       "");