]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/crescendo.cc
release: 1.3.100
[lilypond.git] / lily / crescendo.cc
index df349421bb658035b7020c45132a70c39d96d113..be54a96e62e0057a377b78697d250dc77144ec3b 100644 (file)
@@ -3,65 +3,75 @@
 
   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 "molecule.hh"
-#include "dimen.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"
 
-Crescendo::Crescendo()
-{
-    grow_dir_i_ =0;
-    dir_i_ = -1 ;
-    left_dyn_b_ = right_dyn_b_ =false;
-    inside_staff_b_ = false;
-}
+MAKE_SCHEME_CALLBACK (Crescendo, brew_molecule, 1);
 
-Interval
-Crescendo::symbol_height()const
+SCM
+Crescendo::brew_molecule (SCM smob) 
 {
-    return get_symbol().dim.y;
-}
+  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 ();
 
-static Real absdyn_dim = 10 PT;        // ugh
-
-Symbol
-Crescendo::get_symbol()const
-{    
-    Real w_dim = width().length();
-    if ( left_dyn_b_ ) {
-       w_dim -= absdyn_dim;
+  SCM s = me->get_elt_property("grow-direction");
+  if (!isdir_b (s))
+    {
+      me->suicide ();
+      return SCM_EOL;
     }
-    if ( right_dyn_b_ ) {
-       w_dim -= absdyn_dim;
+  
+  Direction grow_dir = to_dir (s);
+
+  Real width = span->spanner_length ();
+  width -= span->get_broken_left_end_align ();
+
+  if (width < 0)
+    {
+      warning (_ ((grow_dir < 0) ? "decrescendo too small"
+                 : "crescendo too small"));
+      width = 0;
     }
-    
-    if (w_dim < 0) {
-       warning("Crescendo too small");
-       w_dim = 0;
+
+  Drul_array<bool> broken;
+  Direction 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 = 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);
 
-    return Symbol( paper()->lookup_l()->hairpin( w_dim, grow_dir_i_ < 0) );
-}
+  Box b (Interval (0, width), Interval (-2*height, 2*height));
+  Molecule mol (b, hairpin);
+  mol.translate_axis (broken_left, X_AXIS);
 
-Molecule*
-Crescendo::brew_molecule_p() const
-{
-    Molecule* m_p =0;
-    Real x_off_dim=0.0;
-    if ( left_dyn_b_)
-       x_off_dim += absdyn_dim;
-    
-    m_p = new Molecule;
-    Symbol s(get_symbol());
-    m_p->add(Atom(s));
-    m_p->translate(Offset(x_off_dim, pos_i_ * paper()->internote_f()));
-    return m_p;
+  return mol.create_scheme ();
 }
 
 
-IMPLEMENT_IS_TYPE_B1(Crescendo,Spanner);