]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
patch::: 1.3.126.jcn1
[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       
57       if (text_->get_grob_property ("text") != txt)
58         text_->set_grob_property ("text", txt);
59      
60       if (delim_)
61         text_->set_parent (delim_, Y_AXIS);
62       
63       announce_grob (text_,0);
64     }
65 }
66
67 void
68 Instrument_name_engraver::acknowledge_grob (Grob_info i)
69 {
70   if (Bar::has_interface (i.elem_l_))
71     {
72       SCM s = get_property ("instrument");
73   
74       if (now_mom () > Moment (0))
75         s = get_property ("instr");
76
77       /*
78         FIXME: use markup_p () to check type.
79       */
80       if (gh_string_p (s) || gh_pair_p (s))
81         create_text (s);
82           
83     }
84
85   if (Align_interface::has_interface (i.elem_l_)
86       && Align_interface::axis  (i.elem_l_) == Y_AXIS      
87       //System_start_delimiter::has_interface (i.elem_l_)
88       && i.origin_trans_l_->daddy_trans_l_ == daddy_trans_l_)
89     {
90       delim_ = i.elem_l_;
91     }
92 }
93
94
95
96