]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
release: 1.3.109
[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 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
17 class Instrument_name_engraver : public Engraver
18 {
19   Item *text_;
20   Grob * delim_ ;
21
22   void create_text (SCM s);
23 public:
24   VIRTUAL_COPY_CONS(Translator);
25   Instrument_name_engraver ();
26
27   virtual void acknowledge_grob (Grob_info);
28   virtual void stop_translation_timestep ();
29 };
30
31 ADD_THIS_TRANSLATOR(Instrument_name_engraver);
32
33 Instrument_name_engraver::Instrument_name_engraver ()
34 {
35   text_ = 0;
36   delim_ =0;
37 }
38
39
40 void
41 Instrument_name_engraver::stop_translation_timestep ()
42 {
43   if (text_)
44     {
45       typeset_grob (text_);
46       text_ = 0;
47     }
48 }
49
50 void
51 Instrument_name_engraver::create_text (SCM txt)
52 {
53   if(!text_)
54     {
55       text_ = new Item (get_property ("InstrumentName"));
56       text_->set_grob_property ("text", txt);
57
58       if (delim_)
59         text_->set_parent (delim_, Y_AXIS);
60
61       announce_grob (text_,0);
62     }
63 }
64
65 void
66 Instrument_name_engraver::acknowledge_grob (Grob_info i)
67 {
68   SCM s = get_property ("instrument");
69   
70   if (now_mom () > Moment (0))
71     s = get_property ("instr");
72
73   if (gh_string_p (s))
74     {
75       if (Bar::has_interface (i.elem_l_))
76         {
77           create_text (s);
78         }
79     }
80
81   if (Align_interface::has_interface (i.elem_l_)
82       && Align_interface::axis  (i.elem_l_) == Y_AXIS      
83       //System_start_delimiter::has_interface (i.elem_l_)
84       && i.origin_trans_l_->daddy_trans_l_ == daddy_trans_l_)
85     {
86       delim_ = i.elem_l_;
87     }
88 }
89
90
91
92