]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/crescendo.cc
release: 1.3.100
[lilypond.git] / lily / crescendo.cc
index b8d1744fb4cc298209d84038f2f97b34ba127537..be54a96e62e0057a377b78697d250dc77144ec3b 100644 (file)
@@ -8,91 +8,70 @@
 
 #include "molecule.hh"
 #include "crescendo.hh"
-#include "lookup.hh"
+#include "spanner.hh"
+#include "font-interface.hh"
 #include "dimensions.hh"
 #include "paper-def.hh"
 #include "debug.hh"
 #include "paper-column.hh"
-#include "atom.hh"
-
-Crescendo::Crescendo ()
-{
-  set_elt_property ("dynamic-drul", gh_cons (SCM_BOOL_F, SCM_BOOL_F));
-}
 
+MAKE_SCHEME_CALLBACK (Crescendo, brew_molecule, 1);
 
-
-Molecule*
-Crescendo::do_brew_molecule_p () const
+SCM
+Crescendo::brew_molecule (SCM smob) 
 {
-  Real absdyn_dim = paper_l ()-> get_var ("crescendo_shorten");
-  Real extra_left =  get_broken_left_end_align ();
-
-  SCM dir = get_elt_property("grow-direction");
-  SCM dyns = get_elt_property ("dynamic-drul");
+  Score_element *me= unsmob_element (smob);
+  Spanner *span = dynamic_cast<Spanner*>(me);
+  Real staff_space = me->paper_l ()->get_var ("staffspace");
+  Real line = me->paper_l ()->get_var ("stafflinethickness");  
+  
+  Real broken_left =  span->get_broken_left_end_align ();
 
-  if (!isdir_b (dir) || !gh_pair_p (dyns))
+  SCM s = me->get_elt_property("grow-direction");
+  if (!isdir_b (s))
     {
-Crescendo * me = (Crescendo*)this;
-      me->set_elt_property ("transparent", SCM_BOOL_T);
-      return new Molecule;
+      me->suicide ();
+      return SCM_EOL;
     }
   
-  Direction gd = to_dir (dir);
-
-  bool dynleft= to_boolean (gh_car (dyns));
-  bool dynright = to_boolean (gh_cdr (dyns));
-  
-  if (dynleft)
-    extra_left += absdyn_dim;
-
-  
-
-  Real width = spanner_length()- get_broken_left_end_align ();
+  Direction grow_dir = to_dir (s);
 
-  if (dynleft)
-    {
-      width -= absdyn_dim;
-    }
-  if (dynright)
-    {
-      width -= absdyn_dim;
-    }
+  Real width = span->spanner_length ();
+  width -= span->get_broken_left_end_align ();
 
   if (width < 0)
     {
-      warning (_ ("crescendo") + " " + _ ("too small"));
+      warning (_ ((grow_dir < 0) ? "decrescendo too small"
+                 : "crescendo too small"));
       width = 0;
     }
 
   Drul_array<bool> broken;
   Direction d = LEFT;
-  do {
-    Paper_column* s = dynamic_cast<Paper_column*>(spanned_drul_[d]); // UGH
-    broken[d] = (!s->musical_b ());
-  } while (flip (&d) != LEFT);
+  do
+    {
+      Paper_column* s = dynamic_cast<Paper_column*> (span->get_bound (d)); // UGH
+      broken[d] = (!s->musical_b ());
+    }
+  while (flip (&d) != LEFT);
   
-
-  bool continued = broken[Direction (-gd)];
-  Real height = paper_l()->get_var ("crescendo_height");
-  Real thick = paper_l ()->get_var ("crescendo_thickness");
-
-  const char* hairpin = (gd < 0)? "decrescendo" :  "crescendo";
-  Molecule * m
-    = new Molecule;
-  m->dim_.x () = Interval (0, width);
-  m->dim_.y () = Interval (-2*height, 2*height);
-
-  Atom *a = new Atom(gh_list (ly_symbol2scm (hairpin),
-                    gh_double2scm (thick),
-                    gh_double2scm (width),
-                    gh_double2scm (height),
-                    gh_double2scm (continued ? height/2 : 0.0),
-                    SCM_UNDEFINED));
-
-  m->add_atom (a->self_scm_);
-  m->translate_axis (extra_left, X_AXIS);
-  return m;
+  bool continued = broken[Direction (-grow_dir)];
+  Real height = staff_space * gh_scm2double (me->get_elt_property ("height"));
+  Real thick = line * gh_scm2double (me->get_elt_property ("thickness"));
+  
+  const char* type = (grow_dir < 0) ? "decrescendo" :  "crescendo";
+  SCM hairpin = gh_list (ly_symbol2scm (type),
+                   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 mol (b, hairpin);
+  mol.translate_axis (broken_left, X_AXIS);
+
+  return mol.create_scheme ();
 }