]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.21
authorfred <fred>
Fri, 3 Jan 1997 17:08:50 +0000 (17:08 +0000)
committerfred <fred>
Fri, 3 Jan 1997 17:08:50 +0000 (17:08 +0000)
hdr/idealspacing.hh [new file with mode: 0644]
src/calcideal.cc
src/linespace.cc

diff --git a/hdr/idealspacing.hh b/hdr/idealspacing.hh
new file mode 100644 (file)
index 0000000..801818e
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+  idealspacing.hh -- part of LilyPond
+
+  (c) 1996 Han-Wen Nienhuys
+*/
+
+#ifndef IDEALSPACING_HH
+#define IDEALSPACING_HH
+#include "proto.hh"
+
+/// ideal spacing between two columns
+struct Idealspacing {
+
+    /// the ideal distance
+    Real space;
+
+    /// Hooke's constant: how strong are the "springs" attached to columns
+    Real hooke;
+
+    /// the two columns
+    const PCol *left, *right;
+    
+    void print()const;
+    void OK() const ;
+    Idealspacing(const PCol *left,const PCol *right);    
+};
+
+
+#endif // IDEALSPACING_HH
+
index faf88d6ead48fdde8b0929668011a566d28dbe52..77cef180ef47bf4a83eb7e326d4e00f6eee7f879 100644 (file)
@@ -1,3 +1,4 @@
+#include "idealspacing.hh"
 #include "tstream.hh"
 #include "score.hh"
 #include "pscore.hh"
@@ -37,11 +38,11 @@ Score::connect(PCol* c1, PCol *c2, Real d, Real h)
 void
 Score::calc_idealspacing()
 {
-    PCursor<Score_column*> i(cols_);
+    iter_top(cols_,i);
 
     for (; i.ok(); i++) {
        assert(i->used());
-       PCursor<Score_column*> j (i+1);
+       PCursor<Score_column*> j(i+1);
        if (i->musical) {
            assert(j.ok());
            for (int n=0; n < i->durations.sz(); n++) {
index 784c1f30ad5125f724cc409045db61de49f9068b..f35f64e2fabfe0a2bb7c7c7c86147a9bdc4c69ee 100644 (file)
@@ -1,10 +1,13 @@
 #include <math.h>
 #include "linespace.hh"
+#include "pcol.hh"
 #include "debug.hh"
 #include "qlp.hh"
 #include "unionfind.hh"
+#include "idealspacing.hh"
 
 const Real COLFUDGE=1e-3;
+
 //#define COLFUDGE 1e-3
 bool
 Spacing_problem::contains(const PCol *w)
@@ -38,7 +41,7 @@ Spacing_problem::OK() const
        connected.connect(l,r);         
     }
     for (int i = 0; i < cols.sz(); i++)
-       if (cols[i].fixed)
+       if (cols[i].fixed())
            fixed.add(i);
     for (int i = 0; i < cols.sz(); i++) {
        bool c=false;
@@ -56,7 +59,7 @@ Spacing_problem::check_constraints(Vector v) const
     // mtor << "checking solution " << v << '\n';
     for (int i=0; i < dim; i++) {
 
-       if (cols[i].fixed&& abs(cols[i].fixpos - v(i)) > COLFUDGE) {
+       if (cols[i].fixed()&& abs(cols[i].fixed_position() - v(i)) > COLFUDGE) {
            return false;
        }
        if (!i) 
@@ -101,8 +104,8 @@ Spacing_problem::try_initial_solution() const
     int dim=cols.sz();
     Vector initsol(dim);
     for (int i=0; i < dim; i++) {
-       if (cols[i].fixed) {
-           initsol(i)=cols[i].fixpos;      
+       if (cols[i].fixed()) {
+           initsol(i)=cols[i].fixed_position();            
        } else {
            Real mindist=cols[i-1].minright()
                +cols[i].minleft();
@@ -124,6 +127,7 @@ Spacing_problem::find_initial_solution() const
     assert(check_constraints(v));
     return v;
 }
+
 // generate the matrices
 void
 Spacing_problem::make_matrices(Matrix &quad, Vector &lin, Real &c) const
@@ -155,13 +159,12 @@ Spacing_problem::make_constraints(Mixed_qp& lp) const
     int dim=cols.sz();
     for (int j=0; j < dim; j++) {
        Colinfo *c=&(cols[j]);
-       if (c->fixed) {
-           lp.add_fixed_var(j,c->fixpos);          
+       if (c->fixed()) {
+           lp.add_fixed_var(j,c->fixed_position());        
        }
        if (j > 0){
            Vector c1(dim);
            
-              
            c1(j)=1.0 ;
            c1(j-1)=-1.0 ;
            lp.add_inequality_cons(c1, cols[j-1].minright() +
@@ -199,11 +202,7 @@ Spacing_problem::solve() const
 void
 Spacing_problem::add_column(const PCol *col, bool fixed, Real fixpos)
 {
-    Colinfo c;
-    c.fixed=fixed;
-    c.fixpos=fixpos;
-    assert(col);
-    c.pcol_=col;
+    Colinfo c(col,(fixed)? &fixpos :  0);
     cols.add(c);
 }
 
@@ -246,21 +245,50 @@ Spacing_problem::print() const
     
 }
 
+/*****************/
+
 void
 Colinfo::print() const
 {
 #ifndef NPRINT
     mtor << "column { ";
-    if (fixed)
-       mtor << "fixed at " << fixpos<<", ";
+    if (fixed())
+       mtor << "fixed at " << fixed_position()<<", ";
     assert(pcol_);
     mtor << "[" << minleft() << ", " << minright() << "]";
     mtor <<"}\n";
 #endif
 }
 
+Colinfo::Colinfo(Colinfo const&c)
+{
+    fixpos = (c.fixpos)?new Real(*c.fixpos):0;
+    pcol_ = c.pcol_;
+    width = c.width;
+}
+
+Colinfo::Colinfo(const PCol*col_p, const Real*fixed_r_p )
+{
+    fixpos = (fixed_r_p)? new Real(*fixed_r_p) : 0;
+    pcol_ = col_p;
+    width = pcol_->width();
+}
+
+Colinfo::~Colinfo()
+{
+    delete fixpos;
+}
+
 Colinfo::Colinfo()
 {
-    fixed=false;
     pcol_=0;
+    fixpos = 0;
+}
+void
+Colinfo::operator=(Colinfo const&c )
+{
+    delete fixpos;
+    fixpos = (c.fixpos)?new Real(*c.fixpos):0;
+    pcol_ = c.pcol_;
+    width = c.width;
 }