2 piano-pedal-engraver.cc -- implement Piano_pedal_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2001 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "musical-request.hh"
13 #include "lily-guile.hh"
14 #include "rhythmic-head.hh"
16 #include "side-position-interface.hh"
17 #include "staff-symbol-referencer.hh"
20 class Piano_pedal_engraver
: public Engraver
23 VIRTUAL_COPY_CONS (Translator
);
24 Piano_pedal_engraver ();
25 ~Piano_pedal_engraver ();
27 virtual void initialize ();
28 virtual bool try_music (Music
*);
29 virtual void stop_translation_timestep ();
30 virtual void start_translation_timestep ();
31 virtual void acknowledge_grob (Grob_info
);
32 virtual void create_grobs ();
38 Span_req
* start_req_l_
;
39 Drul_array
<Span_req
*> req_l_drul_
;
44 Pedal_info
*info_list_
;
47 ADD_THIS_TRANSLATOR (Piano_pedal_engraver
);
49 Piano_pedal_engraver::Piano_pedal_engraver ()
54 Piano_pedal_engraver::initialize ()
56 info_list_
= new Pedal_info
[4];
57 Pedal_info
*p
= info_list_
;
60 char * names
[] = { "Sostenuto", "Sustain", "UnaCorda", 0 };
66 p
->req_l_drul_
[START
] = 0;
67 p
->req_l_drul_
[STOP
] = 0;
75 Piano_pedal_engraver::~Piano_pedal_engraver ()
85 Piano_pedal_engraver::acknowledge_grob (Grob_info info
)
87 for (Pedal_info
*p
= info_list_
; p
&& p
->name_
; p
++)
91 if (Rhythmic_head::has_interface (info
.elem_l_
))
93 Side_position_interface::add_support (p
->item_p_
, info
.elem_l_
);
95 if (Side_position_interface::get_axis (p
->item_p_
) == X_AXIS
96 && !p
->item_p_
->parent_l (Y_AXIS
))
97 p
->item_p_
->set_parent (info
.elem_l_
, Y_AXIS
);
99 if (Stem::has_interface (info
.elem_l_
))
101 Side_position_interface::add_support (p
->item_p_
,info
.elem_l_
);
108 Piano_pedal_engraver::try_music (Music
*m
)
110 if (Span_req
* s
= dynamic_cast<Span_req
*> (m
))
112 for (Pedal_info
*p
= info_list_
; p
->name_
; p
++)
114 if (scm_equal_p (s
->get_mus_property ("span-type"),
115 ly_str02scm (p
->name_
))==SCM_BOOL_T
)
117 p
->req_l_drul_
[s
->get_span_dir ()] = s
;
126 Piano_pedal_engraver::create_grobs ()
128 for (Pedal_info
*p
= info_list_
; p
&& p
->name_
; p
++)
130 if (p
->item_p_
|| ! (p
->req_l_drul_
[STOP
] || p
->req_l_drul_
[START
]))
134 SCM strings
= get_property (("pedal" + String (p
->name_
) + "Strings").ch_C ());
135 if (scm_ilength (strings
) < 3)
138 if (p
->req_l_drul_
[STOP
] && p
->req_l_drul_
[START
])
140 if (!p
->start_req_l_
)
142 p
->req_l_drul_
[STOP
]->origin ()->warning (_f ("can't find start of piano pedal: %s", p
->name_
));
146 s
= gh_cadr (strings
);
148 p
->start_req_l_
= p
->req_l_drul_
[START
];
150 else if (p
->req_l_drul_
[STOP
])
152 if (!p
->start_req_l_
)
154 p
->req_l_drul_
[STOP
]->origin ()->warning (_f ("can't find start of piano pedal: %s", p
->name_
));
158 s
= gh_caddr (strings
);
162 else if (p
->req_l_drul_
[START
])
164 p
->start_req_l_
= p
->req_l_drul_
[START
];
165 s
= gh_car (strings
);
170 String propname
= String (p
->name_
) + "Pedal";
171 p
->item_p_
= new Item (get_property (propname
.ch_C ()));
172 p
->item_p_
->set_grob_property ("text", s
);
174 announce_grob (p
->item_p_
,
175 p
->req_l_drul_
[START
]
176 ? p
->req_l_drul_
[START
]
177 : p
->req_l_drul_
[STOP
]);
179 p
->req_l_drul_
[START
] = 0;
180 p
->req_l_drul_
[STOP
] = 0;
185 Piano_pedal_engraver::stop_translation_timestep ()
188 for (Pedal_info
*p
= info_list_
; p
->name_
; p
++)
190 if (p
->name_
== String ("Sustain"))
191 sustain
= p
->item_p_
;
194 for (Pedal_info
*p
= info_list_
; p
->name_
; p
++)
198 Side_position_interface::add_staff_support (p
->item_p_
);
203 if (p
->name_
!= String ("Sustain"))
207 Side_position_interface::add_support (p
->item_p_
,sustain
);
210 typeset_grob (p
->item_p_
);
217 Piano_pedal_engraver::start_translation_timestep ()
219 for (Pedal_info
*p
= info_list_
; p
->name_
; p
++)
221 p
->req_l_drul_
[STOP
] = 0;
222 p
->req_l_drul_
[START
] = 0;