]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/script.cc
release: 0.1.55
[lilypond.git] / lily / script.cc
index b92892de6fde6f1c71d8077f5962a795f22a7db9..491e6d655fc8fa43af20734dbef021eec18e57d9 100644 (file)
@@ -1,3 +1,11 @@
+/*
+  script.cc -- implement Script
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+#include "script-def.hh"
 #include "musical-request.hh"
 #include "paper-def.hh"
 #include "script.hh"
 #include "molecule.hh"
 #include "lookup.hh"
 
-
-
 void
-Script::set_stem(Stem*st_l)
+Script::do_print() const
 {
-    stem_l_ = st_l;
-    add_dependency(st_l);
+#ifndef NPRINT
+  specs_l_->print();
+#endif
 }
 
 void
-Script::set_support(Item*i)
+Script::do_substitute_dependency (Score_elem*o,Score_elem*n)
 {
-    support.push(i);
-    add_dependency(i);
-}
-
-Script::Script(Script_req* rq, int staflen)
-{    
-    staffsize =staflen;
-    specs_l_ = rq->scriptdef_p_;
-    stem_l_ = 0;
-    pos = 0;
-    symdir=1;
-    dir =rq->dir_i_;
+  Staff_side::do_substitute_dependency (o,n);
+  if (o == stem_l_)
+    {
+      stem_l_ = n ? (Stem*)n->item() : 0;
+    }
 }
 
 void
-Script::set_symdir()
+Script::set_stem (Stem*st_l)
 {
-    if (specs_l_->invertsym)
-       symdir = (dir < 0) ? -1:1;
+  stem_l_ = st_l;
+  add_support (st_l);
 }
 
-void
-Script::set_default_dir()
-{
-    if (specs_l_->stemdir) {
-       if (!stem_l_)
-           dir = 1;
-       else
-           dir = stem_l_->dir * specs_l_->stemdir;
-    }
-}
 
-Interval
-Script::support_height() const return r;
+Script::Script()
 {
-    for (int i=0; i < support.size(); i++)
-       r.unite(support[i]->height());
+  specs_l_ = 0;
+  stem_l_ = 0;
+  dir_ =  CENTER;
 }
 
 void
-Script::set_default_index()
+Script::set_default_dir()
 {
-    Real inter_f= paper()->internote();
-    Interval dy = symbol().dim.y;
-    
-    int d = specs_l_->staffdir;
-    Real y  ;
-    if (!d) {
-       Interval v= support_height();
-       y = v[dir]  -dy[-dir] + 2*dir*inter_f;
-    } else {
-       y  = (d > 0) ? staffsize + 2: -2; // ug
-       y *=inter_f;
-       Interval v= support_height();
-
-       if (d > 0) {
-           y = y >? v.max();
-       } else if (d < 0) {
-           y = y <? v.min();
+  int s_i=specs_l_->rel_stem_dir();
+  if (s_i)
+    {
+      if (stem_l_)
+       dir_ = Direction(stem_l_->dir_ * s_i);
+      else
+       {
+         specs_l_->warning (_("Script needs stem direction"));
+         dir_ = DOWN;
        }
     }
-    
-    if (stem_l_) {
-       Interval v= stem_l_->height();
-
-       if (d > 0 || (!d && dir > 0)) {
-           y = y >? v.max();
-       }else if (d < 0 || (!d && dir < 0)) {
-           y = y <? v.min();
-       }
+  else
+    {
+      dir_ =specs_l_->staff_dir();
     }
-    
-    pos = int(rint(Real(y)/inter_f));
+  assert (dir_);
 }
 
-Interval
-Script::width() const
-{
-    return symbol().dim.x;
-}
 
-Symbol
-Script::symbol()const
+Interval
+Script::do_width() const
 {
-    String preidx_str = (symdir < 0) ?"-" :"";
-    return paper()->lookup_l()->script(preidx_str + specs_l_->symidx);
+  return specs_l_->get_atom (paper(), dir_).extent ().x ();
 }
 
 void
 Script::do_pre_processing()
 {
+  if  (breakable_b_ && break_status_i() != 1)
+    {
+      transparent_b_ = true;
+      set_empty (true);
+    }
+
+  if (!dir_)
     set_default_dir();
-    set_symdir();
 }
 
-void
-Script::do_post_processing()
+Interval
+Script::symbol_height() const
 {
-    set_default_index();
+  return specs_l_->get_atom (paper(), dir_).extent ().y ();
 }
 
 Molecule*
 Script::brew_molecule_p() const
 {
-    Real dy = paper()->internote();
-    
-    Molecule*out = new Molecule(Atom(symbol()));
-    out->translate(Offset(0,dy * pos));
-    return out;
+  Real dx = paper()->note_width()/2;
+
+  Molecule*out = new Molecule (specs_l_->get_atom (paper(), dir_));
+  // ugh, staccato dots are not centred between stafflines (how?)?
+  Real correct = - (Real)dir_ * 2.0 * paper ()->rule_thickness ();
+  out->translate_axis (y_ + correct, Y_AXIS);
+  out->translate_axis (dx, X_AXIS);    // FIXME! ugh
+  return out;
+}
+
+
+IMPLEMENT_IS_TYPE_B2(Script,Item,Staff_side);
+
+int
+Script::compare (Script  *const&l1, Script *const&l2)
+{
+  return l1->specs_l_->priority_i() - l2->specs_l_->priority_i ();
 }
-IMPLEMENT_STATIC_NAME(Script);