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>
10 #include "engraver.hh"
11 #include "text-item.hh"
12 #include "side-position-interface.hh"
13 #include "note-head.hh"
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_
;
26 Line_number_engraver ();
27 VIRTUAL_COPY_CONS (Translator
);
29 virtual void do_pre_move_processing ();
30 virtual void acknowledge_element (Score_element_info
);
31 virtual void process_acknowledged ();
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_
);
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));
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_
);
64 Line_number_engraver::do_pre_move_processing ()
69 Side_position_interface
si (text_item_p_
);
70 for (int i
=0; i
< interesting_
.size (); i
++)
75 s
+= interesting_
[i
].req_l_
->line_number_str ();
79 for (int j
= support_
.size (); j
--; )
81 si
.add_support (support_
[j
]);
85 text_item_p_
->set_elt_property ("text", ly_str02scm (s
.ch_C()));
89 typeset_element (text_item_p_
);
92 interesting_
.clear ();
96 Line_number_engraver::Line_number_engraver ()
101 ADD_THIS_TRANSLATOR(Line_number_engraver
);