2 staff-margin-engraver.cc -- implement Staff_margin_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2000 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "translator.hh"
10 #include "engraver.hh"
12 #include "dimension-cache.hh"
13 #include "directional-element-interface.hh"
14 #include "timing-translator.hh"
15 #include "text-item.hh"
16 #include "side-position-interface.hh"
17 #include "bar-script-engraver.hh"
18 #include "staff-symbol-referencer.hh"
19 #include "staff-symbol.hh"
24 * align over full score
25 * text aligment: left, centred, right
26 * merge with/derive from/add functionality to Bar_script_engraver
30 Hang on left edge of staff to provide suppor for simple items.
32 class Left_edge_item : public Item
35 VIRTUAL_COPY_CONS (Score_element);
39 put (instrument) text to left of line
41 class Staff_margin_engraver : public Engraver
44 VIRTUAL_COPY_CONS (Translator);
45 Staff_margin_engraver ();
48 virtual void do_pre_move_processing ();
49 virtual void acknowledge_element (Score_element_info);
54 Left_edge_item* left_edge_p_;
55 void create_text (SCM);
58 ADD_THIS_TRANSLATOR (Staff_margin_engraver);
61 Staff_margin_engraver::Staff_margin_engraver ()
69 Staff_margin_engraver::acknowledge_element (Score_element_info info)
71 SCM s = get_property ("instrument");
73 if (now_mom () > Moment (0))
74 s = get_property ("instr");
76 //s = ly_str02scm ("HALLO");
78 if (dynamic_cast<Bar*> (info.elem_l_) && gh_string_p (s))
83 Staff_margin_engraver::create_text (SCM text)
87 assert (!left_edge_p_);
88 Left_edge_item* l = new Left_edge_item;
90 l->set_elt_property ("breakable", SCM_BOOL_T);
91 l->set_elt_property ("break-aligned", SCM_BOOL_T);
93 announce_element (Score_element_info (l, 0));
95 Staff_symbol_referencer_interface sl (l);
99 Text_item* t = new Text_item;
101 t->set_elt_property ("self-alignment-Y", gh_int2scm (0));
102 t->add_offset_callback (Side_position_interface::aligned_on_self, Y_AXIS);
104 t->set_parent (l, X_AXIS);
105 t->set_parent (l, Y_AXIS);
107 // 'just to be sure': see Clef_item::do_add_processing
108 l->add_dependency (t);
113 In almost every score that uses "instrument" and "instr"
114 we need two different paddings.
115 Let's try one of those first:
116 instrumentScriptPadding/instrScriptPadding
118 SCM s = get_property (String (now_mom () ? "instr" : "instrument")
120 if (!gh_number_p (s))
121 s = get_property (type_ + "ScriptPadding");
125 padding = gh_scm2double (s);
127 s = get_property (type_ + "ScriptTextStyle");
129 t->set_elt_property ("style", s);
131 s = get_property (type_ + "ScriptHorizontalAlignment");
135 if (gh_number_p (s) && !gh_scm2int (s))
137 t->set_elt_property ("self-alignment-X", gh_int2scm (0));
138 t->add_offset_callback (Side_position_interface::aligned_on_self, X_AXIS);
140 % Centred is still broken, it always requires proper padding.
144 t->translate_axis (padding, X_AXIS);
147 left or right alignment.
151 side_position (t).set_axis (X_AXIS);
152 side_position (t).add_support (l);
158 By default, align at left edge of Left_edge_item,
159 (which makes text right-aligned)
160 so that we don't collide with staff.
165 directional_element (t).set (d);
168 t->set_elt_property ("padding", gh_double2scm (padding));
172 announce_element (Score_element_info (t, 0));
177 text_p_->set_elt_property ("text", text);
181 Staff_margin_engraver::do_pre_move_processing ()
186 Let's not allow user settings for visibility function (yet).
187 Although end-of-line would work, to some extent, we should
188 make a properly ordered Right_edge_item, if that need arises.
190 text_p_->set_elt_property("visibility-lambda",
191 ly_eval_str ("begin-of-line-visible"));
192 typeset_element (text_p_);
194 assert (left_edge_p_);
195 typeset_element (left_edge_p_);