]> git.donarmstrong.com Git - lilypond.git/blob - lily/line-number-engraver.cc
release: 1.3.69
[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 (Score_element_info (text_item_p_, 0));
47     }
48 }
49
50 void
51 Line_number_engraver::acknowledge_element (Score_element_info inf)
52 {
53   if (Note_head::has_interface (inf.elem_l_))
54     {
55       interesting_.push (inf);
56       support_.push (inf.elem_l_);
57     }
58   else if (Stem::has_interface (inf.elem_l_))
59     {
60       support_.push (inf.elem_l_);
61     }
62 }
63
64 void
65 Line_number_engraver::do_pre_move_processing ()
66 {
67   if (text_item_p_)
68     {
69       String s;
70       
71       for (int i=0; i < interesting_.size (); i++)
72         {
73           if (i)
74             s += ",";
75           
76           s += interesting_[i].req_l_->line_number_str ();
77           
78         }
79
80       for (int j= support_.size (); j--; )
81         {
82           Side_position::add_support (text_item_p_,support_[j]);
83         }
84       if (s != last_text_)
85         {
86           text_item_p_->set_elt_property ("text", ly_str02scm (s.ch_C()));
87           last_text_ =s;
88         }
89       
90       typeset_element (text_item_p_);
91       text_item_p_ =0;
92     }
93   interesting_.clear ();
94   support_.clear ();
95 }
96
97 Line_number_engraver::Line_number_engraver ()
98 {
99   text_item_p_ =0;
100 }
101
102 ADD_THIS_TRANSLATOR(Line_number_engraver);