/*
crescendo.cc -- implement Crescendo
- source file of the LilyPond music typesetter
+ source file of the GNU LilyPond music typesetter
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+ (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
-#include "dimen.hh"
+
+#include "molecule.hh"
#include "crescendo.hh"
+#include "spanner.hh"
#include "lookup.hh"
+#include "dimensions.hh"
#include "paper-def.hh"
#include "debug.hh"
-Crescendo::Crescendo(int s)
-{
- staff_size_i_ = s;
- grow_dir_i_ =0;
- dir_i_ = -1 ;
- left_dyn_b_ = right_dyn_b_ =false;
-}
+#include "paper-column.hh"
-Spanner*
-Crescendo::do_break_at(PCol*, PCol*)const
+void
+Crescendo::set_interface (Score_element*s)
{
- return new Crescendo(*this);
+ s->set_elt_pointer ("dynamic-drul", gh_cons (SCM_UNDEFINED, SCM_UNDEFINED));
}
-Molecule*
-Crescendo::brew_molecule_p() const return m_p ;
+
+MAKE_SCHEME_SCORE_ELEMENT_CALLBACK(Crescendo,brew_molecule);
+SCM
+Crescendo::brew_molecule (SCM smob)
{
- Real x_off_dim=0.0;
- Real absdyn_dim = 10 PT; // UGR
-
- m_p = new Molecule;
- Real w_dim = width().length();
- if ( left_dyn_b_ ) {
- w_dim -= absdyn_dim;
- x_off_dim += absdyn_dim;
- }
- if ( right_dyn_b_ ) {
- w_dim -= absdyn_dim;
- }
-
- if (w_dim < 0) {
- error("Crescendo too small");
- w_dim = 0;
- }
- Symbol s( paper()->lookup_l()->hairpin(w_dim, grow_dir_i_ < 0) );
- m_p->add(Atom(s));
- int pos = (dir_i_ >0) ? staff_size_i_ + 4 : - 4 ;
- if(dir_i_<0 ) // should do something better anyway.
- m_p->translate(Offset(0, -m_p->extent().y.left ));
- m_p->translate(Offset(x_off_dim,pos * paper()->internote()));
+ Score_element *me= unsmob_element (smob);
+ Spanner * sp = dynamic_cast<Spanner*>(me);
+ Real absdyn_dim = me->paper_l ()-> get_var ("crescendo_shorten");
+ Real extra_left = sp->get_broken_left_end_align ();
+
+ SCM dir = me->get_elt_property("grow-direction");
+ SCM dyns = me->get_elt_property ("dynamic-drul");
+
+ if (!isdir_b (dir) || !gh_pair_p (dyns))
+ {
+ me->suicide ();
+ return SCM_EOL;
+ }
+
+ Direction gd = to_dir (dir);
+
+ bool dynleft= unsmob_element (gh_car (dyns));
+ bool dynright = unsmob_element (gh_cdr (dyns));
+
+ if (dynleft)
+ extra_left += absdyn_dim;
+
+ Real width = sp->spanner_length()- sp->get_broken_left_end_align ();
+
+ if (dynleft)
+ {
+ width -= absdyn_dim;
+ }
+ if (dynright)
+ {
+ width -= absdyn_dim;
+ }
+
+ if (width < 0)
+ {
+ warning (_ ("crescendo") + " " + _ ("too small"));
+ width = 0;
+ }
+
+ Drul_array<bool> broken;
+ Direction d = LEFT;
+ do
+ {
+ Paper_column* s = dynamic_cast<Paper_column*>(sp->get_bound (d)); // UGH
+ broken[d] = (!s->musical_b ());
+ }
+ while (flip (&d) != LEFT);
+
+
+ Molecule m;
+
+ Real pad = 0;
+ SCM s = me->get_elt_property ("start-text");
+ if (gh_string_p (s))
+ {
+ Molecule start_text (me->lookup_l ()->text ("italic",
+ ly_scm2string (s),
+ me->paper_l ()));
+ m.add_molecule (start_text);
+
+ pad = me->paper_l ()->get_var ("interline") / 2;
+
+ width -= start_text.extent (X_AXIS).length ();
+ width -= pad;
+ width = width >? 0;
+ }
+
+ SCM at;
+ s =me->get_elt_property ("spanner");
+ Real height;
+ if (gh_string_p (s) && ly_scm2string (s) == "dashed-line")
+ {
+ Real thick = me->paper_l ()->get_var ("crescendo_dash_thickness");
+ Real dash = me->paper_l ()->get_var ("crescendo_dash");
+ height = thick;
+ at = gh_list (ly_symbol2scm (ly_scm2string (s).ch_C ()),
+ gh_double2scm (thick),
+ gh_double2scm (dash),
+ gh_double2scm (width),
+ SCM_UNDEFINED);
+ }
+ else
+ {
+ bool continued = broken[Direction (-gd)];
+ height = me->paper_l()->get_var ("crescendo_height");
+ Real thick = me->paper_l ()->get_var ("crescendo_thickness");
+
+ const char* hairpin = (gd < 0)? "decrescendo" : "crescendo";
+
+ at = gh_list (ly_symbol2scm (hairpin),
+ gh_double2scm (thick),
+ gh_double2scm (width),
+ gh_double2scm (height),
+ gh_double2scm (continued ? height/2 : 0.0),
+ SCM_UNDEFINED);
+ }
+ Box b (Interval (0, width), Interval (-2*height, 2*height));
+ Molecule span (b, at);
+
+ m.add_at_edge (X_AXIS, RIGHT, span, pad);
+ m.translate_axis (extra_left, X_AXIS);
+
+ return m.create_scheme ();
}
-IMPLEMENT_STATIC_NAME(Crescendo);
+