2 piano-pedal-engraver.cc -- implement Piano_pedal_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "musical-request.hh"
11 #include "score-element.hh"
14 #include "lily-guile.hh"
15 #include "rhythmic-head.hh"
17 #include "side-position-interface.hh"
18 #include "staff-symbol-referencer.hh"
24 * it would be really cool if an engraver could be initialised with a
27 Piano_pedal_engraver::"sostenuto"
28 Piano_pedal_engraver::"sustain"
29 Piano_pedal_engraver::"una-chorda"
34 Would it? The semantics are unclear, and real benefits are muddy
41 engrave Piano pedals symbols.
43 class Piano_pedal_engraver
: public Engraver
46 VIRTUAL_COPY_CONS (Translator
);
47 Piano_pedal_engraver ();
48 ~Piano_pedal_engraver ();
50 virtual void do_creation_processing ();
51 virtual bool do_try_music (Music
*);
52 virtual void do_process_music ();
53 virtual void do_pre_move_processing ();
54 virtual void do_post_move_processing ();
55 virtual void acknowledge_element (Score_element_info
);
61 Span_req
* start_req_l_
;
62 Drul_array
<Span_req
*> req_l_drul_
;
67 Pedal_info
*info_list_
;
70 ADD_THIS_TRANSLATOR (Piano_pedal_engraver
);
72 Piano_pedal_engraver::Piano_pedal_engraver ()
77 Piano_pedal_engraver::do_creation_processing()
79 info_list_
= new Pedal_info
[4];
80 Pedal_info
*p
= info_list_
;
83 char * names
[] = { "Sostenuto", "Sustain", "UnaChorda", 0 };
89 p
->req_l_drul_
[START
] = 0;
90 p
->req_l_drul_
[STOP
] = 0;
98 Piano_pedal_engraver::~Piano_pedal_engraver()
108 Piano_pedal_engraver::acknowledge_element (Score_element_info info
)
110 for (Pedal_info
*p
= info_list_
; p
->name_
; p
++)
114 if (Rhythmic_head::has_interface (info
.elem_l_
))
116 Side_position::add_support (p
->item_p_
, info
.elem_l_
);
118 if (Side_position::get_axis(p
->item_p_
) == X_AXIS
119 && !p
->item_p_
->parent_l (Y_AXIS
))
120 p
->item_p_
->set_parent (info
.elem_l_
, Y_AXIS
);
122 if (Stem::has_interface (info
.elem_l_
))
124 Side_position::add_support (p
->item_p_
,info
.elem_l_
);
131 Piano_pedal_engraver::do_try_music (Music
*m
)
133 if (Span_req
* s
= dynamic_cast<Span_req
*>(m
))
135 for (Pedal_info
*p
= info_list_
; p
->name_
; p
++)
137 if (s
->span_type_str_
== p
->name_
)
139 p
->req_l_drul_
[s
->span_dir_
] = s
;
148 Piano_pedal_engraver::do_process_music ()
150 for (Pedal_info
*p
= info_list_
; p
->name_
; p
++)
152 SCM s
= SCM_UNDEFINED
;
153 if (p
->req_l_drul_
[STOP
] && p
->req_l_drul_
[START
])
155 if (!p
->start_req_l_
)
157 p
->req_l_drul_
[STOP
]->warning (_f ("can't find start of piano pedal: %s", p
->name_
));
161 s
= get_property (("stopStart" + String (p
->name_
)).ch_C());
163 p
->start_req_l_
= p
->req_l_drul_
[START
];
165 else if (p
->req_l_drul_
[STOP
])
167 if (!p
->start_req_l_
)
169 p
->req_l_drul_
[STOP
]->warning (_f ("can't find start of piano pedal: %s", p
->name_
));
173 s
= get_property (("stop" + String (p
->name_
)).ch_C());
177 else if (p
->req_l_drul_
[START
])
179 p
->start_req_l_
= p
->req_l_drul_
[START
];
180 s
= get_property (("start" + String (p
->name_
)).ch_C());
185 if (p
->name_
== String ("Sustain"))
187 // fixme: Item should be sufficient.
188 p
->item_p_
= new Item (get_property ("basicSustainPedalProperties"));
192 p
->item_p_
= new Item (get_property ("basicPedalProperties"));
194 p
->item_p_
->set_elt_property ("text", s
);
197 Side_position::set_axis (p
->item_p_
,Y_AXIS
);
199 // todo: init with basic props.
200 p
->item_p_
->add_offset_callback (Side_position::aligned_on_self
, X_AXIS
);
201 p
->item_p_
->add_offset_callback (Side_position::centered_on_parent
, X_AXIS
);
202 announce_element (Score_element_info (p
->item_p_
,
203 p
->req_l_drul_
[START
]
204 ? p
->req_l_drul_
[START
]
205 : p
->req_l_drul_
[STOP
]));
211 Piano_pedal_engraver::do_pre_move_processing ()
214 for (Pedal_info
*p
= info_list_
; p
->name_
; p
++)
216 if (p
->name_
== String ("Sustain"))
217 sustain
= p
->item_p_
;
220 for (Pedal_info
*p
= info_list_
; p
->name_
; p
++)
224 Side_position::add_staff_support (p
->item_p_
);
228 if (p
->name_
!= String ("Sustain"))
232 Side_position::add_support (p
->item_p_
,sustain
);
235 typeset_element (p
->item_p_
);
242 Piano_pedal_engraver::do_post_move_processing ()
244 for (Pedal_info
*p
= info_list_
; p
->name_
; p
++)
246 p
->req_l_drul_
[STOP
] = 0;
247 p
->req_l_drul_
[START
] = 0;