]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
release: 1.3.115
[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 /*
51   FIXME: use different mechanics, and use a markup-p function?
52  */
53 void
54 Instrument_name_engraver::create_text (SCM txt)
55 {
56   if(!text_)
57     {
58       text_ = new Item (get_property ("InstrumentName"));
59       if (txt != SCM_EOL)
60         {
61           text_->set_grob_property ("text", txt);
62         }
63       else if (text_->get_grob_property ("text") == SCM_EOL)
64         {
65           return;
66         }
67       if (delim_)
68         text_->set_parent (delim_, Y_AXIS);
69       
70       announce_grob (text_,0);
71     }
72 }
73
74 void
75 Instrument_name_engraver::acknowledge_grob (Grob_info i)
76 {
77   if (Bar::has_interface (i.elem_l_))
78     {
79       SCM s = get_property ("instrument");
80   
81       if (now_mom () > Moment (0))
82         s = get_property ("instr");
83
84       //      if (gh_string_p (s))
85       //        {
86           create_text (s);
87           //    }
88     }
89
90   if (Align_interface::has_interface (i.elem_l_)
91       && Align_interface::axis  (i.elem_l_) == Y_AXIS      
92       //System_start_delimiter::has_interface (i.elem_l_)
93       && i.origin_trans_l_->daddy_trans_l_ == daddy_trans_l_)
94     {
95       delim_ = i.elem_l_;
96     }
97 }
98
99
100
101