lilypond-1.3.31
[lilypond.git] / lily / line-number-engraver.cc
blobfc9f6393674990a03f940744b49ffa3f8fb2031d
1 /*
2 line-number-engraver.cc -- implement Line_number_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "engraver.hh"
11 #include "text-item.hh"
12 #include "side-position-interface.hh"
13 #include "note-head.hh"
14 #include "stem.hh"
16 /**
17 Annotate output with line numbers. Creates text-items when it
18 catches note heads. */
19 class Line_number_engraver : public Engraver
21 Array<Score_element_info> interesting_;
22 Link_array<Score_element> support_;
23 Item * text_item_p_;
24 String last_text_;
25 public:
26 Line_number_engraver ();
27 VIRTUAL_COPY_CONS (Translator);
28 protected:
29 virtual void do_pre_move_processing ();
30 virtual void acknowledge_element (Score_element_info);
31 virtual void process_acknowledged ();
34 void
35 Line_number_engraver::process_acknowledged ()
37 if (!text_item_p_ && interesting_.size ())
39 text_item_p_ = new Text_item;
40 Side_position_interface si (text_item_p_);
41 si.set_axis (Y_AXIS);
42 text_item_p_->set_parent (interesting_[0].elem_l_, Y_AXIS);
44 si.set_direction (UP);
45 announce_element (Score_element_info (text_item_p_, 0));
49 void
50 Line_number_engraver::acknowledge_element (Score_element_info inf)
52 if (dynamic_cast<Note_head*> (inf.elem_l_))
54 interesting_.push (inf);
55 support_.push (inf.elem_l_);
57 if (dynamic_cast<Stem*> (inf.elem_l_))
59 support_.push (inf.elem_l_);
63 void
64 Line_number_engraver::do_pre_move_processing ()
66 if (text_item_p_)
68 String s;
69 Side_position_interface si (text_item_p_);
70 for (int i=0; i < interesting_.size (); i++)
72 if (i)
73 s += ",";
75 s += interesting_[i].req_l_->line_number_str ();
79 for (int j= support_.size (); j--; )
81 si.add_support (support_[j]);
83 if (s != last_text_)
85 text_item_p_->set_elt_property ("text", ly_str02scm (s.ch_C()));
86 last_text_ =s;
89 typeset_element (text_item_p_);
90 text_item_p_ =0;
92 interesting_.clear ();
93 support_.clear ();
96 Line_number_engraver::Line_number_engraver ()
98 text_item_p_ =0;
101 ADD_THIS_TRANSLATOR(Line_number_engraver);