]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/crescendo.cc
release: 1.3.105
[lilypond.git] / lily / crescendo.cc
index 01f2ba5a775c7343a72a87630fa447d8fc21ee41..9bfbf02eff6c8aaff9edc2fca3730cedb13d7d98 100644 (file)
@@ -3,76 +3,75 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 #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 "score-column.hh"
-
-Crescendo::Crescendo ()
-{
-  grow_dir_ =0;
-  dyn_b_drul_[LEFT] = dyn_b_drul_[RIGHT] =false;
-}
+#include "paper-column.hh"
 
+MAKE_SCHEME_CALLBACK (Crescendo, brew_molecule, 1);
 
+SCM
+Crescendo::brew_molecule (SCM smob) 
+{
+  Score_element *me= unsmob_element (smob);
+  Spanner *span = dynamic_cast<Spanner*>(me);
 
+  Real line = me->paper_l ()->get_var ("stafflinethickness");  
+  
+  Real broken_left =  span->get_broken_left_end_align ();
 
-Molecule
-Crescendo::get_symbol () const
-{
-  Real w_dim = extent (X_AXIS).length () - get_broken_left_end_align ();
-  Real absdyn_dim = paper_l ()-> get_realvar (ly_symbol ("crescendo_shorten"));
-  if (dyn_b_drul_[LEFT])
-    {
-      w_dim -= absdyn_dim;
-    }
-  if (dyn_b_drul_[RIGHT])
+  SCM s = me->get_elt_property("grow-direction");
+  if (!isdir_b (s))
     {
-      w_dim -= absdyn_dim;
+      me->suicide ();
+      return SCM_EOL;
     }
+  
+  Direction grow_dir = to_dir (s);
+
+  Real width = span->spanner_length ();
+  width -= span->get_broken_left_end_align ();
 
-  if (w_dim < 0)
+  if (width < 0)
     {
-      warning (_ ("crescendo") + " " + _ ("too small"));
-      w_dim = 0;
+      warning (_ ((grow_dir < 0) ? "decrescendo too small"
+                 : "crescendo too small"));
+      width = 0;
     }
 
   Drul_array<bool> broken;
   Direction d = LEFT;
-  do {
-    Score_column* s = dynamic_cast<Score_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 (-grow_dir_)];
-  Real height = paper_l()->get_var ("crescendo_height");
-  Real thick = paper_l ()->get_var ("crescendo_thickness");
-
-  return Molecule (lookup_l ()->hairpin (w_dim, height, thick, grow_dir_ < 0, continued));
-}
-
-Molecule*
-Crescendo::do_brew_molecule_p () const
-{
-  Molecule* m_p =0;
-  Real absdyn_dim = paper_l ()-> get_realvar (ly_symbol ("crescendo_shorten"));
-  Real x_off_dim =  get_broken_left_end_align ();
-
-  if (dyn_b_drul_[LEFT])
-    x_off_dim += absdyn_dim;
-
-  m_p = new Molecule;
-  Molecule s (get_symbol ());
-  m_p->add_molecule (s);
-  m_p->translate_axis (x_off_dim, X_AXIS);
-  return m_p;
+  bool continued = broken[Direction (-grow_dir)];
+  Real height = 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.smobbed_copy ();
 }