From fd7e615444cf58b38283a59b56d3457c07778397 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sat, 18 Dec 1999 18:02:07 +0100 Subject: [PATCH] release: 1.3.13 --- CHANGES | 10 + TODO | 1 + VERSION | 2 +- flower/include/direction.hh | 2 - flower/include/offset.hh | 81 ++-- flower/include/polynomial.hh | 85 ++++ flower/offset.cc | 4 +- flower/polynomial.cc | 367 ++++++++++++++++ input/bugs/1845390254.ly | 38 ++ input/test/GNUmakefile | 2 +- lily/afm-reader.cc | 15 +- lily/align-element.cc | 20 +- lily/all-font-metrics.cc | 78 +++- lily/beam.cc | 15 +- lily/bezier.cc | 648 +++++------------------------ lily/bow.cc | 13 +- lily/break-algorithm.cc | 10 +- lily/break-align-item.cc | 12 +- lily/chord.cc | 4 +- lily/column-x-positions.cc | 13 - lily/crescendo.cc | 59 +-- lily/debug.cc | 54 +-- lily/dimension-cache.cc | 23 - lily/dots.cc | 2 +- lily/engraver-group-engraver.cc | 52 +-- lily/font-metric.cc | 35 ++ lily/gourlay-breaking.cc | 4 +- lily/grace-performer-group.cc | 9 +- lily/include/afm.hh | 2 +- lily/include/all-font-metrics.hh | 11 +- lily/include/beam.hh | 11 +- lily/include/bezier-bow.hh | 58 +++ lily/include/bezier.hh | 75 +--- lily/include/bow.hh | 3 +- lily/include/break-algorithm.hh | 6 +- lily/include/column-x-positions.hh | 9 +- lily/include/curve.hh | 38 -- lily/include/dimension-cache.hh | 6 - lily/include/font-metric.hh | 6 + lily/include/global-translator.hh | 3 - lily/include/item.hh | 2 - lily/include/keyword.hh | 12 +- lily/include/lily-proto.hh | 1 + lily/include/lookup.hh | 1 - lily/include/misc.hh | 30 +- lily/include/note-head-side.hh | 2 - lily/include/notename-table.hh | 12 +- lily/include/scope.hh | 13 +- lily/include/score-element.hh | 12 +- lily/include/spanner.hh | 7 - lily/include/translator-group.hh | 8 +- lily/item.cc | 7 +- lily/leastsquares.cc | 14 +- lily/lily-guile.cc | 2 +- lily/local-key-item.cc | 4 +- lily/lookup.cc | 21 +- lily/main.cc | 17 +- lily/misc.cc | 85 +--- lily/molecule.cc | 4 +- lily/moment.cc | 2 +- lily/my-lily-lexer.cc | 4 +- lily/note-column.cc | 3 - lily/note-head.cc | 1 - lily/notename-table.cc | 39 +- lily/paper-outputter.cc | 4 +- lily/paper-score.cc | 10 +- lily/parser.yy | 5 +- lily/performer-group-performer.cc | 52 +-- lily/property-engraver.cc | 10 +- lily/scm-hash.cc | 2 +- lily/scope.cc | 44 +- lily/score-element.cc | 40 +- lily/score-engraver.cc | 4 +- lily/script-engraver.cc | 20 +- lily/script.cc | 2 +- lily/slur.cc | 9 +- lily/spacing-spanner.cc | 6 +- lily/spanner.cc | 18 +- lily/time-description.cc | 11 - lily/translator-group.cc | 67 ++- ly/property.ly | 12 +- make/out/lilypond.lsm | 8 +- make/out/lilypond.spec | 4 +- po/nl.po | 2 +- 84 files changed, 1198 insertions(+), 1321 deletions(-) create mode 100644 flower/include/polynomial.hh create mode 100644 flower/polynomial.cc create mode 100644 input/bugs/1845390254.ly create mode 100644 lily/include/bezier-bow.hh delete mode 100644 lily/include/curve.hh delete mode 100644 lily/time-description.cc diff --git a/CHANGES b/CHANGES index 537ec3f1c4..b248113d9c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,13 @@ +pl 12.hwn1 + - polynomial.hh + - bf: generic properties + - quantise_iv () fix. + - bezier cleanup + - class Polynomial + - use smobs for font metric tables/hashes. + - nl.po bf + + pl 11.jcn3 - small beam fixes (interstaff knees still broken) diff --git a/TODO b/TODO index a08d5cbf25..128422b0d1 100644 --- a/TODO +++ b/TODO @@ -28,6 +28,7 @@ Grep -i for TODO, FIXME and ugh/ugr/urg. ctor_dict["Score_element"]->create_func (); . * acc at tied note after linebreak. . * fix font-naming and selecting +. * sparse ties. . * chord tonic: placement of accidental C#, Cb (from scm and C++) . * note head on stem err msg in dutch. . * why need to run -C mf twice? diff --git a/VERSION b/VERSION index 04cb146bb1..bcb4087ea5 100644 --- a/VERSION +++ b/VERSION @@ -1,7 +1,7 @@ PACKAGE_NAME=LilyPond MAJOR_VERSION=1 MINOR_VERSION=3 -PATCH_LEVEL=12 +PATCH_LEVEL=13 MY_PATCH_LEVEL= # use the above to send patches: MY_PATCH_LEVEL is always empty for a diff --git a/flower/include/direction.hh b/flower/include/direction.hh index ffd262f6a8..5cce076c0f 100644 --- a/flower/include/direction.hh +++ b/flower/include/direction.hh @@ -25,8 +25,6 @@ enum Direction BIGGER=1, START = -1, STOP = 1, - X=1, - Y=-1, }; inline Direction diff --git a/flower/include/offset.hh b/flower/include/offset.hh index 428a8fa6b3..0a5a7a10d5 100644 --- a/flower/include/offset.hh +++ b/flower/include/offset.hh @@ -9,20 +9,21 @@ #include "real.hh" #include "axes.hh" +#include "arithmetic-operator.hh" + +struct Offset; + +Offset complex_multiply (Offset, Offset); +Offset complex_exp (Offset); + /** 2d vector should change to Complex */ struct Offset { public: - Real coordinate_a_[NO_AXES]; - Real &y() { return coordinate_a_[Y_AXIS]; } - Real &x() { return coordinate_a_[X_AXIS]; } - Real y() const { return coordinate_a_[Y_AXIS]; } - Real x() const { return coordinate_a_[X_AXIS]; } - Real &operator[](Axis i) { return coordinate_a_[i]; } @@ -31,74 +32,62 @@ public: } Offset& operator+=(Offset o) { - x()+=o.x (); - y()+=o.y (); + (*this)[X_AXIS] += o[X_AXIS]; + (*this)[Y_AXIS] += o[Y_AXIS]; return *this; } Offset operator - () const { Offset o = *this; - o.x () = - o.x (); - o.y () = - o.y (); + + o[X_AXIS] = - o[X_AXIS]; + o[Y_AXIS] = - o[Y_AXIS]; return o; } Offset& operator-=(Offset o) { - x()-=o.x (); - y()-=o.y (); + (*this)[X_AXIS] -= o[X_AXIS]; + (*this)[Y_AXIS] -= o[Y_AXIS]; + return *this; } Offset &scale (Offset o) { - x()*=o.x (); - y()*=o.y (); + (*this)[X_AXIS] *= o[X_AXIS]; + (*this)[Y_AXIS] *= o[Y_AXIS]; + return *this; } Offset &operator *=(Real a) { - y() *= a; - x() *= a; + (*this)[X_AXIS] *= a; + (*this)[Y_AXIS] *= a; + return *this; } Offset (Real ix , Real iy) { - x()=ix; - y()=iy; + coordinate_a_[X_AXIS] =ix; + coordinate_a_[Y_AXIS] =iy; } Offset() { - x()=0.0; - y()=0.0; + coordinate_a_[X_AXIS]= + coordinate_a_[Y_AXIS]= + 0.0; } -#ifndef STANDALONE + String str () const; -#endif void mirror (Axis); Real arg () const; Real length () const; -}; - -Offset complex_multiply (Offset, Offset); -Offset complex_exp (Offset); - - -inline Offset -operator* (Offset z1, Offset z2) -{ - return complex_multiply (z1,z2); -} - -inline Offset -operator+ (Offset o1, Offset const& o2) -{ - o1 += o2; - return o1; -} + Offset operator *=(Offset z2) { + *this = complex_multiply (*this,z2); + return *this; + } -inline Offset -operator- (Offset o1, Offset const& o2) -{ - o1 -= o2; - return o1; -} +}; +IMPLEMENT_ARITHMETIC_OPERATOR(Offset, +); +IMPLEMENT_ARITHMETIC_OPERATOR(Offset, -); +IMPLEMENT_ARITHMETIC_OPERATOR(Offset, *); inline Offset operator* (Real o1, Offset o2) diff --git a/flower/include/polynomial.hh b/flower/include/polynomial.hh new file mode 100644 index 0000000000..df79274bdc --- /dev/null +++ b/flower/include/polynomial.hh @@ -0,0 +1,85 @@ + +/* + * poly.h -- routines for manipulation of polynomials in one var + * + * (c) 1993, 1996,1999 Han-Wen Nienhuys + */ + +#ifndef POLY_H +#define POLY_H + +#include "array.hh" +#include "arithmetic-operator.hh" +#include "real.hh" + +/// structure for a polynomial in one var. +struct Polynomial +{ + /// degree of polynomial + int degree ()const; + + /// coefficients + Array coefs_; + + // leading coef + Real &lc(); + + // leading coef + Real lc() const; + void print() const ; + Real eval(Real) const ; + void print_sols(Array) const ; + void check_sols(Array) const ; + void check_sol(Real x) const; + static Polynomial multiply(const Polynomial & p1, const Polynomial & p2); + static Polynomial power(int exponent, const Polynomial & src); + + /// chop low coefficients + void clean(); + + /// eliminate #x# close to zero + void real_clean(); + static Polynomial add(const Polynomial & p1, const Polynomial & p2); + void scalarmultiply(Real fact); + void operator *= (Real f) { scalarmultiply(f); } + void operator /= (Real f) { scalarmultiply(1/f); } + void operator += (Polynomial const &p2); + void operator *= (Polynomial const &p2); + void operator -= (Polynomial const &p2); + Polynomial (Real a, Real b =0.0); + Polynomial (){} + static Polynomial subtract(const Polynomial & p1, const Polynomial & p2); + void set_negate(const Polynomial & src); + + /// take the derivative + void differentiate(); + int set_mod(const Polynomial &u, const Polynomial &v); + + void debug_clean(); + + Array solve_quadric()const; + Array solve_cubic()const; + Array solve_linear()const; + + Array solve () const; +}; + + +IMPLEMENT_ARITHMETIC_OPERATOR(Polynomial, - ); +IMPLEMENT_ARITHMETIC_OPERATOR(Polynomial, + ); +IMPLEMENT_ARITHMETIC_OPERATOR(Polynomial, * ); + +inline Polynomial +operator * (Polynomial p, Real a) +{ + p *=a; + return p; +} +inline Polynomial +operator * (Real a,Polynomial p) +{ + p *=a; + return p; +} +#endif + diff --git a/flower/offset.cc b/flower/offset.cc index 4e4e1e3bb0..90f70b73a6 100644 --- a/flower/offset.cc +++ b/flower/offset.cc @@ -63,7 +63,7 @@ complex_exp (Offset o) Real Offset::arg () const { - return atan2 (y (), x()); + return atan2 (coordinate_a_[Y_AXIS], coordinate_a_[X_AXIS]); } /** @@ -72,7 +72,7 @@ Offset::arg () const Real Offset::length () const { - return sqrt (sqr (x()) + sqr (y())); + return sqrt (sqr (coordinate_a_[X_AXIS]) + sqr (coordinate_a_[Y_AXIS])); } void Offset::mirror (Axis a) diff --git a/flower/polynomial.cc b/flower/polynomial.cc new file mode 100644 index 0000000000..7fe77f2112 --- /dev/null +++ b/flower/polynomial.cc @@ -0,0 +1,367 @@ +/* + poly.cc -- routines for manipulation of polynomials in one var + + (c) 1993--1999 Han-Wen Nienhuys + */ + + +#include "polynomial.hh" + +/* + Een beter milieu begint bij uzelf. Hergebruik! + + + This was ripped from Rayce, a raytracer I once wrote. +*/ + +Real +Polynomial::eval (Real x)const +{ + Real p = 0.0; + + // horner's scheme + for (int i = coefs_.size (); i--; ) + p = x * p + coefs_[i]; + + return p; +} + + +Polynomial +Polynomial::multiply(const Polynomial & p1, const Polynomial & p2) +{ + Polynomial dest; + + int deg= p1.degree () + p2.degree (); + for (int i = 0; i <= deg; i++) + { + dest.coefs_.push (0); + for (int j = 0; j <= i; j++) + if (i - j <= p2.degree () && j <= p1.degree ()) + dest.coefs_.top () += p1.coefs_[j] * p2.coefs_[i - j]; + } + + return dest; +} + +void +Polynomial::differentiate() +{ + for (int i = 1; i<= degree (); i++) + { + coefs_[i-1] = coefs_[i] * i; + } +} + +Polynomial +Polynomial::power(int exponent, const Polynomial & src) +{ + int e = exponent; + Polynomial dest(1), base(src); + + // classicint power. invariant: src^exponent = dest * src ^ e + // greetings go out to Lex Bijlsma & Jaap vd Woude + while (e > 0) + { + if (e % 2) + { + dest = multiply(dest, base); + e--; + } else + { + base = multiply(base, base); + e /= 2; + } + } + return dest; +} + +const Real FUDGE = 1e-8; + +void +Polynomial::clean() +{ + int i; + for (i = 0; i <= degree (); i++) + { + if (abs(coefs_[i]) < FUDGE) + coefs_[i] = 0.0; + } + + while (degree () > 0 && fabs (coefs_.top ()) < FUDGE * fabs (coefs_.top (1))) + coefs_.pop (); +} + + +Polynomial +Polynomial::add(const Polynomial & p1, const Polynomial & p2) +{ + Polynomial dest; + int tempord = p2.degree () >? p1.degree (); + for (int i = 0; i <= tempord; i++) + { + Real temp = 0.0; + if (i <= p1.degree ()) + temp += p1.coefs_[i]; + if (i <= p2.degree ()) + temp += p2.coefs_[i]; + dest.coefs_.push (temp); + } + return dest; +} + +void +Polynomial::scalarmultiply(Real fact) +{ + for (int i = 0; i <= degree (); i++) + coefs_[i] *= fact; +} + +Polynomial +Polynomial::subtract(const Polynomial & p1, const Polynomial & p2) +{ + Polynomial dest; + int tempord = p2.degree () >? p1.degree (); + + for (int i = 0; i <= tempord; i++) + { + Real temp = 0.0; // can't store result directly.. a=a-b + if (i <= p1.degree ()) + temp += p1.coefs_[i]; + if (i <= p2.degree ()) + temp -= p2.coefs_[i]; + dest.coefs_.push (temp); + } + return dest; + +} + +void +Polynomial::set_negate(const Polynomial & src) +{ + for (int i = 0; i <= src.degree(); i++) + coefs_[i] = -src.coefs_[i]; +} + +/// mod of #u/v# +int +Polynomial::set_mod(const Polynomial &u, const Polynomial &v) +{ + (*this) = u; + + if (v.lc() < 0.0) { + for (int k = u.degree () - v.degree () - 1; k >= 0; k -= 2) + coefs_[k] = -coefs_[k]; + + for (int k = u.degree () - v.degree (); k >= 0; k--) + for (int j = v.degree () + k - 1; j >= k; j--) + coefs_[j] = -coefs_[j] - coefs_[v.degree () + k] * v.coefs_[j - k]; + } else { + for (int k = u.degree () - v.degree (); k >= 0; k--) + for (int j = v.degree () + k - 1; j >= k; j--) + coefs_[j] -= coefs_[v.degree () + k] * v.coefs_[j - k]; + } + + int k = v.degree () - 1; + while (k >= 0 && coefs_[k] == 0.0) + k--; + + coefs_.set_size(1+ ( (k < 0) ? 0 : k)); + return degree(); +} + +void +Polynomial::check_sol(Real x) const +{ + Real f=eval(x); + Polynomial p(*this); + p.differentiate(); + Real d = p.eval(x); + + if( abs(f) > abs(d) * FUDGE) + ; + /* + warning("x=%f is not a root of polynomial\n" + "f(x)=%f, f'(x)=%f \n", x, f, d); */ +} + +void +Polynomial::check_sols(Array roots) const +{ + for (int i=0; i< roots.size (); i++) + check_sol(roots[i]); +} + +Polynomial::Polynomial (Real a, Real b) +{ + coefs_.push (a); + if (b) + coefs_.push (b); +} + +/* cubic root. */ +inline Real cubic_root(Real x) +{ + if (x > 0.0) + return pow(x, 1.0/3.0) ; + else if (x < 0.0) + return -pow(-x, 1.0/3.0); + else + return 0.0; +} + +static bool +iszero (Real r) +{ + return !r; +} + +Array +Polynomial::solve_cubic()const +{ + Array sol; + + /* normal form: x^3 + Ax^2 + Bx + C = 0 */ + Real A = coefs_[2] / coefs_[3]; + Real B = coefs_[1] / coefs_[3]; + Real C = coefs_[0] / coefs_[3]; + + /* + * substitute x = y - A/3 to eliminate quadric term: x^3 +px + q = 0 + */ + + Real sq_A = A * A; + Real p = 1.0 / 3 * (-1.0 / 3 * sq_A + B); + Real q = 1.0 / 2 * (2.0 / 27 * A * sq_A - 1.0 / 3 * A * B + C); + + /* use Cardano's formula */ + + Real cb_p = p * p * p; + Real D = q * q + cb_p; + + if (iszero(D)) { + if (iszero(q)) { /* one triple solution */ + sol.push (0); + sol.push (0); + sol.push (0); + } else { /* one single and one double solution */ + Real u = cubic_root(-q); + + sol.push (2 * u); + sol.push (-u); + } + } else if (D < 0) { /* Casus irreducibilis: three real solutions */ + Real phi = 1.0 / 3 * acos(-q / sqrt(-cb_p)); + Real t = 2 * sqrt(-p); + + sol.push (t * cos(phi)); + sol.push (-t * cos(phi + M_PI / 3)); + sol.push ( -t * cos(phi - M_PI / 3)); + } else { /* one real solution */ + Real sqrt_D = sqrt(D); + Real u = cubic_root(sqrt_D - q); + Real v = -cubic_root(sqrt_D + q); + + sol.push ( u + v); + } + + /* resubstitute */ + Real sub = 1.0 / 3 * A; + + for (int i = sol.size (); i--;) + { + sol[i] -= sub; + + assert (fabs (eval (sol[i]) ) < 1e-8); + } + + return sol; +} + +Real +Polynomial::lc () const +{ + return coefs_.top(); +} + +Real& +Polynomial::lc () +{ + return coefs_.top (); +} + +int +Polynomial::degree ()const +{ + return coefs_.size () -1; +} +/* + all roots of quadratic eqn. + */ +Array +Polynomial::solve_quadric()const +{ + Array sol; + /* normal form: x^2 + px + q = 0 */ + Real p = coefs_[1] / (2 * coefs_[2]); + Real q = coefs_[0] / coefs_[2]; + + Real D = p * p - q; + + if (D>0) { + D = sqrt(D); + + sol.push ( D - p); + sol.push ( -D - p); + } + return sol; +} + +/* solve linear equation */ +Array +Polynomial::solve_linear()const +{ + Array s; + if (coefs_[1]) + s.push ( -coefs_[0] / coefs_[1]); + return s; +} + + +Array +Polynomial::solve () const +{ + Polynomial * me = (Polynomial*) this; + me->clean (); + + switch (degree ()) + { + case 1: + return solve_linear (); + case 2: + return solve_quadric (); + case 3: + return solve_cubic (); + } + assert (false); + Array s; + return s; +} + +void +Polynomial:: operator *= (Polynomial const &p2) +{ + *this = multiply (*this,p2); +} + +void +Polynomial::operator += (Polynomial const &p) +{ + *this = add( *this, p); +} + +void +Polynomial::operator -= (Polynomial const &p) +{ + *this = subtract(*this, p); +} diff --git a/input/bugs/1845390254.ly b/input/bugs/1845390254.ly new file mode 100644 index 0000000000..87b066e187 --- /dev/null +++ b/input/bugs/1845390254.ly @@ -0,0 +1,38 @@ + +% Generated by mudela-book.py; options are center +\include "paper16.ly" +\paper { linewidth = 390.000000 \pt; } + +\header { + title = "The river is flowing"; + composer = "Traditional (?)"; +} +\include "paper16.ly" + +melody = \notes \relative c' { + \partial 8; + g8 | + +} + +text = \lyrics { + The +} + +accompaniment =\chords { + r8 + c2:3- f:3-.7 d:min es4 c8:min r8 + c2:min f:min7 g:7^3.5 c:min } + +\score { + \simultaneous { + + \addlyrics + \context Staff = mel { + \melody + } + \context Lyrics \text + } +% \midi { } + \paper { linewidth = 10.0\cm; } +} diff --git a/input/test/GNUmakefile b/input/test/GNUmakefile index 83bbdcd9ef..00cddc0806 100644 --- a/input/test/GNUmakefile +++ b/input/test/GNUmakefile @@ -1,7 +1,7 @@ # input/test/Makefile depth = ../.. -examples=font20 +examples=font20 sleur LOCALSTEPMAKE_TEMPLATES=mutopia include $(depth)/make/stepmake.make diff --git a/lily/afm-reader.cc b/lily/afm-reader.cc index 7663aab22b..1eb882832b 100644 --- a/lily/afm-reader.cc +++ b/lily/afm-reader.cc @@ -82,11 +82,11 @@ Adobe_font_metric::read_char_metrics (Data_file &input, int size) } #define READSTRING(k) if (key == #k) { \ - afm.k ## _ = input.get_line (); continue; } + afm->k ## _ = input.get_line (); continue; } #define READBOX(b) if (key == #b) { \ - afm.b ## _ = read_box (input); continue; } + afm->b ## _ = read_box (input); continue; } #define READREAL(r) if (key == #r) { \ - afm.r ## _ = read_real (input); continue; } + afm->r ## _ = read_real (input); continue; } Real read_real(Data_file &d) @@ -108,7 +108,7 @@ read_box ( Data_file &d) return b; } -Adobe_font_metric +Adobe_font_metric * read_afm_file (String fn) { Data_file input (fn); @@ -120,11 +120,10 @@ read_afm_file (String fn) {} int font_size = String_convert::dec2_i(fn.cut_str(i+1,INT_MAX)); - Adobe_font_metric afm; - + Adobe_font_metric *afm = new Adobe_font_metric; for (i=0; i < 256; i++) { - afm.ascii_to_metric_idx_.push (-1); + afm->ascii_to_metric_idx_.push (-1); } while (!input.eof_b ()) @@ -157,7 +156,7 @@ read_afm_file (String fn) if (key == "StartCharMetrics") { input.get_line (); - afm.read_char_metrics (input, font_size); + afm->read_char_metrics (input, font_size); } if (key == "EndFontMetrics") break; diff --git a/lily/align-element.cc b/lily/align-element.cc index 5f4080015c..fed4065602 100644 --- a/lily/align-element.cc +++ b/lily/align-element.cc @@ -43,17 +43,21 @@ Align_element::do_side_processing () // todo: fucks up if item both in Halign & Valign. SCM min_dims = e->remove_elt_property ("minimum-space"); - if (min_dims != SCM_UNDEFINED) + if (gh_pair_p (min_dims) && + gh_number_p (gh_car (min_dims)) + && gh_number_p (gh_cdr (min_dims))) { - y.unite (Interval (gh_scm2double (SCM_CAR (min_dims)), - gh_scm2double (SCM_CDR (min_dims)))); + y.unite (Interval (gh_scm2double (gh_car (min_dims)), + gh_scm2double (gh_cdr (min_dims)))); } SCM extra_dims = e->remove_elt_property ("extra-space"); - if (extra_dims != SCM_UNDEFINED) + if (gh_pair_p (extra_dims) && + gh_number_p (gh_car (extra_dims)) + && gh_number_p (gh_cdr (extra_dims))) { - y[LEFT] += gh_scm2double (SCM_CAR (extra_dims)); - y[RIGHT] += gh_scm2double (SCM_CDR (extra_dims)); + y[LEFT] += gh_scm2double (gh_car (extra_dims)); + y[RIGHT] += gh_scm2double (gh_cdr (extra_dims)); } elems.push (e); @@ -96,10 +100,6 @@ Align_element::do_side_processing () if (center_f) translate_axis ( - center_f, axis ()); - - - // dim_cache_[axis ()]->invalidate (); - } Align_element::Align_element() diff --git a/lily/all-font-metrics.cc b/lily/all-font-metrics.cc index eddad21ed0..89608e4768 100644 --- a/lily/all-font-metrics.cc +++ b/lily/all-font-metrics.cc @@ -13,7 +13,6 @@ #include "warn.hh" #include "afm.hh" #include "tfm.hh" -#include "dictionary-iter.hh" #include "lily-guile.hh" #include "tfm-reader.hh" @@ -27,7 +26,8 @@ All_font_metrics::All_font_metrics (String path) Adobe_font_metric * All_font_metrics::find_afm (String name) { - if (!afm_p_dict_.elem_b (name)) + SCM sname = ly_symbol2scm (name.ch_C ()); + if (!afm_p_dict_.elem_b (sname)) { String path = name + ".afm"; path = search_path_.find (path); @@ -35,16 +35,17 @@ All_font_metrics::find_afm (String name) return 0; *mlog << "[" << path; - Adobe_font_metric - * afm_p = new Adobe_font_metric (read_afm_file (path)); + Adobe_font_metric * afm_p = read_afm_file (path); afm_p->name_str_ = name; *mlog << "]" << flush ; - afm_p_dict_[name] = afm_p; + afm_p_dict_[sname] = afm_p->self_scm_; + scm_unprotect_object (afm_p->self_scm_); } - return afm_p_dict_[name]; + + return dynamic_cast (unsmob_metrics (afm_p_dict_[sname])); } Scaled_font_metric * @@ -52,21 +53,28 @@ All_font_metrics::find_scaled (String nm, int m) { Scaled_font_metric * s=0; String index = nm + "@" + to_str (m); - if (!scaled_p_dict_.elem_b (index)) + SCM sname = ly_symbol2scm (index.ch_C ()); + + Font_metric *fm =0; + if (!scaled_p_dict_.elem_b (sname)) { Font_metric *f = find_font (nm); s = new Scaled_font_metric (f, m); - scaled_p_dict_[index] = s; - return s; + scaled_p_dict_[sname] = s->self_scm_; + fm = s; + scm_unprotect_object (s->self_scm_); } else - return scaled_p_dict_[index]; + fm = unsmob_metrics (scaled_p_dict_[sname]); + + return dynamic_cast (fm); } Tex_font_metric * All_font_metrics::find_tfm (String name) { - if (!tfm_p_dict_.elem_b (name)) + SCM sname = ly_symbol2scm (name.ch_C ()); + if (!tfm_p_dict_.elem_b (sname)) { String path = name + ".tfm"; path = search_path_.find (path); @@ -79,9 +87,12 @@ All_font_metrics::find_tfm (String name) *mlog << "]" << flush ; - tfm_p_dict_[name] = tfm_p; + tfm_p_dict_[sname] = tfm_p->self_scm_; + scm_unprotect_object (tfm_p->self_scm_); } - return tfm_p_dict_[name]; + + return + dynamic_cast (unsmob_metrics (tfm_p_dict_[sname])); } @@ -106,19 +117,40 @@ All_font_metrics::find_font (String name) error (_f ("Can't find default font: `%s'", default_font_sz_)); error (_f ("(search path: `%s'", search_path_.str ())); error (_ ("Giving up")); + + return 0; } SCM All_font_metrics::font_descriptions () const { - SCM l = SCM_EOL; - for (Dictionary_iter ai(afm_p_dict_); ai.ok (); ai++) - l = gh_cons (ai.val ()->description (), l); - for (Dictionary_iter ai(tfm_p_dict_); ai.ok (); ai++) - l = gh_cons(ai.val ()->description (), l); - - for (Dictionary_iter ai(scaled_p_dict_); ai.ok (); ai++) - l = gh_cons (ai.val ()->description (),l); - - return l; + SCM l[] = {0,0,0}; + + l[0] = afm_p_dict_.to_alist (); + l[1] = tfm_p_dict_.to_alist (); + l[2] = scaled_p_dict_.to_alist (); + + SCM list = SCM_EOL; + for (int i=0; i < 3; i++) + { + for (SCM s = l[i]; gh_pair_p (s); s = gh_cdr (s)) + { + Font_metric * fm = unsmob_metrics (gh_cdar (s)); + + list = gh_cons (fm->description (), list); + } + } + return list; +} + +Font_metric * +unsmob_metrics( SCM s) +{ + if (SMOB_IS_TYPE_B(Font_metric, s)) + return SMOB_TO_TYPE(Font_metric, s); + else + return 0; } + +#include "ly-smobs.icc" +IMPLEMENT_SMOBS(Font_metric); diff --git a/lily/beam.cc b/lily/beam.cc index 152e411cff..de137b9a38 100644 --- a/lily/beam.cc +++ b/lily/beam.cc @@ -10,13 +10,10 @@ /* [TODO] - * center beam symbol * less hairy code * move paper vars to scm - */ - -//#include +*/ #include "beaming.hh" #include "dimensions.hh" @@ -87,7 +84,7 @@ Beam::do_pre_processing () } if (!get_direction ()) - set_direction (calc_default_dir ()); + set_direction (get_default_dir ()); auto_knees (); set_stem_directions (); @@ -99,7 +96,7 @@ Beam::do_pre_processing () FIXME */ Direction -Beam::calc_default_dir () const +Beam::get_default_dir () const { Drul_array total; total[UP] = total[DOWN] = 0; @@ -529,7 +526,8 @@ Beam::quantise_dy_f (Real dy) const allowed_fraction[1] = (beam_f / 2 + staffline_f / 2); allowed_fraction[2] = (beam_f + staffline_f); - Interval iv = quantise_iv (allowed_fraction, interline_f, abs (dy)); + allowed_fraction.push (interline_f); + Interval iv = quantise_iv (allowed_fraction, abs (dy)); Real q = (abs (dy) - iv[SMALLER] <= iv[BIGGER] - abs (dy)) ? iv[SMALLER] : iv[BIGGER]; @@ -607,8 +605,9 @@ Beam::quantise_y_f (Real y, Real dy, int quant_dir) allowed_position.push (hang); } + allowed_position.push (space); Real up_y = get_direction () * y; - Interval iv = quantise_iv (allowed_position, space, up_y); + Interval iv = quantise_iv (allowed_position, up_y); Real q = up_y - iv[SMALLER] <= iv[BIGGER] - up_y ? iv[SMALLER] : iv[BIGGER]; diff --git a/lily/bezier.cc b/lily/bezier.cc index 024db5f7b8..781220d72c 100644 --- a/lily/bezier.cc +++ b/lily/bezier.cc @@ -8,622 +8,170 @@ #include #include "bezier.hh" -#include "misc.hh" - -#ifndef STANDALONE -#include "dimensions.hh" -#include "direction.hh" -#include "paper-def.hh" -#include "debug.hh" -#include "main.hh" -#define BEZIER_BOW_DEBUG_OUT if (flower_dstream && !flower_dstream->silent_b ("Bezier_bow")) cout -#else -#define BEZIER_BOW_DEBUG_OUT cerr -#endif - +#include "polynomial.hh" /* - [TODO] - * better names, esp. for all calc_foo functions - * blow_fit vs calc_default (Real) and calc_f (Real) - * exact height / tangent calculation + Formula of the bezier 3-spline + sum_{j=0}^3 (3 over j) z_j (1-t)^(3-j) t^j */ - -/* - UGH. Remove debugging junk. - */ - - -void -Curve::flipy () -{ - for (int i = 0; i < size (); i++) - (*this)[i].mirror (Y_AXIS); -} - -int -Curve::largest_disturbing () -{ - Real alpha = 0; - int j = 0; - for (int i = 1; i < size (); i++) - { - if ((*this)[i][Y_AXIS] > 0) - { - Real phi = (*this)[i][Y_AXIS] / (*this)[i][X_AXIS]; - if (phi > alpha) - { - alpha = phi; - j = i; - } - } - } - return j; -} - -void -Curve::rotate (Real phi) -{ - Offset rot (complex_exp (Offset (0, phi))); - for (int i = 0; i < size (); i++) - (*this)[i] = complex_multiply (rot, (*this)[i]); -} - -void -Curve::translate (Offset o) -{ - for (int i = 0; i < size (); i++) - (*this)[i] += o; -} - Bezier::Bezier () { - control_.set_size (4); -} - -void -Bezier::calc (int steps) -{ - steps = steps >? 10; - curve_.set_size (steps); - Real dt = 1.0 / curve_.size (); - Offset c = 3.0 * (control_[1] - control_[0]); - Offset b = 3.0 * (control_[2] - control_[1]) - c; - Offset a = control_[3] - (control_[0] + c + b); - Real t = 0.0; - for (int i = 0; i < curve_.size (); i++ ) - { - curve_[i] = ((a * t + b) * t + c) * t + control_[0]; - t += dt; - } -} - -void -Bezier::print () const -{ -#ifndef NPRINT - if (flower_dstream && !flower_dstream->silent_b ("Bezier_controls")) - { - if (control_[1].length ()) - { - cout << "Bezier\n"; - cout << "Controls: "; - for (int i=0; i < control_.size (); i++) - cout << control_[i].str () << ", "; - } - } -#endif -} - -void -Bezier::set (Array points) -{ - assert (points.size () == 4); - control_ = points; } Real -Bezier::y (Real x) +Bezier::get_other_coordinate (Axis a, Real x) const { - // ugh - // bounds func should be templatised to take array of offsets too? - Array positions; - for (int i = 0; i < curve_.size (); i++) - positions.push (curve_[i][X_AXIS]); - - Slice slice = get_bounds_slice (positions, x); - // ugh - Offset z1 = curve_[0 >? slice[BIGGER] - 1]; - Offset z2 = curve_[1 >? slice[BIGGER]]; - Real multiplier = (x - z2[X_AXIS]) / (z1[X_AXIS] - z2[X_AXIS]); - Real y = z1[Y_AXIS] * multiplier + (1.0 - multiplier) * z2[Y_AXIS]; - - return y; -} - - -Bezier_bow::Bezier_bow (Paper_def* paper_l) -{ - paper_l_ = paper_l; - return_.set_size (4); -} - -void -Bezier_bow::blow_fit () -{ - Real dy1 = check_fit_f (); - if (!dy1) - return; - - // be careful not to take too big step - Real f = 0.3; - Real h1 = dy1 * f; - control_[1][Y_AXIS] += h1; - control_[2][Y_AXIS] += h1; - return_[1][Y_AXIS] += h1; - return_[2][Y_AXIS] += h1; - - calc_bezier (); - Real dy2 = check_fit_f (); - if (!dy2) - return; - -#ifndef STANDALONE - Real internote_f = paper_l_->get_var ("interline")/2.0; -#else - Real internote_f = STAFFHEIGHT / 8; -#endif - - Real epsilon = internote_f / 4; - if (abs (dy2 - dy1) < epsilon) - return; + Axis other = Axis ((a +1)%NO_AXES); + Array ts = solve_point (a, x); - /* - Assume - dy = B (h) - with - B (h) = a * h + b; - - Then we get for h : B (h) = 0 - - B(0) = dy1 = a * 0 + b => b = dy1 - B(h1) = dy2 = a * h1 + b => a * f * dy1 + b = dy2 - - => - - a * dy1 / 2 + dy1 = dy2 => a = (dy2 - dy1) / (f * dy1) - */ - - Real a = (dy2 - dy1) / (f * dy1); - Real b = dy1; - Real h = -b / a; - - if (sign (h) != sign (h1)) - return; - - if (sign (h) != sign (h1)) - return; - - control_[1][Y_AXIS] += -h1 +h; - control_[2][Y_AXIS] += -h1 +h; - return_[1][Y_AXIS] += -h1 +h; - return_[2][Y_AXIS] += -h1 +h; -} - -void -Bezier_bow::calc_bezier () -{ - Real s = sqrt (control_[3][X_AXIS] * control_[3][X_AXIS] - + control_[1][Y_AXIS] * control_[2][Y_AXIS]); -#ifndef STANDALONE - Real internote = paper_l_->get_var ("interline")/2.0; -#else - Real internote = STAFFHEIGHT / 8; -#endif - int steps = (int)rint (s / internote); - Bezier::calc (steps); + Offset c = curve_point (ts[0]); + assert (fabs (c[a] - x) < 1e-8); + + return c[other]; } Real -Bezier_bow::calc_f (Real height) +binomial_coefficient (Real over , int under) { - transform (); - calc_default (height); - calc_bezier (); + Real x = 1.0; - Real dy = check_fit_f (); - calc_return (0, 0); + while (under) + { + x *= over / Real (under); - transform_back (); - return dy; + over -= 1.0; + under --; + } + return x; } -void -Bezier_bow::calc () +Offset +Bezier::curve_point (Real t)const { -#ifndef NPRINT -// if (flower_dstream && !flower_dstream->silent_b ("Bezier_bow_controls")) - if (flower_dstream && !(flower_dstream->silent_b ("Bezier_controls") - && flower_dstream->silent_b ("Bezier_bow_controls"))) - { - cout << "Before transform*********\n"; - print (); - cout << "************************\n"; - } -#endif - transform (); - print (); - - calc_controls (); + Real tj = 1; + Real one_min_tj = (1-t)*(1-t)*(1-t); - /* - duh, this is crude (control-points) - perhaps it's even better to check the amount of blow_fit () - */ - for (int i=0; i < control_.size (); i++) + Offset o; + for (int j=0 ; j < 4; j++) { - Real y = control_[i][Y_AXIS]; - curve_extent_drul_[Y].unite (Interval (y, y)); - Real x = control_[i][X_AXIS]; - curve_extent_drul_[X].unite (Interval (x, x)); - } + o += control_[j] * binomial_coefficient (3, j) + * pow (t,j) * pow (1-t, 3-j); - print (); - transform_back (); -#ifndef NPRINT -// if (flower_dstream && !flower_dstream->silent_b ("Bezier_bow_controls")) - if (flower_dstream && !(flower_dstream->silent_b ("Bezier_controls") - && flower_dstream->silent_b ("Bezier_bow_controls"))) - { - cout << "After transform*********\n"; - print (); - cout << "************************\n"; + tj *= t; + if (1-t) + one_min_tj /= (1-t); } -#endif -} -/* - [TODO] - * see if it works - * document in Documentation/fonts.tex - */ - -/* - Clipping - - This function tries to address two issues: - * the tangents of the slur should always point inwards - in the actual slur, i.e. *after rotating back*. - - * slurs shouldn't be too high - let's try : h <= 1.2 b && h <= 3 staffheight? + assert (fabs (o[X_AXIS] - polynomial (X_AXIS).eval (t))< 1e-8); + assert (fabs (o[Y_AXIS] - polynomial (Y_AXIS).eval (t))< 1e-8); - We could calculate the tangent of the bezier curve from - both ends going inward, and clip the slur at the point - where the tangent (after rotation) points up (or inward - with a certain maximum angle). - However, we assume that real clipping is not the best - answer. We expect that moving the outer control point up - if the slur becomes too high will result in a nicer slur - after recalculation. + return o; +} - Knowing that the tangent is the line through the first - two control points, we'll clip (move the outer control - point upwards) too if the tangent points outwards. - */ -bool -Bezier_bow::calc_clipping () +Polynomial +Bezier::polynomial (Axis a)const { -#ifndef STANDALONE - Real clip_height = paper_l_->get_var ("slur_clip_height"); - Real clip_ratio = paper_l_->get_var ("slur_clip_ratio"); - Real clip_angle = paper_l_->get_var ("slur_clip_angle"); -#else - Real staffsize_f = STAFFHEIGHT; - Real clip_height = 3.0 * staffsize_f; - Real clip_ratio = 1.2; - Real clip_angle = 100; -#endif - - Real b = control_[3][X_AXIS] - control_[0][X_AXIS]; - Real clip_h = clip_ratio * b ? begin_h - clip_h; - Real end_dy = 0 >? end_h - clip_h; - - Real pi = M_PI; - Real begin_alpha = (control_[1] - control_[0]).arg () + get_direction () * alpha_; - Real end_alpha = pi - (control_[2] - control_[3]).arg () - get_direction () * alpha_; - - Real max_alpha = clip_angle / 90 * pi / 2; - if ((begin_dy < 0) && (end_dy < 0) - && (begin_alpha < max_alpha) && (end_alpha < max_alpha)) - return false; - - transform_back (); - - bool again = true; - - if ((begin_dy > 0) || (end_dy > 0)) + Polynomial p (0.0); + for (int j=0; j <= 3; j++) { - Real dy = (begin_dy + end_dy) / 4; - dy *= cos (alpha_); - encompass_[0][Y_AXIS] += get_direction () * dy; - encompass_[encompass_.size () - 1][Y_AXIS] += get_direction () * dy; + p += control_[j][a] + * Polynomial::power (j , Polynomial (0,1))* + Polynomial::power (3 - j, Polynomial (1,-1))* + binomial_coefficient(3, j); } - else - { - //ugh - Real c = 0.4; - if (begin_alpha >= max_alpha) - begin_dy = 0 >? c * begin_alpha / max_alpha * begin_h; - if (end_alpha >= max_alpha) - end_dy = 0 >? c * end_alpha / max_alpha * end_h; - - encompass_[0][Y_AXIS] += get_direction () * begin_dy; - encompass_[encompass_.size () - 1][Y_AXIS] += get_direction () * end_dy; - Offset delta = encompass_[encompass_.size () - 1] - encompass_[0]; - alpha_ = delta.arg (); - } - - transform (); - - return again; + return p; } -void -Bezier_bow::calc_controls () +/** + Remove all numbers outside [0,1] from SOL + */ +Array +filter_solutions (Array sol) { - for (int i = 0; i < 3; i++) - { - if (i && !calc_clipping ()) - return; - - /* - why do we always recalc from 0? - shouldn't calc_f () be used (too), rather than blow_fit () (only)? - */ - calc_default (0); - calc_bezier (); - - if (check_fit_bo ()) - { - calc_return (0, 0); - return; - } - calc_tangent_controls (); - - blow_fit (); - // ugh - blow_fit (); - } + for (int i = sol.size (); i--;) + if (sol[i] < 0 || sol[i] >1) + sol.del (i); + return sol; } -void -Bezier_bow::calc_return (Real begin_alpha, Real end_alpha) +/** + find t such that derivative is proportional to DERIV + */ +Array +Bezier::solve_derivative (Offset deriv)const { -#ifndef STANDALONE - Real thick = paper_l_->get_var ("slur_thickness"); -#else - Real thick = 1.8 * 0.4 PT; -#endif + Polynomial xp[2]; - return_[0] = control_[3]; - return_[3] = control_[0]; - - return_[1] = control_[2] - thick * complex_exp (Offset (0, 90 + end_alpha)); - return_[2] = control_[1] - - thick * complex_exp (Offset (0, 90 - begin_alpha)); + xp[X_AXIS] = polynomial (X_AXIS); + xp[Y_AXIS] = polynomial (Y_AXIS); + Polynomial combine = xp[X_AXIS] * deriv[Y_AXIS] - xp[Y_AXIS] * deriv [X_AXIS]; + return filter_solutions (combine.solve ()); } + /* - See Documentation/fonts.tex - */ -void -Bezier_bow::calc_tangent_controls () + Find t such that curve_point (t)[AX] == COORDINATE +*/ +Array +Bezier::solve_point (Axis ax, Real coordinate) const { - Offset ijk_p (control_[3][X_AXIS] / 2, control_[1][Y_AXIS]); - BEZIER_BOW_DEBUG_OUT << "ijk: " << ijk_p[X_AXIS] << ", " << ijk_p[Y_AXIS] << endl; - - Real default_rc = ijk_p[Y_AXIS] / ijk_p[X_AXIS]; - - int begin_disturb = encompass_.largest_disturbing (); - Offset begin_p = begin_disturb ? Offset (encompass_[begin_disturb][X_AXIS], - encompass_[begin_disturb][Y_AXIS]) : ijk_p; - Real begin_rc = begin_p[Y_AXIS] / begin_p[X_AXIS]; - if (default_rc > begin_rc) - { - begin_p = ijk_p; - begin_rc = default_rc; - } - - Curve reversed; - reversed.set_size (encompass_.size ()); - Real b = control_[3][X_AXIS]; - for (int i = 0; i < encompass_.size (); i++ ) - { - // b 1 0 - // r = - * c - // 0 0 -1 - reversed[i][X_AXIS] = b - encompass_[encompass_.size () - i - 1][X_AXIS]; - reversed[i][Y_AXIS] = encompass_[encompass_.size () - i - 1][Y_AXIS]; - } - - int end_disturb = reversed.largest_disturbing (); - end_disturb = end_disturb ? encompass_.size () - end_disturb - 1 : 0; - Offset end_p = end_disturb ? Offset (encompass_[end_disturb][X_AXIS], - encompass_[end_disturb][Y_AXIS]) : ijk_p; - Real end_rc = end_p[Y_AXIS] / (control_[3][X_AXIS] - end_p[X_AXIS]); - if (default_rc > end_rc) - { - end_p = ijk_p; - end_rc = default_rc; - } - - Real height =control_[1][Y_AXIS]; - for (int i = 0; i < encompass_.size (); i++ ) - height = height >? encompass_[i][Y_AXIS]; - - // emperic computer science: - // * tangents somewhat steeper than minimal line -#ifndef STANDALONE - Real internote = paper_l_->get_var ("interline")/2.0; - Real rc_correct = paper_l_->get_var ("slur_rc_factor"); -#else - Real internote = STAFFHEIGHT / 8; - Real rc_correct = 2.4; -#endif - - begin_rc *= rc_correct; - end_rc *= rc_correct; - Real rc1 = begin_rc; - Real rc2 = -end_rc; + Polynomial p(polynomial (ax)); + p.coefs_[0] -= coordinate; - Real begin_alpha = atan (begin_rc); - Real end_alpha = atan (-end_rc); - Real theta = (begin_alpha - end_alpha) / 2; - - Real epsilon = internote / 5; - - // if we have two disturbing points, have height line through those... - if (!((abs (begin_p[X_AXIS] - end_p[X_AXIS]) < epsilon) - && (abs (begin_p[Y_AXIS] - end_p[Y_AXIS]) < epsilon))) - theta = atan (end_p[Y_AXIS] - begin_p[Y_AXIS]) / (end_p[X_AXIS] - begin_p[X_AXIS]); - - Real rc3 = tan (theta); - // ugh: be less steep - rc3 /= 2*rc_correct; - - Real c2 = -rc2 * control_[3][X_AXIS]; - Real c3 = begin_p[Y_AXIS] > end_p[Y_AXIS] ? begin_p[Y_AXIS] - - rc3 * begin_p[X_AXIS] : end_p[Y_AXIS] - rc3 * end_p[X_AXIS]; - - control_[1][X_AXIS] = c3 / (rc1 - rc3); - control_[1][Y_AXIS] = rc1 * control_[1][X_AXIS]; - control_[2][X_AXIS] = (c3 - c2) / (rc2 - rc3); - control_[2][Y_AXIS] = rc2 * control_[2][X_AXIS] + c2; - - calc_return (begin_alpha, end_alpha); -} - -bool -Bezier_bow::check_fit_bo () -{ - for (int i = 1; i < encompass_.size () - 1; i++) - if ((encompass_[i][X_AXIS] > encompass_[0][X_AXIS]) - && (encompass_[i][X_AXIS] < encompass_[encompass_.size () -1][X_AXIS])) - if (encompass_[i][Y_AXIS] > y (encompass_[i][X_AXIS])) - return false; - return true; -} - -Real -Bezier_bow::check_fit_f () -{ - Real dy = 0; - for (int i = 1; i < encompass_.size () - 1; i++) - if ((encompass_[i][X_AXIS] > encompass_[0][X_AXIS]) - && (encompass_[i][X_AXIS] < encompass_[encompass_.size () -1][X_AXIS])) - dy = dy >? (encompass_[i][Y_AXIS] - y (encompass_[i][X_AXIS])); - return dy; + Array sol (p.solve ()); + return filter_solutions (sol); } -void -Bezier_bow::print () const +Interval +Bezier::extent (Axis a)const { -#ifndef NPRINT - Bezier::print (); - if (flower_dstream && !flower_dstream->silent_b ("Bezier_bow_controls")) + int o = (a+1)%NO_AXES; + Offset d; + d[Axis (o)] =1.0; + Interval iv; + Array sols (solve_derivative (d)); + sols.push (1.0); + sols.push (0.0); + for (int i= sols.size (); i--;) { - cout << "Bezier_bow\n"; - cout << "Encompass: "; - for (int i=0; i < encompass_.size (); i++) - cout << encompass_[i].str () << ", "; -// cout << "\n"; + Offset o (curve_point (sols[i])); + iv.unite (Interval (o[a],o[a])); } -#endif + return iv; } void -Bezier_bow::set (Array points, Direction dir) +Bezier::flip (Axis a) { - set_direction (dir); - encompass_ = points; + for (int i = CONTROL_COUNT; i--;) + control_[i][a] = - control_[i][a]; } void -Bezier_bow::transform () +Bezier::rotate (Real phi) { - origin_ = encompass_[0]; - encompass_.translate (-origin_); - - Offset delta = encompass_[encompass_.size () - 1] - encompass_[0]; - alpha_ = delta.arg (); - - encompass_.rotate (-alpha_); - - if (get_direction () == DOWN) - encompass_.flipy (); + Offset rot (complex_exp (Offset (0, phi))); + for (int i = 0; i < CONTROL_COUNT; i++) + control_[i] = complex_multiply (rot, control_[i]); } void -Bezier_bow::transform_back () +Bezier::translate (Offset o) { - if (get_direction () == DOWN) - { - control_.flipy (); - return_.flipy (); - encompass_.flipy (); - } - - control_.rotate (alpha_); - control_.translate (origin_); - - return_.rotate (alpha_); - return_.translate (origin_); - - encompass_.rotate (alpha_); - encompass_.translate (origin_); + for (int i = 0; i < CONTROL_COUNT; i++) + control_[i] += o; } -/* - See Documentation/fonts.tex - */ void -Bezier_bow::calc_default (Real h) +Bezier::check_sanity () const { - Real pi = M_PI; -#ifndef STANDALONE - Real height_limit = paper_l_->get_var ("slur_height_limit"); - Real ratio = paper_l_->get_var ("slur_ratio"); -#else - Real staffsize_f = STAFFHEIGHT; - Real height_limit = staffsize_f; - Real ratio = 1.0/3.0; -#endif - - Real alpha = height_limit * 2.0 / pi; - Real beta = pi * ratio / (2.0 * height_limit); - - Offset delta (encompass_[encompass_.size () - 1][X_AXIS] - - encompass_[0][X_AXIS], 0); - Real b = delta.length (); - Real indent = alpha * atan (beta * b); - Real height = indent + h; - - Array control; - control.push (Offset (0, 0)); - control.push (Offset (indent, height)); - control.push (Offset (b - indent, height)); - control.push (Offset (b, 0)); - Bezier::set (control); + for (int i=0; i < CONTROL_COUNT; i++) + assert (!isnan (control_[i].length ()) + && !isinf (control_[i].length ())); } - - diff --git a/lily/bow.cc b/lily/bow.cc index 5d44313d04..70ea171995 100644 --- a/lily/bow.cc +++ b/lily/bow.cc @@ -13,7 +13,7 @@ #include "paper-def.hh" #include "molecule.hh" #include "lookup.hh" -#include "bezier.hh" +#include "bezier-bow.hh" #include "main.hh" Bow::Bow () @@ -65,13 +65,13 @@ Bow::dim_callback (Dimension_cache const* c) return iv; } -Drul_array -Bow::curve_extent_drul () const +Interval +Bow::curve_extent (Axis a) const { Bezier_bow b (paper_l ()); b.set (get_encompass_offset_arr (), get_direction ()); b.calc (); - return b.curve_extent_drul_; + return b.curve_.extent (a); } Array @@ -81,11 +81,10 @@ Bow::get_controls () const b.set (get_encompass_offset_arr (), get_direction ()); b.calc (); Array controls; - controls.set_size (8); for (int i = 0; i < 4; i++) - controls[i] = b.control_[i]; + controls.push (b.curve_.control_[i]); for (int i = 0; i < 4; i++) - controls[i + 4] = b.return_[i]; + controls.push (b.return_.control_[i]); return controls; } diff --git a/lily/break-algorithm.cc b/lily/break-algorithm.cc index 40d7b84e97..9e242d22f0 100644 --- a/lily/break-algorithm.cc +++ b/lily/break-algorithm.cc @@ -24,7 +24,7 @@ Array Break_algorithm::find_break_indices () const { - Line_of_cols all (pscore_l_->col_l_arr_); + Link_array all (pscore_l_->col_l_arr_); Array retval; for (int i=0; i < all.size (); i++) @@ -39,11 +39,11 @@ Break_algorithm::find_break_indices () const } -Line_of_cols +Link_array Break_algorithm::find_breaks () const { - Line_of_cols all (pscore_l_->col_l_arr_); - Line_of_cols retval; + Link_array all (pscore_l_->col_l_arr_); + Link_array retval; for (int i=0; i < all.size (); i++) if (all[i]->breakable_b ()) @@ -58,7 +58,7 @@ Break_algorithm::find_breaks () const Simple_spacer* -Break_algorithm::generate_spacing_problem (Line_of_cols curline, Interval line) const +Break_algorithm::generate_spacing_problem (Link_array curline, Interval line) const { Simple_spacer * sp = new Simple_spacer; Paper_def * d = pscore_l_->paper_l_; diff --git a/lily/break-align-item.cc b/lily/break-align-item.cc index c4b6963bbc..7a5b9f9f09 100644 --- a/lily/break-align-item.cc +++ b/lily/break-align-item.cc @@ -70,7 +70,7 @@ Break_align_item::do_pre_processing() SCM extra_space = scm_eval (scm_listify (ly_symbol2scm ("break-align-spacer"), current_origin, next_origin, SCM_UNDEFINED)); - SCM symbol = SCM_CAR (extra_space); + SCM symbol = gh_car (extra_space); Real spc = gh_scm2double (SCM_CADR(extra_space)); spc *= interline; @@ -81,15 +81,15 @@ Break_align_item::do_pre_processing() // skip the first sym. - symbol_list = SCM_CDR (scm_reverse (symbol_list)); + symbol_list = gh_cdr (scm_reverse (symbol_list)); for (int i=0; i set_elt_property (sym_str, scm_cons (gh_double2scm (0), gh_double2scm (dists[i+1]))); - symbol_list = SCM_CDR (symbol_list); + symbol_list = gh_cdr (symbol_list); } @@ -113,12 +113,12 @@ Break_align_item::do_pre_processing() Real stretch_distance =0.; - if (SCM_CAR (symbol_list) == ly_symbol2scm ("extra-space")) + if (gh_car (symbol_list) == ly_symbol2scm ("extra-space")) { spring_len += dists.top (); stretch_distance = dists.top (); } - else if (SCM_CAR (symbol_list) == ly_symbol2scm ("minimum-space")) + else if (gh_car (symbol_list) == ly_symbol2scm ("minimum-space")) { spring_len = spring_len >? dists.top (); stretch_distance = spring_len; diff --git a/lily/chord.cc b/lily/chord.cc index 30a5ae9300..9f45be7e63 100644 --- a/lily/chord.cc +++ b/lily/chord.cc @@ -220,8 +220,6 @@ Chord::~Chord () { delete inversion_p_; delete bass_p_; - // AAARGH, why doesn't Score_elt do this? - unsmobify_self (); } Array @@ -539,7 +537,7 @@ Chord::user_chord_name (Array pitch_arr, Chord_name* name_p) cons chord = gh_cons (pitch2scm (chord_type[i]), chord); SCM name = scm_eval (gh_list (ly_symbol2scm ("user-chord-name"), ly_quote_scm (chord), SCM_UNDEFINED)); - if (name != SCM_UNSPECIFIED) + if (gh_pair_p (name)) { name_p->modifier_mol = ly_text2molecule (gh_car (name)); name_p->addition_mol = ly_text2molecule (gh_cdr (name)); diff --git a/lily/column-x-positions.cc b/lily/column-x-positions.cc index 2532610973..8c5c6186d7 100644 --- a/lily/column-x-positions.cc +++ b/lily/column-x-positions.cc @@ -17,19 +17,6 @@ Column_x_positions::Column_x_positions() force_f_ = 0; } -Column_x_positions::~Column_x_positions() -{ -} - - -void -Column_x_positions::print() const -{ -#ifndef NPRINT - DEBUG_OUT << "energy : " << energy_f_ << '\n'; - DEBUG_OUT << "line of " << config_.size() << " cols\n"; -#endif -} diff --git a/lily/crescendo.cc b/lily/crescendo.cc index ccd2e91b80..ebaf874cf0 100644 --- a/lily/crescendo.cc +++ b/lily/crescendo.cc @@ -13,6 +13,7 @@ #include "paper-def.hh" #include "debug.hh" #include "score-column.hh" +#include "atom.hh" Crescendo::Crescendo () { @@ -20,24 +21,34 @@ Crescendo::Crescendo () dyn_b_drul_[LEFT] = dyn_b_drul_[RIGHT] =false; } -Molecule -Crescendo::get_symbol () const + + +Molecule* +Crescendo::do_brew_molecule_p () const { - Real w_dim = spanner_length()- get_broken_left_end_align (); Real absdyn_dim = paper_l ()-> get_var ("crescendo_shorten"); + Real extra_left = get_broken_left_end_align (); + + if (dyn_b_drul_[LEFT]) + extra_left += absdyn_dim; + + + + Real width = spanner_length()- get_broken_left_end_align (); + if (dyn_b_drul_[LEFT]) { - w_dim -= absdyn_dim; + width -= absdyn_dim; } if (dyn_b_drul_[RIGHT]) { - w_dim -= absdyn_dim; + width -= absdyn_dim; } - if (w_dim < 0) + if (width < 0) { warning (_ ("crescendo") + " " + _ ("too small")); - w_dim = 0; + width = 0; } Drul_array broken; @@ -52,24 +63,22 @@ Crescendo::get_symbol () const 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_var ("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; + const char* hairpin = (grow_dir_ < 0)? "decrescendo" : "crescendo"; + Atom at (gh_list (ly_symbol2scm (hairpin), + gh_double2scm (thick), + gh_double2scm (width), + gh_double2scm (height), + gh_double2scm (continued ? height/2 : 0.0), + SCM_UNDEFINED)); + Molecule * m + = new Molecule; + + m->dim_.x () = Interval (0, width); + m->dim_.y () = Interval (-2*height, 2*height); + m->add_atom (&at); + + m->translate_axis (extra_left, X_AXIS); + return m; } diff --git a/lily/debug.cc b/lily/debug.cc index 35a32a7a28..9edbf4ac6b 100644 --- a/lily/debug.cc +++ b/lily/debug.cc @@ -6,6 +6,7 @@ (c) 1996,98 Han-Wen Nienhuys */ + #include #include @@ -39,59 +40,6 @@ debug_init() bool check_malloc_b = false; -// #define MEMORY_PARANOID - -#ifdef MEMORY_PARANOID - -#include - -void -frobnify (void *p, size_t s) -{ - char *cp = (char*)p; - char *e = cp + s; - while (cp < e) - { - *cp++ ^=42; - } -} - - -void * -operator new (size_t size) -{ - void *result; - result = malloc (size); - if (check_malloc_b) - frobnify (result, size); - return result; -} - -void *to_frob; int frob_size; - -void -set_frobnify (void * p, size_t sz) -{ - to_frob = p; - frob_size = sz; -} - -void -operator delete (void *p) -{ - if (!p) - return ; - if (p == to_frob) - { - frobnify (p, frob_size); - to_frob = 0; - frob_size=0; - } - - free (p); -} -#endif // MEMORY_PARANOID - void set_debug (bool b) { diff --git a/lily/dimension-cache.cc b/lily/dimension-cache.cc index ce851df2bd..f7757ee820 100644 --- a/lily/dimension-cache.cc +++ b/lily/dimension-cache.cc @@ -31,7 +31,6 @@ void Dimension_cache::init() { callback_l_ =0; - basic_offset_ =0.0; extra_offset_ =0.0; @@ -43,27 +42,6 @@ Dimension_cache::init() } -void -Dimension_cache::invalidate () -{ - /* off_valid_b_ =false; - valid_b_ = false;*/ -} - - -void -Dimension_cache::set_offset (Real x) -{ - // ugh! - /* - - UGH ! UGH ! - - */ - - extra_offset_ = x; -} - void Dimension_cache::translate (Real x) { @@ -141,7 +119,6 @@ Dimension_cache::get_dim () const } else if (!valid_b_) { - nc->dim_= (*callback_l_ ) (nc); nc->valid_b_ = true; } diff --git a/lily/dots.cc b/lily/dots.cc index 92d564478e..fc3c57e0dd 100644 --- a/lily/dots.cc +++ b/lily/dots.cc @@ -32,7 +32,7 @@ Dots::do_post_processing () set_direction (UP); Staff_symbol_referencer_interface si (this); - int p = si.position_f (); + int p = int (si.position_f ()); if (!(p % 2)) si.set_position (p + get_direction ()); } diff --git a/lily/engraver-group-engraver.cc b/lily/engraver-group-engraver.cc index 8420c7fa3b..610b9890ec 100644 --- a/lily/engraver-group-engraver.cc +++ b/lily/engraver-group-engraver.cc @@ -26,19 +26,14 @@ Engraver_group_engraver::announce_element (Score_element_info info) void Engraver_group_engraver::do_announces() { - Link_array groups = group_l_arr (); - for (int i=0; i < groups.size(); i++) + for (Cons *p = trans_p_list_.head_; p; p = p->next_) { - Engraver_group_engraver * group = dynamic_cast (groups[i]); - if (group) - { - group->do_announces(); - } + if (Engraver_group_engraver *trg = dynamic_cast (p->car_)) + trg->do_announces (); } - + Request dummy_req; - Link_array nongroups = nongroup_l_arr (); while (announce_info_arr_.size ()) { for (int j =0; j < announce_info_arr_.size(); j++) @@ -47,21 +42,28 @@ Engraver_group_engraver::do_announces() if (!info.req_l_) info.req_l_ = &dummy_req; - for (int i=0; i < nongroups.size(); i++) - { // Is this good enough? - Engraver * eng = dynamic_cast (nongroups[i]); - if (eng && eng!= info.origin_trans_l_arr_[0]) - eng->acknowledge_element (info); + + for (Cons *p = trans_p_list_.head_; p; p = p->next_) + { + if (!dynamic_cast (p->car_)) + { + Engraver * eng = dynamic_cast (p->car_); + if (eng && eng!= info.origin_trans_l_arr_[0]) + eng->acknowledge_element (info); + } } } + announce_info_arr_.clear (); - for (int i=0; i < nongroups.size(); i++) + for (Cons *p = trans_p_list_.head_; p; p = p->next_) { - Engraver * eng = dynamic_cast (nongroups[i]); - if (eng) - eng->process_acknowledged (); + if (!dynamic_cast (p->car_)) + { + Engraver * eng = dynamic_cast (p->car_); + if (eng) + eng->process_acknowledged (); + } } - } } @@ -71,12 +73,14 @@ Engraver_group_engraver::get_staff_info() const { Staff_info inf = Engraver::get_staff_info(); - Link_array simple_translators = nongroup_l_arr (); - for (int i=0; i < simple_translators.size(); i++) + for (Cons *p = trans_p_list_.head_; p; p = p->next_) { - Engraver * eng = dynamic_cast (simple_translators[i]); - if (eng) - eng->fill_staff_info (inf); + if (!dynamic_cast (p->car_)) + { + Engraver * eng = dynamic_cast (p->car_); + if (eng) + eng->fill_staff_info (inf); + } } return inf; } diff --git a/lily/font-metric.cc b/lily/font-metric.cc index 8c8a8e31a7..e542a73cfe 100644 --- a/lily/font-metric.cc +++ b/lily/font-metric.cc @@ -65,6 +65,17 @@ Character_metric::dimensions () const } Font_metric::~Font_metric () +{ + unsmobify_self (); +} + +Font_metric::Font_metric () +{ + self_scm_ = SCM_EOL; + smobify_self (); +} + +Font_metric::Font_metric (Font_metric const &) { } @@ -98,3 +109,27 @@ Scaled_font_metric::description () const gh_set_cdr_x (od, gh_int2scm (magstep_i_)); return od; } + + +void +Font_metric::do_smobify_self () +{ +} + +SCM +Font_metric::mark_smob (SCM s) +{ + return SCM_EOL; +} + +int +Font_metric::print_smob (SCM s, SCM port, scm_print_state * ) +{ + scm_puts ("#", port); + + return 1; +} + + + + diff --git a/lily/gourlay-breaking.cc b/lily/gourlay-breaking.cc index 130f1a0821..9ea2b8259e 100644 --- a/lily/gourlay-breaking.cc +++ b/lily/gourlay-breaking.cc @@ -51,7 +51,7 @@ Array Gourlay_breaking::do_solve () const { Array optimal_paths; - Line_of_cols all = pscore_l_->col_l_arr_ ; + Link_array all = pscore_l_->col_l_arr_ ; Array breaks = find_break_indices (); optimal_paths.set_size (breaks.size ()); @@ -76,7 +76,7 @@ Gourlay_breaking::do_solve () const for (int start_idx = break_idx; start_idx--;) { - Line_of_cols line = all.slice (breaks[start_idx], breaks[break_idx]+1); + Link_array line = all.slice (breaks[start_idx], breaks[break_idx]+1); line[0] = dynamic_cast(line[0]->find_broken_piece (RIGHT)); line.top () = dynamic_cast(line.top ()->find_broken_piece (LEFT)); diff --git a/lily/grace-performer-group.cc b/lily/grace-performer-group.cc index da7b622c3f..45c47ca37f 100644 --- a/lily/grace-performer-group.cc +++ b/lily/grace-performer-group.cc @@ -100,13 +100,6 @@ Grace_performer_group::each (Const_method_pointer method) const bool Grace_performer_group::do_try_music (Music *m) { - bool hebbes_b =false; - - Link_array nongroups (nongroup_l_arr ()); - - for (int i =0; !hebbes_b && i < nongroups.size() ; i++) - hebbes_b =nongroups[i]->try_music (m); - - return hebbes_b; + return try_music_on_nongroup_children (m); } diff --git a/lily/include/afm.hh b/lily/include/afm.hh index 263deb8b62..8c5c0ed9ca 100644 --- a/lily/include/afm.hh +++ b/lily/include/afm.hh @@ -58,7 +58,7 @@ struct Adobe_font_metric : Font_metric { Character_metric const *get_char (int, bool) const; }; -Adobe_font_metric read_afm_file (String fn); +Adobe_font_metric *read_afm_file (String fn); diff --git a/lily/include/all-font-metrics.hh b/lily/include/all-font-metrics.hh index 432da7ea4c..f581d65e9e 100644 --- a/lily/include/all-font-metrics.hh +++ b/lily/include/all-font-metrics.hh @@ -14,16 +14,17 @@ #include "file-path.hh" #include "lily-proto.hh" #include "font-metric.hh" -#include "lily-guile.hh" +#include "scm-hash.hh" /** Interface to all .afm files living in the filesystem. */ class All_font_metrics { - Dictionary afm_p_dict_; - Dictionary tfm_p_dict_; - Dictionary scaled_p_dict_; + Scheme_hash_table afm_p_dict_; + Scheme_hash_table tfm_p_dict_; + Scheme_hash_table scaled_p_dict_; + File_path search_path_; public: @@ -37,7 +38,7 @@ public: SCM font_descriptions () const; }; - +Font_metric * unsmob_metrics (SCM s); #endif /* ALL_FONTS_HH */ diff --git a/lily/include/beam.hh b/lily/include/beam.hh index ff53282f52..13e3421f0c 100644 --- a/lily/include/beam.hh +++ b/lily/include/beam.hh @@ -36,14 +36,6 @@ public: Stem* first_visible_stem () const; Stem* last_visible_stem () const; - /** - the slope of the beam in dy/dx - */ - Real dydx_f_; - - /// position of leftmost end of beam - Real left_y_; - Beam (); void add_stem (Stem*); void set_grouping (Rhythmic_grouping def, Rhythmic_grouping current); @@ -61,7 +53,7 @@ protected: Molecule stem_beams (Stem *here, Stem *next, Stem *prev) const; private: - Direction calc_default_dir () const; + Direction get_default_dir () const; void set_stem_directions (); void auto_knees (); bool auto_knee (String gap_str, bool interstaff_b); @@ -75,7 +67,6 @@ private: Real quantise_dy_f (Real dy) const; Real quantise_y_f (Real y, Real dy, int quant_dir); int forced_stem_count () const; - }; #endif // BEAM_HH diff --git a/lily/include/bezier-bow.hh b/lily/include/bezier-bow.hh new file mode 100644 index 0000000000..75acd8e471 --- /dev/null +++ b/lily/include/bezier-bow.hh @@ -0,0 +1,58 @@ +/* + bezier-bow.hh -- declare Bezier_bow + + source file of the GNU LilyPond music typesetter + + (c) 1999 Han-Wen Nienhuys + + */ + +#ifndef BEZIER_BOW_HH +#define BEZIER_BOW_HH + +#include "bezier.hh" +#include "lily-proto.hh" + + +/** + Implement bow specific bezier curve + */ +class Bezier_bow +{ +public: + Bezier_bow (Paper_def* paper_l); + + /** + Calculate bezier curve for bow from bow paratime_signatures. + */ + void blow_fit (); + void calc (); + Real calc_f (Real height); + void calc_bezier (); + bool calc_clipping (); + void calc_controls (); + void check_sanity () const; + void calc_default (Real h); + void calc_return (Real begin_alpha, Real end_alpha); + void calc_tangent_controls (); + bool check_fit_b () const; + Real check_fit_f () const; + void set (Array points, Direction dir); + void transform (); + void transform_back (); + + Array encompass_; + + Paper_def* paper_l_; + Direction dir_; + Real alpha_; + Offset origin_; + + + Bezier curve_; + Bezier return_; +}; + + +#endif /* BEZIER_BOW_HH */ + diff --git a/lily/include/bezier.hh b/lily/include/bezier.hh index 73b6079104..a2c5df48c8 100644 --- a/lily/include/bezier.hh +++ b/lily/include/bezier.hh @@ -7,14 +7,14 @@ #ifndef BEZIER_HH #define BEZIER_HH -#ifndef STANDALONE -#include "lily-proto.hh" -#endif #include "real.hh" -#include "curve.hh" #include "drul-array.hh" #include "interval.hh" +#include "axes.hh" +#include "offset.hh" +#include "array.hh" +#include "polynomial.hh" /** Simple bezier curve @@ -24,60 +24,19 @@ class Bezier public: Bezier (); - /** - Calculate bezier curve into Offset (x,y) array. - */ - void calc (int steps); - void print () const; - - void set (Array points); - - /** - Return y that goes with x by interpolation. - */ - Real y (Real x); - - Curve curve_; - Curve control_; -}; - -/** - Implement bow specific bezier curve - */ -class Bezier_bow : public Bezier -{ -public: - Bezier_bow (Paper_def* paper_l); - - /** - Calculate bezier curve for bow from bow paratime_signatures. - */ - void blow_fit (); - void calc (); - Real calc_f (Real height); - void calc_bezier (); - bool calc_clipping (); - void calc_controls (); - void calc_default (Real h); - void calc_return (Real begin_alpha, Real end_alpha); - void calc_tangent_controls (); - bool check_fit_bo (); - Real check_fit_f (); - void print () const; - void set (Array points, Direction dir); - void transform (); - void transform_back (); - - Paper_def* paper_l_; - Curve encompass_; - Direction dir_; - void set_direction (Direction d ) { dir_ = d; } - Direction get_direction () const { return dir_; } - - Real alpha_; - Offset origin_; - Curve return_; - Drul_array curve_extent_drul_; + void rotate (Real); + void translate (Offset); + void flip (Axis); + void check_sanity () const; + Real get_other_coordinate (Axis a, Real x) const; + Array solve_point (Axis, Real coordinate) const; + Array solve_derivative (Offset) const; + Interval extent (Axis)const; + Polynomial polynomial (Axis)const; + Offset curve_point (Real t) const; + + static const int CONTROL_COUNT = 4; + Offset control_[CONTROL_COUNT]; }; diff --git a/lily/include/bow.hh b/lily/include/bow.hh index 132ae263a6..99de88b237 100644 --- a/lily/include/bow.hh +++ b/lily/include/bow.hh @@ -11,7 +11,6 @@ #define BOW_HH #include "directional-spanner.hh" -#include "curve.hh" /** Base class for anything that looks like a slur. @@ -33,7 +32,7 @@ protected: Array get_controls () const; virtual Array get_encompass_offset_arr () const; static Interval dim_callback (Dimension_cache const*); - Drul_array curve_extent_drul () const; + Interval curve_extent (Axis) const; Drul_array dy_f_drul_; Drul_array dx_f_drul_; diff --git a/lily/include/break-algorithm.hh b/lily/include/break-algorithm.hh index 8a25d7b554..50521bbca6 100644 --- a/lily/include/break-algorithm.hh +++ b/lily/include/break-algorithm.hh @@ -28,7 +28,7 @@ protected: Real linewidth_f_; /// search all pcols which are breakable. - Line_of_cols find_breaks() const; + Link_array find_breaks() const; Array find_break_indices() const; @@ -40,10 +40,10 @@ protected: void approximate_solve_line (Column_x_positions*) const; /// does curline fit on the paper? - bool feasible (Line_of_cols) const; + bool feasible (Link_array) const; - Simple_spacer* generate_spacing_problem (Line_of_cols, Interval) const; + Simple_spacer* generate_spacing_problem (Link_array, Interval) const; virtual Array do_solve() const=0; virtual void do_set_pscore(); diff --git a/lily/include/column-x-positions.hh b/lily/include/column-x-positions.hh index d124535153..30ee56c2b2 100644 --- a/lily/include/column-x-positions.hh +++ b/lily/include/column-x-positions.hh @@ -10,20 +10,17 @@ #include "parray.hh" #include "lily-proto.hh" -typedef Link_array Line_of_cols; -struct Column_x_positions { - - Line_of_cols cols_; +struct Column_x_positions +{ + Link_array cols_; Array config_; Real force_f_; Real energy_f_; bool satisfies_constraints_b_; - ~Column_x_positions(); Column_x_positions(); - void print() const; }; diff --git a/lily/include/curve.hh b/lily/include/curve.hh deleted file mode 100644 index a3116038b6..0000000000 --- a/lily/include/curve.hh +++ /dev/null @@ -1,38 +0,0 @@ -/* - curve.hh -- declare point and curve - - (c) 1998--1999 Jan Nieuwenhuizen -*/ - -#ifndef CURVE_HH -#define CURVE_HH - -#ifndef STANDALONE -#include "lily-proto.hh" -#endif - -#include "real.hh" - -#include "offset.hh" -#include "array.hh" - -class Curve : public Array -{ -public: - void flipy (); - int largest_disturbing (); - void rotate (Real phi); - void translate (Offset o); - - void operator = (Array const & src) - { - Array::operator =(src); - } - void operator = (Curve const & src) - { - Array::operator =((Array)src); - } -}; - -#endif // CURVE_HH - diff --git a/lily/include/dimension-cache.hh b/lily/include/dimension-cache.hh index 0a61bc2d74..7db6f94a56 100644 --- a/lily/include/dimension-cache.hh +++ b/lily/include/dimension-cache.hh @@ -55,9 +55,6 @@ public: Score_element *element_l () const { return elt_l_; } - void invalidate (); - void invalidate_dependencies (); - Dimension_cache(Dimension_cache const&); Dimension_cache (); @@ -74,9 +71,6 @@ public: void set_empty (bool); void translate (Real); - // junkme. - void set_offset (Real); - bool valid_b () const { return valid_b_; } bool empty_b() const; Interval get_dim () const; diff --git a/lily/include/font-metric.hh b/lily/include/font-metric.hh index 03152c7be8..a26c2e565c 100644 --- a/lily/include/font-metric.hh +++ b/lily/include/font-metric.hh @@ -12,6 +12,7 @@ #include "box.hh" #include "lily-guile.hh" +#include "smobs.hh" struct Character_metric { @@ -21,11 +22,16 @@ struct Character_metric struct Font_metric { + Font_metric (); String name_str_; virtual SCM description () const; virtual Character_metric const *get_char (int ascii, bool warn) const; virtual ~Font_metric (); virtual Box text_dimension (String) const; + + DECLARE_SMOBS; +private: + Font_metric (Font_metric const&); // no copy. }; diff --git a/lily/include/global-translator.hh b/lily/include/global-translator.hh index fbb8f8d37e..674b2af139 100644 --- a/lily/include/global-translator.hh +++ b/lily/include/global-translator.hh @@ -15,9 +15,6 @@ #include "pqueue.hh" -class Iteration_interface_translator : public virtual Translator_group { -}; - class Global_translator : public virtual Translator_group{ PQueue extra_mom_pq_; public: diff --git a/lily/include/item.hh b/lily/include/item.hh index 1c6135d999..b9e2fd8130 100644 --- a/lily/include/item.hh +++ b/lily/include/item.hh @@ -65,8 +65,6 @@ public: Item (Item const &); protected: virtual void do_breakable_col_processing(); - virtual void handle_prebroken_dependencies(); - //virtual void handle_prebroken_dependents (); void copy_breakable_items(); }; diff --git a/lily/include/keyword.hh b/lily/include/keyword.hh index eec7c6f86e..74bcc33c48 100644 --- a/lily/include/keyword.hh +++ b/lily/include/keyword.hh @@ -10,16 +10,16 @@ /* for the keyword table */ struct Keyword_ent { - char const *name; - int tokcode; + char const *name; + int tokcode; }; struct Keyword_table { - Keyword_ent *table; - int maxkey; - Keyword_table (Keyword_ent *); - int lookup (char const *s) const; + Keyword_ent *table; + int maxkey; + Keyword_table (Keyword_ent *); + int lookup (char const *s) const; }; diff --git a/lily/include/lily-proto.hh b/lily/include/lily-proto.hh index fae4e4d398..794c6e7087 100644 --- a/lily/include/lily-proto.hh +++ b/lily/include/lily-proto.hh @@ -168,6 +168,7 @@ struct Note_req; struct Notename_table; struct Offset; struct Paper_column; +struct Polynomial; struct Paper_def; struct Paper_outputter; struct Paper_score; diff --git a/lily/include/lookup.hh b/lily/include/lookup.hh index f49115097c..2e9399958e 100644 --- a/lily/include/lookup.hh +++ b/lily/include/lookup.hh @@ -34,7 +34,6 @@ public: Molecule ledger_line (Interval) const; Molecule fill (Box b) const; Molecule filledbox (Box b) const; - Molecule hairpin (Real width, Real height, Real thick, bool decresc, bool continued) const; Molecule tuplet_bracket (Real dy, Real dx, Real gap, Real thick,Real height, Direction dir) const; Molecule accordion (SCM arg, Real interline_f) const; Molecule slur (Array controls, Real thick) const; diff --git a/lily/include/misc.hh b/lily/include/misc.hh index d45eabe840..917c66a6b6 100644 --- a/lily/include/misc.hh +++ b/lily/include/misc.hh @@ -10,31 +10,17 @@ double log_2(double x) ; int intlog2(int d); -#if 0 - // defined in real.hh inline int -abs (int i){ - return (i < 0)?-i:i; +sign (int i) +{ + if (i<0) + return -1; + else if (i) + return 1; + else return 0; } -#endif - -inline int -sign (int i) { - if (i<0) return -1; - else if (i) return 1; - else return 0; -} - -#ifndef STANDALONE -#include "lily-proto.hh" -Interval itemlist_width (const Link_array &its); -#endif -void set_frobnify (void*, size_t); -int get_lower_bound (Array const& positions, Real x); -Slice get_bounds_slice (Array const& positions, Real x); -Interval get_bounds_iv (Array const& positions, Real x); -Interval quantise_iv (Array const& positions, Real period, Real x); +Interval quantise_iv (Array positions, Real x); #endif diff --git a/lily/include/note-head-side.hh b/lily/include/note-head-side.hh index 1c0eed80db..b30271855f 100644 --- a/lily/include/note-head-side.hh +++ b/lily/include/note-head-side.hh @@ -15,8 +15,6 @@ /** be next to noteheads. - - UGH. another reduplication of Staff_side */ class Note_head_side: public virtual Item, public virtual Directional_element { diff --git a/lily/include/notename-table.hh b/lily/include/notename-table.hh index d53d374365..2bbb8e175a 100644 --- a/lily/include/notename-table.hh +++ b/lily/include/notename-table.hh @@ -10,15 +10,19 @@ #ifndef NOTENAME_TABLE_HH #define NOTENAME_TABLE_HH -#include "pointer.hh" #include "string.hh" #include "lily-proto.hh" -#include "dictionary.hh" -#include "musical-pitch.hh" -class Notename_table : public Dictionary{ +class Notename_table { + Dictionary *pitch_dict_; public: + Notename_table (); + ~Notename_table (); + Notename_table (Notename_table const&); + Musical_pitch get_pitch(String s) const; + void add_note_name (String, Musical_pitch const *p); String get_name (Musical_pitch) const; + bool elem_b (String )const; }; #endif // NOTENAME_TABLE_HH diff --git a/lily/include/scope.hh b/lily/include/scope.hh index 29ba4a0a4e..3699953bbb 100644 --- a/lily/include/scope.hh +++ b/lily/include/scope.hh @@ -10,13 +10,12 @@ #ifndef SCOPE_HH #define SCOPE_HH -#include "dictionary.hh" #include "lily-proto.hh" #include "lily-guile.hh" -#include "dictionary-iter.hh" -#include "protected-scm.hh" -class Scope : private Hash_table { +class Protected_scm; +class Scope { + Hash_table *id_dict_; public: void print () const; bool elem_b (String ) const; @@ -30,10 +29,14 @@ public: friend class Scope_iter; }; -class Scope_iter : public Hash_table_iter { +class Scope_iter { + Hash_table_iter * iter_; public: + void operator ++(int); + bool ok ()const; Scope_iter(Scope const&); String key () const; + Identifier* val () const; SCM scm_key () const; }; diff --git a/lily/include/score-element.hh b/lily/include/score-element.hh index ba75990681..a223d5657d 100644 --- a/lily/include/score-element.hh +++ b/lily/include/score-element.hh @@ -35,6 +35,11 @@ Boolean (true iff defined) */ class Score_element { + /** + The lookup, determined by the font size. Cache this value. + */ + Lookup * lookup_l_; +public: /** properties specific for this element. Destructor will not call scm_unprotect, so as to allow more flexible GC arrangements. The @@ -43,11 +48,7 @@ class Score_element { */ SCM element_property_alist_; - /** - The lookup, determined by the font size. Cache this value. - */ - Lookup * lookup_l_; -public: + Score_element *original_l_; /** @@ -159,7 +160,6 @@ public: */ void set_empty (Axis a); bool empty_b (Axis a) const; - void invalidate_cache (Axis); Interval extent (Axis) const; /** diff --git a/lily/include/spanner.hh b/lily/include/spanner.hh index 6ef182fe13..ec711110e2 100644 --- a/lily/include/spanner.hh +++ b/lily/include/spanner.hh @@ -53,15 +53,8 @@ public: protected: void set_my_columns (); VIRTUAL_COPY_CONS(Score_element); - - /** - this is virtual; for instance, Line_of_score overrides it. - */ - virtual void break_into_pieces (); Real get_broken_left_end_align () const; - friend Axis_group_spanner; // UGH - virtual void do_space_processing (); virtual void do_break_processing (); Real spanner_length () const; diff --git a/lily/include/translator-group.hh b/lily/include/translator-group.hh index e1d91d1aea..0846cc9f6d 100644 --- a/lily/include/translator-group.hh +++ b/lily/include/translator-group.hh @@ -35,6 +35,7 @@ class Translator_group : public virtual Translator { int iterator_count_; friend class Interpretation_context_handle; +protected: Cons_list trans_p_list_; public: @@ -54,11 +55,6 @@ public: Translator_group(); void add_translator (Translator *trans_p); - Link_array nongroup_l_arr () const; - Link_array group_l_arr () const; - - virtual Global_translator *global_l() { return 0; } - /// Score_register = 0, Staff_registers = 1, etc) Translator_group* ancestor_l (int l=1); int depth_i() const; @@ -68,8 +64,6 @@ public: Translator *remove_translator_p (Translator*trans_l); void check_removal (); - - Translator *get_simple_translator (String) const; Translator_group *find_existing_translator_l (String n, String id); Translator_group *find_create_translator_l (String n, String id); diff --git a/lily/item.cc b/lily/item.cc index fc082e4166..5417dae3d4 100644 --- a/lily/item.cc +++ b/lily/item.cc @@ -155,12 +155,7 @@ Item::find_broken_piece (Direction d) const } } -void -Item::handle_prebroken_dependencies() -{ - if (original_l_) - Score_element::handle_prebroken_dependencies(); -} + bool Item::broken_original_b () const diff --git a/lily/leastsquares.cc b/lily/leastsquares.cc index a9bb8df655..6856c625b3 100644 --- a/lily/leastsquares.cc +++ b/lily/leastsquares.cc @@ -7,7 +7,7 @@ Least_squares::OK() const assert (input.size() > 1); Real dx = 0.0; for (int i=1; i < input.size(); i++) - dx += abs (input[i-1].x() - input[i].x ()); + dx += abs (input[i-1][X_AXIS] - input[i][X_AXIS]); assert (dx); } @@ -22,12 +22,12 @@ Least_squares::minimise (Real &coef, Real &offset) for (int i=0; i < input.size();i++) { - Real x=input[i].x(); - Real y = input[i].y(); - sx += x; - sy += y; - sqx += sqr (x); - sxy += x*y; + Real x=input[i][X_AXIS]; + Real y = input[i][Y_AXIS]; + sx += x; + sy += y; + sqx += sqr (x); + sxy += x*y; } int N = input.size(); diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index 93e1651cc0..21723f7713 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -184,7 +184,7 @@ SCM index_cell (SCM s, Direction d) { assert (d); - return (d == LEFT) ? SCM_CAR (s) : SCM_CDR (s); + return (d == LEFT) ? gh_car (s) : gh_cdr (s); } SCM diff --git a/lily/local-key-item.cc b/lily/local-key-item.cc index 72c7104e4a..55f17551a7 100644 --- a/lily/local-key-item.cc +++ b/lily/local-key-item.cc @@ -95,8 +95,8 @@ Local_key_item::do_brew_molecule_p() const * note_distance; Molecule m (accidental (p.accidental_i_, - accidental_arr_[i].cautionary_b_, - accidental_arr_[i].natural_b_)); + accidental_arr_[i].cautionary_b_, + accidental_arr_[i].natural_b_)); m.translate_axis (dy, Y_AXIS); octave_mol_p->add_at_edge (X_AXIS, RIGHT, m, 0); diff --git a/lily/lookup.cc b/lily/lookup.cc index 7f98f45965..c3d2213592 100644 --- a/lily/lookup.cc +++ b/lily/lookup.cc @@ -468,24 +468,7 @@ Lookup::staff_brace (Real y, int staff_size) const return m; } -Molecule -Lookup::hairpin (Real width, Real height, Real thick, bool decresc, bool continued) const -{ - Molecule m; - - const char* hairpin = decresc ? "decrescendo" : "crescendo"; - Atom at (gh_list (ly_symbol2scm (hairpin), - gh_double2scm (thick), - gh_double2scm (width), - gh_double2scm (height), - gh_double2scm (continued ? height/2 : 0.0), - SCM_UNDEFINED)); - m.dim_.x () = Interval (0, width); - m.dim_.y () = Interval (-2*height, 2*height); - m.add_atom (&at); - return m; -} Molecule Lookup::tuplet_bracket (Real dy , Real dx, Real thick, Real gap, @@ -579,8 +562,8 @@ Molecule Lookup::accordion (SCM s, Real interline_f) const { Molecule m; - String sym = ly_scm2string(SCM_CAR(s)); - String reg = ly_scm2string(SCM_CAR(SCM_CDR(s))); + String sym = ly_scm2string(gh_car (s)); + String reg = ly_scm2string(gh_car (gh_cdr(s))); if (sym == "Discant") { diff --git a/lily/main.cc b/lily/main.cc index 246e763587..b45226b6e9 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -10,6 +10,7 @@ #include #include #include + #include "lily-guile.hh" #include "lily-version.hh" @@ -178,7 +179,6 @@ notice () "USA.\n"); } - void setup_paths () { @@ -217,12 +217,13 @@ setup_paths () char *suffixes[] = {"ly", "afm", "scm", "tfm", "cmtfm", "ps", 0}; - for (char **s = suffixes; *s; s++){ - if (!prefix_directory.empty_b()) - global_path.add (prefix_directory + to_str ('/') + String (*s)); - else - global_path.add (String (DIR_DATADIR) + to_str ('/') + String(*s)); - } + for (char **s = suffixes; *s; s++) + { + if (!prefix_directory.empty_b()) + global_path.add (prefix_directory + to_str ('/') + String (*s)); + else + global_path.add (String (DIR_DATADIR) + to_str ('/') + String(*s)); + } } @@ -233,7 +234,7 @@ main_prog (int, char**) need to do this first. Engravers use lily.scm contents. */ init_lily_guile (); - read_lily_scm_file ( "lily.scm"); + read_lily_scm_file ("lily.scm"); cout << endl; call_constructors (); diff --git a/lily/misc.cc b/lily/misc.cc index ab6cceb5f5..d9c56c4a8d 100644 --- a/lily/misc.cc +++ b/lily/misc.cc @@ -8,15 +8,11 @@ */ #include - #include "misc.hh" -#ifndef STANDALONE -#include "item.hh" -#endif - int -intlog2(int d) { +intlog2(int d) +{ int i=0; while (!(d&1)) { @@ -28,76 +24,41 @@ intlog2(int d) { } double -log_2(double x) { - return log (x) /log (2.0); -} - - -/* - TODO - group in some Array_* - make more generic / templatise - */ -int -get_lower_bound (Array const& positions, Real x) +log_2(double x) { - if (x < positions[0]) - return 0; - for (int i = 1; i < positions.size (); i++) - if (x < positions[i]) - return i - 1; - return positions.size () - 1; + return log (x) /log (2.0); } -Slice -get_bounds_slice (Array const& positions, Real x) -{ - int l = get_lower_bound (positions, x); - int u = positions.size () - 1 const& positions, Real x) +static int +comp (Real const &a, Real const &b) { - Slice slice = get_bounds_slice (positions, x); - return Interval (positions[slice[SMALLER]], positions[slice[BIGGER]]); + return sign (a-b); } -// silly name Interval -quantise_iv (Array const& positions, Real period, Real x) +quantise_iv (Array positions, Real x) { - /* - ugh - assume that - * positions are sorted, - * positions are nonnegative - * period starts at zero - */ + positions.sort (comp); + Real period = positions.top () - positions[0]; + + int n = int ((x - positions[0]) / period); + Real frac = (x - positions[0] ) - n * period; - int n = (int)(x / period); - Real frac = (x / period - n) * period; - if (frac < 0) + while (frac < 0) { frac += period; - n--; + n --; } - - Slice slice = get_bounds_slice (positions, frac); - Interval iv(positions[slice[SMALLER]], positions[slice[BIGGER]]); - - if (slice[SMALLER] == slice[BIGGER]) + + Real px = frac + positions[0]; + assert ( positions[0] <= px && px <= positions.top ()); + int i=0; + for (; i < positions.size () - 1; i++) { - if (slice[SMALLER] == 0) - iv[SMALLER] = - period + positions.top (); - else - iv[BIGGER] = period + positions[0]; + if (positions[i] <= px && px <= positions[i+1]) + break; } - iv += period * n; - - return iv; + return Interval (positions[i] , positions[i+1]) + period * n; } diff --git a/lily/molecule.cc b/lily/molecule.cc index 3f14811955..710ee8b397 100644 --- a/lily/molecule.cc +++ b/lily/molecule.cc @@ -16,12 +16,12 @@ #ifdef ATOM_SMOB #define MOL_EOL SCM_EOL -#define NEXT_CELL(a) SCM_CDR(a) +#define NEXT_CELL(a) gh_cdr(a) #define CELLTYPE SCM #define UNBOX_ATOM(a) Atom::atom_l (a) #define BOX_ATOM(a) a->make_smob () #define NEWCELL(a,b) gh_cons (a,b) -#define UNBOX_PTR(a) SCM_CAR(a) +#define UNBOX_PTR(a) gh_car (a) #else #define MOL_EOL 0 #define NEXT_CELL(a) ptr->next_ diff --git a/lily/moment.cc b/lily/moment.cc index 94d65eab45..0e11977686 100644 --- a/lily/moment.cc +++ b/lily/moment.cc @@ -27,7 +27,7 @@ Moment::~Moment() int Moment::print_smob (SCM s, SCM port, scm_print_state *) { - Moment *r = (Moment *) SCM_CDR (s); + Moment *r = (Moment *) gh_cdr (s); scm_puts ("#str()); diff --git a/lily/my-lily-lexer.cc b/lily/my-lily-lexer.cc index b271010fd7..3147b6e517 100644 --- a/lily/my-lily-lexer.cc +++ b/lily/my-lily-lexer.cc @@ -180,13 +180,13 @@ My_lily_lexer::LexerError (char const *s) Musical_pitch My_lily_lexer::lookup_notename (String s) { - return (*note_tab_p_)[s]; + return note_tab_p_->get_pitch (s); } Musical_pitch My_lily_lexer::lookup_chordmodifier (String s) { - return (*chordmodifier_tab_p_)[s]; + return chordmodifier_tab_p_->get_pitch (s); } bool diff --git a/lily/note-column.cc b/lily/note-column.cc index 7ed9936d14..7b69a7c65e 100644 --- a/lily/note-column.cc +++ b/lily/note-column.cc @@ -116,8 +116,6 @@ Note_column::add_head (Rhythmic_head *h) void Note_column::translate_rests (int dy_i) { - // invalidate_cache (Y_AXIS); - SCM s = get_elt_property ("rests"); for (; gh_pair_p (s); s = gh_cdr (s)) { @@ -219,5 +217,4 @@ Note_column::first_head () const { Stem * st = stem_l (); return st? st->first_head (): 0; - } diff --git a/lily/note-head.cc b/lily/note-head.cc index ae8ec87045..70834c191b 100644 --- a/lily/note-head.cc +++ b/lily/note-head.cc @@ -36,7 +36,6 @@ Note_head::do_pre_processing () if (Dots *d = dots_l ()) { // move into Rhythmic_head? - Staff_symbol_referencer_interface si (d); Staff_symbol_referencer_interface me (this); diff --git a/lily/notename-table.cc b/lily/notename-table.cc index 0d2201fca4..2063f79ee4 100644 --- a/lily/notename-table.cc +++ b/lily/notename-table.cc @@ -7,15 +7,14 @@ */ #include "notename-table.hh" -#include "pointer.tcc" -#include "musical-request.hh" #include "dictionary-iter.hh" +#include "dictionary.hh" +#include "musical-pitch.hh" String Notename_table::get_name (Musical_pitch m) const { - - for (Dictionary_iter ai (*this); ai.ok (); ai++) + for (Dictionary_iter ai (*pitch_dict_); ai.ok (); ai++) { if (ai.val () == m) return ai.key (); @@ -23,3 +22,35 @@ Notename_table::get_name (Musical_pitch m) const return "r"; // rest. } + +void +Notename_table::add_note_name (String s, + Musical_pitch const *p) +{ + pitch_dict_->elem (s) = *p; +} + +Notename_table::Notename_table () +{ + pitch_dict_ = new Dictionary; +} + +Notename_table::~Notename_table() +{ + delete pitch_dict_; +} + +Notename_table::Notename_table (Notename_table const &s) +{ + pitch_dict_ = new Dictionary (*s.pitch_dict_); +} +bool +Notename_table::elem_b (String s)const +{ + return pitch_dict_->elem_b (s); +} +Musical_pitch +Notename_table::get_pitch (String s)const +{ + return (*pitch_dict_)[s]; +} diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index dea59e6cf1..fd53025c2c 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -102,8 +102,8 @@ Paper_outputter::output_molecule (Molecule const*m, Offset o, char const *nm) SCM box_scm = gh_list (ly_symbol2scm ("placebox"), - gh_double2scm (a_off.x ()), - gh_double2scm (a_off.y ()), + gh_double2scm (a_off[X_AXIS]), + gh_double2scm (a_off[Y_AXIS]), SCM(i->func_), SCM_UNDEFINED); diff --git a/lily/paper-score.cc b/lily/paper-score.cc index adb3b1f0ca..b23d002e55 100644 --- a/lily/paper-score.cc +++ b/lily/paper-score.cc @@ -49,8 +49,8 @@ Paper_score::typeset_element (Score_element * elem_p) { elem_p->pscore_l_ = this; - SCM_CDR(element_smob_list_) = gh_cons (elem_p->self_scm_, - SCM_CDR (element_smob_list_)); + gh_set_cdr_x(element_smob_list_, + gh_cons (elem_p->self_scm_, gh_cdr (element_smob_list_))); elem_p->set_elt_property ("full-name", gh_str02scm((char*)elem_p->name())); @@ -75,10 +75,10 @@ Paper_score::print () const DEBUG_OUT << "Paper_score { "; DEBUG_OUT << "\n elements: "; - for (SCM p = SCM_CDR (element_smob_list_); + for (SCM p = gh_cdr (element_smob_list_); p != SCM_EOL; - p = SCM_CDR(p)) - gh_display (SCM_CAR(p)); + p = gh_cdr(p)) + gh_display (gh_car (p)); DEBUG_OUT << "}\n"; #endif } diff --git a/lily/parser.yy b/lily/parser.yy index ea6499510e..0d802fd2ff 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -20,7 +20,6 @@ #include "midi-def.hh" #include "main.hh" #include "file-path.hh" -#include "keyword.hh" #include "debug.hh" #include "dimensions.hh" #include "identifier.hh" @@ -132,7 +131,6 @@ yylex (YYSTYPE *s, void * v_l) %token ALTERNATIVE %token BAR %token BREATHE -%token CADENZA %token CHORDMODIFIERS %token CHORDS %token HYPHEN @@ -328,8 +326,7 @@ notenames_body: $$ = $1-> access_content_Notename_table(true); } | notenames_body STRING '=' explicit_musical_pitch { - (*$$)[ly_scm2string ($2)] = *$4; - + $$->add_note_name (ly_scm2string ($2), $4); delete $4; } ; diff --git a/lily/performer-group-performer.cc b/lily/performer-group-performer.cc index b0278c661d..7496881ad0 100644 --- a/lily/performer-group-performer.cc +++ b/lily/performer-group-performer.cc @@ -25,19 +25,15 @@ Performer_group_performer::announce_element (Audio_element_info info) void Performer_group_performer::do_announces() { - Link_array groups = group_l_arr (); - for (int i=0; i < groups.size(); i++) + for (Cons *p = trans_p_list_.head_; p; p = p->next_) { - Performer_group_performer * group = dynamic_cast (groups[i]); - if (group) - { - group->do_announces(); - } + if (Performer_group_performer *trg = dynamic_cast (p->car_)) + trg->do_announces (); } + Request dummy_req; - Link_array nongroups = nongroup_l_arr (); while (announce_info_arr_.size ()) { for (int j =0; j < announce_info_arr_.size(); j++) @@ -46,24 +42,32 @@ Performer_group_performer::do_announces() if (!info.req_l_) info.req_l_ = &dummy_req; - for (int i=0; i < nongroups.size(); i++) - { // Is this good enough? - Performer * eng = dynamic_cast (nongroups[i]); - // urg, huh? core dump? - //if (eng && eng!= info.origin_trans_l_arr_[0]) - if (eng && info.origin_trans_l_arr_.size () - && eng!= info.origin_trans_l_arr_[0]) - eng->acknowledge_element (info); + + for (Cons *p = trans_p_list_.head_; p; p = p->next_) + { + if (!dynamic_cast (p->car_)) + { + Performer * eng = dynamic_cast (p->car_); + // urg, huh? core dump? + //if (eng && eng!= info.origin_trans_l_arr_[0]) + if (eng && info.origin_trans_l_arr_.size () + && eng!= info.origin_trans_l_arr_[0]) + eng->acknowledge_element (info); + } + } + announce_info_arr_.clear (); + + + for (Cons *p = trans_p_list_.head_; p; p = p->next_) + { + if (!dynamic_cast (p->car_)) + { + Performer * eng = dynamic_cast (p->car_); + if (eng) + eng->process_acknowledged (); + } } } - announce_info_arr_.clear (); - for (int i=0; i < nongroups.size(); i++) - { - Performer * eng = dynamic_cast (nongroups[i]); - if (eng) - eng->process_acknowledged (); - } - } } diff --git a/lily/property-engraver.cc b/lily/property-engraver.cc index 268969759b..0c86a3c703 100644 --- a/lily/property-engraver.cc +++ b/lily/property-engraver.cc @@ -53,19 +53,17 @@ Property_engraver::acknowledge_element (Score_element_info i) void Property_engraver::apply_properties (SCM p, Score_element *e) { - for (; SCM_NIMP (p); p = gh_cdr (p)) + for (; gh_pair_p (p); p = gh_cdr (p)) { SCM entry = gh_car (p); SCM prop_sym = gh_car (entry); SCM type_p = gh_cadr (entry); SCM elt_prop_name = gh_caddr (entry); - /* - urg scm <-> symbol-string - */ - if (e->get_elt_property (ly_scm2string (elt_prop_name)) != SCM_UNDEFINED) + SCM preset = scm_assq(prop_sym, e->element_property_alist_); + if (preset != SCM_BOOL_F) continue; - + SCM val = get_property (prop_sym, 0); if (val != SCM_UNDEFINED && gh_apply (type_p, scm_listify (val, SCM_UNDEFINED)) diff --git a/lily/scm-hash.cc b/lily/scm-hash.cc index 043cb23949..4d417416f1 100644 --- a/lily/scm-hash.cc +++ b/lily/scm-hash.cc @@ -60,7 +60,7 @@ Scheme_hash_table::Scheme_hash_table (Scheme_hash_table const &src) } int -Scheme_hash_table::print_smob (SCM s, SCM p, scm_print_state*ps) +Scheme_hash_table::print_smob (SCM s, SCM p, scm_print_state*) { assert (SMOB_IS_TYPE_B (Scheme_hash_table, s)); Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s); diff --git a/lily/scope.cc b/lily/scope.cc index 5262ea179d..b3e5dc83ab 100644 --- a/lily/scope.cc +++ b/lily/scope.cc @@ -11,10 +11,13 @@ #include "dictionary-iter.hh" #include "debug.hh" #include "identifier.hh" +#include "dictionary.hh" +#include "protected-scm.hh" void Scope::print () const { +#ifndef NPRINT bool init_b = false; // ugh for (Scope_iter ai (*this); ai.ok(); ai++) { @@ -24,6 +27,7 @@ Scope::print () const ai.val()->print (); } } +#endif } Scope::~Scope () @@ -33,14 +37,15 @@ Scope::~Scope () DEBUG_OUT << "deleting: " << ai.key() << '\n'; delete ai.val (); } + delete id_dict_; } Scope::Scope (Scope const&s) - : Hash_table (s) { + id_dict_ = new Hash_table (*s.id_dict_); for (Scope_iter ai (s); ai.ok(); ai++) { - (*this)[ai.scm_key ()] = ai.val ()->clone (); + id_dict_->elem (ai.scm_key ()) = ai.val ()->clone (); } } @@ -52,49 +57,68 @@ unsigned int ly_pscm_hash (Protected_scm s) Scope::Scope () { - hash_func_ = ly_pscm_hash; + id_dict_ = new Hash_table; + id_dict_->hash_func_ = ly_pscm_hash; } bool Scope::elem_b (String s) const { - return elem_b (ly_symbol2scm (s.ch_C())); + return id_dict_->elem_b (ly_symbol2scm (s.ch_C())); } Identifier *& Scope::elem (String s) { - return elem (ly_symbol2scm (s.ch_C())); + return id_dict_->elem (ly_symbol2scm (s.ch_C())); } Scope_iter::Scope_iter (Scope const &s) - : Hash_table_iter(s) { + iter_ = new Hash_table_iter(*s.id_dict_); } String Scope_iter::key () const { - SCM s= Hash_table_iter::key (); + SCM s= iter_->key (); return ly_symbol2string (s); } bool Scope::elem_b (SCM s) const { - return Hash_table ::elem_b (s); + return id_dict_->elem_b (s); } Identifier* & Scope::elem (SCM s) { - return Hash_table ::elem (s); + return id_dict_->elem (s); } SCM Scope_iter::scm_key () const { - return Hash_table_iter::key (); + return iter_->key (); +} + +bool +Scope_iter::ok () const +{ + return iter_->ok(); +} + +void +Scope_iter::operator ++(int) +{ + (*iter_) ++; +} + +Identifier* +Scope_iter::val ()const +{ + return iter_->val (); } diff --git a/lily/score-element.cc b/lily/score-element.cc index 918550d158..7e0c8e60b1 100644 --- a/lily/score-element.cc +++ b/lily/score-element.cc @@ -121,7 +121,7 @@ Score_element::get_elt_property (String nm) const SCM s = scm_assq(sym, element_property_alist_); if (s != SCM_BOOL_F) - return SCM_CDR (s); + return gh_cdr (s); if (pscore_l_) { @@ -415,37 +415,14 @@ Score_element::handle_broken_smobs (SCM s, SCM criterion) } return s; } -#if 0 -void -Score_element::recurse_into_smobs (SCM s, void (Score_element::*meth_ptr)()) -{ - Score_element * sc = unsmob_element ( s); - if (sc) - { - (sc->*meth_ptr) (); - } - else if (gh_pair_p (s)) - { - recurse_into_smobs (gh_car (s), meth_ptr); - recurse_into_smobs (gh_cdr (s), meth_ptr); - } -} -#endif void Score_element::handle_broken_dependencies() { Line_of_score *line = line_l(); - - SCM rec = get_elt_property ("handle-broken-deps"); - if (gh_boolean_p (rec) && gh_scm2bool (rec)) - return; - - set_elt_property ("handle-broken-deps", SCM_BOOL_T); element_property_alist_ = handle_broken_smobs (element_property_alist_, line ? line->self_scm_ : SCM_UNDEFINED); - if (!line) return; } @@ -496,7 +473,7 @@ Score_element::find_broken_piece (Line_of_score*) const SCM Score_element::mark_smob (SCM ses) { - void * mp = (void*) SCM_CDR(ses); + void * mp = (void*) gh_cdr(ses); Score_element * s = (Score_element*) mp; assert (s->self_scm_ == ses); @@ -507,7 +484,7 @@ Score_element::mark_smob (SCM ses) int Score_element::print_smob (SCM s, SCM port, scm_print_state *) { - Score_element *sc = (Score_element *) SCM_CDR (s); + Score_element *sc = (Score_element *) gh_cdr (s); scm_puts ("#name (), port); @@ -529,7 +506,7 @@ IMPLEMENT_SMOBS(Score_element); SCM Score_element::equal_p (SCM a, SCM b) { - return SCM_CDR(a) == SCM_CDR(b) ? SCM_BOOL_T : SCM_BOOL_F; + return gh_cdr(a) == gh_cdr(b) ? SCM_BOOL_T : SCM_BOOL_F; } void @@ -583,15 +560,6 @@ unsmob_element (SCM s) } -/* - JUNKME - */ -void -Score_element::invalidate_cache (Axis a) -{ - // dim_cache_[a]->invalidate (); -} - Score_element* Score_element::parent_l (Axis a) const { diff --git a/lily/score-engraver.cc b/lily/score-engraver.cc index 83d2c47eef..696acfa404 100644 --- a/lily/score-engraver.cc +++ b/lily/score-engraver.cc @@ -5,11 +5,9 @@ (c) 1997--1999 Han-Wen Nienhuys */ - +#include "debug.hh" #include "dimension-cache.hh" -#include "super-element.hh" #include "line-of-score.hh" -#include "debug.hh" #include "item.hh" #include "score-engraver.hh" #include "paper-score.hh" diff --git a/lily/script-engraver.cc b/lily/script-engraver.cc index bb38f28339..65317776bb 100644 --- a/lily/script-engraver.cc +++ b/lily/script-engraver.cc @@ -55,16 +55,16 @@ Script_engraver::do_process_requests() list = gh_cdr (list); p->set_elt_property ("molecule", - SCM_CAR(list)); - - list = SCM_CDR(list); - bool follow_staff = gh_scm2bool (SCM_CAR(list)); - list = SCM_CDR(list); - int relative_stem_dir = gh_scm2int (SCM_CAR(list)); - list = SCM_CDR(list); - int force_dir =gh_scm2int (SCM_CAR(list)); - list = SCM_CDR(list); - SCM priority = SCM_CAR(list); + gh_car (list)); + + list = gh_cdr(list); + bool follow_staff = gh_scm2bool (gh_car (list)); + list = gh_cdr(list); + int relative_stem_dir = gh_scm2int (gh_car (list)); + list = gh_cdr(list); + int force_dir =gh_scm2int (gh_car (list)); + list = gh_cdr(list); + SCM priority = gh_car (list); if (relative_stem_dir) diff --git a/lily/script.cc b/lily/script.cc index cc5db9d748..5fb7c6767d 100644 --- a/lily/script.cc +++ b/lily/script.cc @@ -21,7 +21,7 @@ Script::get_molecule(Direction d) const SCM s = get_elt_property ("molecule"); assert (s != SCM_UNDEFINED); - SCM key = SCM_CAR (s); + SCM key = gh_car (s); if (key == ly_symbol2scm ("feta")) { return lookup_l ()->afm_find ("scripts-" + diff --git a/lily/slur.cc b/lily/slur.cc index 0a351dc2c2..ce3429f892 100644 --- a/lily/slur.cc +++ b/lily/slur.cc @@ -167,7 +167,9 @@ Slur::do_post_processing () Direction d = LEFT; do { - dx_f_drul_[d] = dy_f_drul_[d] = 0; + dx_f_drul_[d] = 0; + dy_f_drul_[d] = 0; + if ((note_column_drul[d] == spanned_drul_[d]) && note_column_drul[d]->first_head () && (note_column_drul[d]->stem_l ())) @@ -319,9 +321,8 @@ Slur::do_post_processing () */ for (int i = 0; i < 3; i++) { - Drul_array curve_xy_drul = curve_extent_drul (); - Real height_f = curve_xy_drul[Y].length (); - Real width_f = curve_xy_drul[X].length (); + Real height_f = curve_extent (Y_AXIS).length (); + Real width_f = curve_extent (X_AXIS).length (); dy_f = dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]; if (!fix_broken_b) diff --git a/lily/spacing-spanner.cc b/lily/spacing-spanner.cc index ab8d82ae4a..b7a44615b7 100644 --- a/lily/spacing-spanner.cc +++ b/lily/spacing-spanner.cc @@ -148,7 +148,7 @@ Spacing_spanner::do_measure (Link_array cols) const if (next_stretch_hint != SCM_UNDEFINED) // see regtest spacing-tight - stretch_dist += - gh_scm2double (SCM_CAR (next_stretch_hint)); + stretch_dist += - gh_scm2double (gh_car (next_stretch_hint)); else stretch_dist += right_dist; @@ -248,8 +248,8 @@ Spacing_spanner::stem_dir_correction (Score_column*l, Score_column*r) const if (scm_ilength (dl) != 1 && scm_ilength (dr) != 1) return 0.; - dl = SCM_CAR(dl); - dr = SCM_CAR(dr); + dl = gh_car (dl); + dr = gh_car (dr); assert (gh_number_p (dl) && gh_number_p(dr)); int d1 = gh_scm2int (dl); diff --git a/lily/spanner.cc b/lily/spanner.cc index 5fb0da4792..b60fe1cf37 100644 --- a/lily/spanner.cc +++ b/lily/spanner.cc @@ -18,8 +18,10 @@ #include "break-align-item.hh" void -Spanner::break_into_pieces () +Spanner::do_break_processing() { + //break_into_pieces + if (line_l () || broken_b ()) return; @@ -99,13 +101,6 @@ Spanner::set_bounds(Direction d, Item*i) } - -void -Spanner::do_break_processing() -{ - break_into_pieces (); -} - Spanner::Spanner () { spanned_drul_[LEFT]=0; @@ -126,8 +121,8 @@ Spanner::spanner_length() const Real r = spanned_drul_[RIGHT]->relative_coordinate (0, X_AXIS); if (r< l) - warning (_ ("spanner with negative length")); - + programming_error ("spanner with negative length"); + return r-l; } @@ -145,9 +140,6 @@ Spanner::line_l() const Score_element* Spanner::find_broken_piece (Line_of_score*l) const { - Spanner* me = (Spanner*) this; - me->break_into_pieces (); - int idx = binsearch_link_array (broken_into_l_arr_, (Spanner*)l, Spanner::compare); if (idx < 0) diff --git a/lily/time-description.cc b/lily/time-description.cc deleted file mode 100644 index 2874444da4..0000000000 --- a/lily/time-description.cc +++ /dev/null @@ -1,11 +0,0 @@ -/* - timing-translator.cc -- implement Timing_translator - - source file of the GNU LilyPond music typesetter - - (c) 1997--1999 Han-Wen Nienhuys -*/ - -#include "timing-translator.hh" -#include "translator-group.hh" -#include "debug.hh" diff --git a/lily/translator-group.cc b/lily/translator-group.cc index e20daeb0aa..fb5d6b4499 100644 --- a/lily/translator-group.cc +++ b/lily/translator-group.cc @@ -40,13 +40,16 @@ Translator_group::Translator_group() void Translator_group::check_removal() { - Link_array groups (group_l_arr ()); - - for (int i =0; i < groups.size(); i++) + Cons *next =0; + for (Cons *p = trans_p_list_.head_; p; p = next) { - groups[i]->check_removal(); - if (groups[i]->removable_b()) - terminate_translator (groups[i]); + next = p->next_; + if (Translator_group *trg = dynamic_cast (p->car_)) + { + trg->check_removal (); + if (trg->removable_b()) + terminate_translator (trg); + } } } @@ -126,11 +129,12 @@ Translator_group::find_existing_translator_l (String n, String id) if (is_alias_b (n) && (id_str_ == id || id.empty_b ())) return this; - Link_array groups (group_l_arr ()); + Translator_group* r = 0; - for (int i =0; !r && i < groups.size(); i++) + for (Cons *p = trans_p_list_.head_; p; p = p->next_) { - r = groups[i]->find_existing_translator_l (n,id); + if (Translator_group *trg = dynamic_cast (p->car_)) + r = trg->find_existing_translator_l (n, id); } return r; @@ -215,10 +219,13 @@ Translator_group::try_music_on_nongroup_children (Music *m) { bool hebbes_b =false; - Link_array nongroups (nongroup_l_arr ()); - - for (int i =0; !hebbes_b && i < nongroups.size() ; i++) - hebbes_b =nongroups[i]->try_music (m); + for (Cons *p = trans_p_list_.head_; !hebbes_b && p; p = p->next_) + { + if (!dynamic_cast (p->car_)) + { + hebbes_b = p->car_->try_music (m); + } + } return hebbes_b; } @@ -247,32 +254,9 @@ Translator_group::ancestor_l (int level) return daddy_trans_l_->ancestor_l (level-1); } -Link_array -Translator_group::group_l_arr () const -{ - Link_array groups; - for (Cons *p = trans_p_list_.head_; p; p = p->next_) - { - if (dynamic_cast (p->car_)) - groups.push (dynamic_cast (p->car_)); - } - return groups; -} -Link_array -Translator_group::nongroup_l_arr () const -{ - Link_array groups; - for (Cons *p = trans_p_list_.head_; p; p = p->next_) - { - if (!dynamic_cast (p->car_)) - groups.push (p->car_); - } - return groups; -} -/** - End translator: call "destructor", remove from hierarchy, and delete - */ + + void Translator_group::terminate_translator (Translator*r_l) @@ -310,11 +294,10 @@ Translator_group::remove_translator_p (Translator*trans_l) Translator* Translator_group::get_simple_translator (String type) const { - Link_array nongroups (nongroup_l_arr ()); - for (int i=0; i < nongroups.size(); i++) + for (Cons *p = trans_p_list_.head_; p; p = p->next_) { - if (classname (nongroups[i]) == type) - return nongroups[i]; + if (classname (p->car_) == type) + return p->car_; } if (daddy_trans_l_) return daddy_trans_l_->get_simple_translator (type); diff --git a/ly/property.ly b/ly/property.ly index 9e755f6a11..4a28d27368 100644 --- a/ly/property.ly +++ b/ly/property.ly @@ -52,28 +52,28 @@ voicefour = { infinity=10000 beamslopeproportional = - \property Score.beamslopedamping = 0 + \property Score.beamSlopedamping = 0 beamslopedamped = - \property Score.beamslopedamping = 1 + \property Score.beamSlopedamping = 1 beamslopezero = - \property Score.beamslopedamping = \infinity + \property Score.beamSlopedamping = \infinity % this sucks, you'd want to pass an array, at least % (or embedded code: you still can't dictate the slope / stemlength) beamposfree = - \property Score.beamquantisation = 0 + \property Score.beamQuantisation = 0 beamposnormal = - \property Score.beamquantisation = 1 + \property Score.beamQuantisation = 1 beampostraditional = - \property Score.beamquantisation = 2 + \property Score.beamQuantisation = 2 slurnormal = diff --git a/make/out/lilypond.lsm b/make/out/lilypond.lsm index 08483c3b3b..a590a6ba78 100644 --- a/make/out/lilypond.lsm +++ b/make/out/lilypond.lsm @@ -1,15 +1,15 @@ Begin3 Title: LilyPond -Version: 1.3.12 -Entered-date: 16DEC99 +Version: 1.3.13 +Entered-date: 18DEC99 Description: Keywords: music notation typesetting midi fonts engraving Author: hanwen@cs.uu.nl (Han-Wen Nienhuys) janneke@gnu.org (Jan Nieuwenhuizen) Maintained-by: hanwen@stack.nl (Han-Wen Nienhuys) Primary-site: sunsite.unc.edu /pub/Linux/apps/sound/convert - 1000k lilypond-1.3.12.tar.gz + 1000k lilypond-1.3.13.tar.gz Original-site: ftp.cs.uu.nl /pub/GNU/LilyPond/development/ - 1000k lilypond-1.3.12.tar.gz + 1000k lilypond-1.3.13.tar.gz Copying-policy: GPL End diff --git a/make/out/lilypond.spec b/make/out/lilypond.spec index 6215ec84ad..e297d6b37a 100644 --- a/make/out/lilypond.spec +++ b/make/out/lilypond.spec @@ -1,9 +1,9 @@ Name: lilypond -Version: 1.3.12 +Version: 1.3.13 Release: 1 Copyright: GPL Group: Applications/Publishing -Source0: ftp.cs.uu.nl:/pub/GNU/LilyPond/development/lilypond-1.3.12.tar.gz +Source0: ftp.cs.uu.nl:/pub/GNU/LilyPond/development/lilypond-1.3.13.tar.gz Summary: A program for printing sheet music. URL: http://www.cs.uu.nl/~hanwen/lilypond # get Packager from (undocumented?) ~/.rpmmacros! diff --git a/po/nl.po b/po/nl.po index c9e0fee900..ad93e68e2f 100644 --- a/po/nl.po +++ b/po/nl.po @@ -816,7 +816,7 @@ msgstr "Negatieve afstand, zet op 10 mm" #: stem-engraver.cc:80 #, c-format msgid "Adding note head to incompatible stem (type = %d)" -msgstr "Voeg noot bolletje toe aan onverenigbare stok (type = %s)" +msgstr "Voeg noot bolletje toe aan onverenigbare stok (type = %d)" #: stem.cc:26 msgid "stem direction set already!" -- 2.39.2