]> git.donarmstrong.com Git - lilypond.git/blob - lily/line-number-engraver.cc
patch::: 1.3.78.jcn1
[lilypond.git] / lily / line-number-engraver.cc
1 /*   
2   line-number-engraver.cc --  implement  Line_number_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 "side-position-interface.hh"
13 #include "rhythmic-head.hh"
14 #include "stem.hh"
15 #include "note-head.hh"
16
17 /**
18    Annotate output with line numbers. Creates text-items when it
19    catches note heads.  */
20 class Line_number_engraver : public Engraver
21 {
22   Array<Score_element_info> interesting_;
23   Link_array<Score_element> support_;
24   Item * text_item_p_;
25   String last_text_;
26 public:
27   Line_number_engraver ();
28   VIRTUAL_COPY_CONS (Translator);
29 protected:
30   virtual void do_pre_move_processing ();
31   virtual void acknowledge_element (Score_element_info);
32   virtual void process_acknowledged ();
33 };
34
35 void
36 Line_number_engraver::process_acknowledged ()
37 {
38   if (!text_item_p_ && interesting_.size ())
39     {
40       text_item_p_ = new Item (get_property ("basicTextProperties") );
41       Side_position::set_axis (text_item_p_,Y_AXIS);
42       Side_position::set_direction (text_item_p_, UP);
43       text_item_p_->set_parent (interesting_[0].elem_l_, Y_AXIS);
44
45
46       announce_element (text_item_p_, 0);
47     }
48 }
49
50 void
51 Line_number_engraver::acknowledge_element (Score_element_info inf)
52 {
53   if (!inf.req_l_)
54     return ;
55   
56   if ( Note_head::has_interface (inf.elem_l_))
57     {
58       interesting_.push (inf);
59       support_.push (inf.elem_l_);
60     }
61   else if (Stem::has_interface (inf.elem_l_))
62     {
63       support_.push (inf.elem_l_);
64     }
65 }
66
67 void
68 Line_number_engraver::do_pre_move_processing ()
69 {
70   if (text_item_p_)
71     {
72       String s;
73       
74       for (int i=0; i < interesting_.size (); i++)
75         {
76           if (i)
77             s += ",";
78           
79           s += interesting_[i].req_l_->origin ()->line_number_str ();
80           
81         }
82
83       for (int j= support_.size (); j--; )
84         {
85           Side_position::add_support (text_item_p_,support_[j]);
86         }
87       if (s != last_text_)
88         {
89           text_item_p_->set_elt_property ("text", ly_str02scm (s.ch_C()));
90           last_text_ =s;
91         }
92       
93       typeset_element (text_item_p_);
94       text_item_p_ =0;
95     }
96   interesting_.clear ();
97   support_.clear ();
98 }
99
100 Line_number_engraver::Line_number_engraver ()
101 {
102   text_item_p_ =0;
103 }
104
105 ADD_THIS_TRANSLATOR(Line_number_engraver);