lilypond-1.3.100
[lilypond.git] / lily / crescendo.cc
blobbe54a96e62e0057a377b78697d250dc77144ec3b
1 /*
2 crescendo.cc -- implement Crescendo
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "molecule.hh"
10 #include "crescendo.hh"
11 #include "spanner.hh"
12 #include "font-interface.hh"
13 #include "dimensions.hh"
14 #include "paper-def.hh"
15 #include "debug.hh"
16 #include "paper-column.hh"
18 MAKE_SCHEME_CALLBACK (Crescendo, brew_molecule, 1);
20 SCM
21 Crescendo::brew_molecule (SCM smob)
23 Score_element *me= unsmob_element (smob);
24 Spanner *span = dynamic_cast<Spanner*>(me);
25 Real staff_space = me->paper_l ()->get_var ("staffspace");
26 Real line = me->paper_l ()->get_var ("stafflinethickness");
28 Real broken_left = span->get_broken_left_end_align ();
30 SCM s = me->get_elt_property("grow-direction");
31 if (!isdir_b (s))
33 me->suicide ();
34 return SCM_EOL;
37 Direction grow_dir = to_dir (s);
39 Real width = span->spanner_length ();
40 width -= span->get_broken_left_end_align ();
42 if (width < 0)
44 warning (_ ((grow_dir < 0) ? "decrescendo too small"
45 : "crescendo too small"));
46 width = 0;
49 Drul_array<bool> broken;
50 Direction d = LEFT;
53 Paper_column* s = dynamic_cast<Paper_column*> (span->get_bound (d)); // UGH
54 broken[d] = (!s->musical_b ());
56 while (flip (&d) != LEFT);
58 bool continued = broken[Direction (-grow_dir)];
59 Real height = staff_space * gh_scm2double (me->get_elt_property ("height"));
60 Real thick = line * gh_scm2double (me->get_elt_property ("thickness"));
62 const char* type = (grow_dir < 0) ? "decrescendo" : "crescendo";
63 SCM hairpin = gh_list (ly_symbol2scm (type),
64 gh_double2scm (thick),
65 gh_double2scm (width),
66 gh_double2scm (height),
67 gh_double2scm (continued ? height/2 : 0.0),
68 SCM_UNDEFINED);
70 Box b (Interval (0, width), Interval (-2*height, 2*height));
71 Molecule mol (b, hairpin);
72 mol.translate_axis (broken_left, X_AXIS);
74 return mol.create_scheme ();