]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/script.cc
partial: 1.1.0.jcn
[lilypond.git] / lily / script.cc
index 2a31133c331d121f75c33fc3c024eba0e1191ec5..76c9cbc02a522ca85b3b0957b2234a144ff1207c 100644 (file)
-#include "musicalrequest.hh"
+/*
+  script.cc -- implement Script
+
+  source file of the GNU LilyPond music typesetter
+
+  (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+#include "script-def.hh"
+#include "musical-request.hh"
 #include "paper-def.hh"
 #include "script.hh"
 #include "stem.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_p_->print ();
+#endif
 }
 
 void
-Script::set_support(Item*i)
+Script::do_substitute_dependency (Score_element*o,Score_element*n)
 {
-    support.push(i);
-    add_dependency(i);
+  Staff_side::do_substitute_dependency (o,n);
+  if (o == stem_l_)
+    {
+      stem_l_ = n ? (Stem*)n->access_Item () : 0;
+    }
 }
 
-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_;
+void
+Script::set_stem (Stem*st_l)
+{
+  stem_l_ = st_l;
+  add_support (st_l);
 }
 
-void
-Script::set_symdir()
+
+Script::Script ()
 {
-    if (specs_l_->invertsym)
-       symdir = (dir < 0) ? -1:1;
+  axis_ = Y_AXIS;
+  specs_p_ = 0;
+  stem_l_ = 0;
+  postbreak_only_b_ = true;
+  dir_ =  CENTER;
 }
 
 void
-Script::set_default_dir()
+Script::set_default_dir ()
 {
-    if (specs_l_->stemdir) {
-       if (!stem_l_)
-           dir = 1;
-       else
-           dir = stem_l_->dir * specs_l_->stemdir;
+  int s_i=specs_p_->rel_stem_dir ();
+  if (s_i)
+    {
+      if (stem_l_)
+       dir_ = Direction (stem_l_->dir_ * s_i);
+      else
+       {
+         specs_p_->warning (_ ("script needs stem direction"));
+         dir_ = DOWN;
+       }
+    }
+  else
+    {
+      dir_ =specs_p_->staff_dir ();
     }
+  assert (dir_);
 }
 
+
 Interval
-Script::support_height() const return r;
+Script::do_width () const
 {
-    for (int i=0; i < support.size(); i++)
-       r.unite(support[i]->height());
+  return specs_p_->get_atom (paper (), dir_).extent ().x ();
 }
 
 void
-Script::set_default_index()
+Script::do_pre_processing ()
 {
-    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();
-       }
-    }
-    
-    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();
-       }
+  Staff_side::do_pre_processing ();
+  if (breakable_b_ && postbreak_only_b_ && (break_status_dir () != RIGHT))
+    {
+      transparent_b_ = true;
+      set_empty (true);
     }
-    
-    pos = int(rint(Real(y)/inter_f));
+  
+  if (axis_ == Y_AXIS && !dir_)
+    set_default_dir ();
 }
 
 Interval
-Script::width() const
+Script::symbol_height () const
 {
-    return symbol().dim.x;
+  return specs_p_->get_atom (paper (), dir_).extent ().y ();
 }
 
-Symbol
-Script::symbol()const
+Interval
+Script::symbol_width () const
 {
-    String preidx_str = (symdir < 0) ?"-" :"";
-    return paper()->lookup_p_->script(preidx_str + specs_l_->symidx);
+  return specs_p_->width (paper ());
 }
 
-void
-Script::do_pre_processing()
+Molecule*
+Script::brew_molecule_p () const
 {
-    set_default_dir();
-    set_symdir();
+  Real dx =0.;
+
+  Molecule*mol_p = new Molecule (specs_p_->get_atom (paper (), dir_));
+  /*
+    ugh, staccato dots are not centred between stafflines (how?)?
+  */
+  Real correct =0.0;
+  if (axis_ == Y_AXIS){
+    dx =  paper ()->note_width ()/2;
+    correct = - (Real)dir_ * 2.0 * paper ()->rule_thickness ();
+    mol_p->translate_axis (dx, X_AXIS);        // FIXME! ugh
+  }
+  
+  mol_p->translate_axis (coordinate_offset_f_ + correct, axis_);
+
+  return mol_p;
 }
 
-void
-Script::do_post_processing()
+
+IMPLEMENT_IS_TYPE_B2 (Script,Item,Staff_side);
+
+int
+Script::compare (Script  *const&l1, Script *const&l2)
 {
-    set_default_index();
+  return l1->specs_p_->priority_i() - l2->specs_p_->priority_i ();
 }
 
-Molecule*
-Script::brew_molecule_p() const
+Script::~Script ()
+{
+  delete specs_p_;
+}
+Script::Script (Script const&s)
+  : Item (s), Staff_side(s)
 {
-    Real dy = paper()->internote();
-    
-    Molecule*out = new Molecule(Atom(symbol()));
-    out->translate(Offset(0,dy * pos));
-    return out;
+  specs_p_ = s.specs_p_ ? s.specs_p_->clone (): 0;
+  stem_l_ =s.stem_l_;
+  postbreak_only_b_ = s.postbreak_only_b_;
 }
+