From: Jan Nieuwenhuizen Date: Tue, 21 Dec 1999 10:44:57 +0000 (+0100) Subject: patch::: 1.3.15.jcn2 X-Git-Tag: release/1.3.16~3 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=3edf5d0b9e3346530cece55fdbcf905b10c8b693;p=lilypond.git patch::: 1.3.15.jcn2 pl 15.jcn2 - beam quanting using scm lists --- diff --git a/CHANGES b/CHANGES index 87bebcbd4b..cfc164b2bb 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +pl 15.jcn2 + - beam quanting using scm lists + pl 14.hwn1jcn1 - chord-name uses scm members - bfs: knee with different mults, interstaff knee, auto-knee diff --git a/VERSION b/VERSION index 538ce3a83b..8644a073a4 100644 --- a/VERSION +++ b/VERSION @@ -2,7 +2,7 @@ PACKAGE_NAME=LilyPond MAJOR_VERSION=1 MINOR_VERSION=3 PATCH_LEVEL=15 -MY_PATCH_LEVEL=jcn1 +MY_PATCH_LEVEL=jcn2 # use the above to send patches: MY_PATCH_LEVEL is always empty for a # released version. diff --git a/input/test/beam-quanting.ly b/input/test/beam-quanting.ly new file mode 100644 index 0000000000..f0f9cc1ef0 --- /dev/null +++ b/input/test/beam-quanting.ly @@ -0,0 +1,17 @@ +%{ +Have some fun beam quanting +%} + +% no y quantising +#(define (beam-vertical-position-quants m dy) '()) + +% rediculous dy quanting +#(define beam-height-quants '(0 4)) + +\score { + \notes\relative c'{ + c8 c c c + c8 e g a + c,8 f b e + } +} diff --git a/lily/beam.cc b/lily/beam.cc index 8620f8747c..7305ff69c6 100644 --- a/lily/beam.cc +++ b/lily/beam.cc @@ -27,6 +27,7 @@ #include "group-interface.hh" #include "staff-symbol-referencer.hh" #include "cross-staff.hh" +#include "lily-guile.icc" Beam::Beam () { @@ -249,10 +250,10 @@ Beam::set_stem_shorten () return; int multiplicity = get_multiplicity (); - SCM shorten = scm_eval (scm_listify ( - ly_symbol2scm ("beamed-stem-shorten"), - gh_int2scm (multiplicity), - SCM_UNDEFINED)); + SCM shorten = scm_eval (gh_list ( + ly_symbol2scm ("beamed-stem-shorten"), + gh_int2scm (multiplicity), + SCM_UNDEFINED)); Real shorten_f = gh_scm2double (shorten) * Staff_symbol_referencer_interface (this).staff_space (); @@ -482,6 +483,10 @@ Beam::check_stem_length_f (Real y, Real dy) const return lengthen * get_direction (); } +/* + Hmm. At this time, beam position and slope are determined. Maybe, + stem directions and length should set to relative to the chord's + position of the beam. */ void Beam::set_stem_length (Real y, Real dy) { @@ -502,39 +507,30 @@ Beam::set_stem_length (Real y, Real dy) /* [Ross] (simplification of) - Try to set dy complying with: + Set dy complying with: - zero - thick / 2 + staffline_f / 2 - thick + staffline_f + n * staff_space - - TODO: get allowed-positions as scm list (aarg: from paper block) */ Real Beam::quantise_dy_f (Real dy) const { - SCM s = get_elt_property ("slope-quantisation"); - - if (s == ly_symbol2scm ("none")) + SCM quants = ly_eval_str ("beam-height-quants"); + + Array a; + scm_to_array (quants, &a); + if (a.size () <= 1) return dy; Staff_symbol_referencer_interface st (this); Real staff_space = st.staff_space (); - Real staffline_f = paper_l ()->get_var ("stafflinethickness"); - Real thick = gh_scm2double (get_elt_property ("beam-thickness"));; - - Array allowed_fraction (3); - allowed_fraction[0] = 0; - allowed_fraction[1] = (thick / 2 + staffline_f / 2); - allowed_fraction[2] = (thick + staffline_f); - - allowed_fraction.push (staff_space); - Interval iv = quantise_iv (allowed_fraction, abs (dy)); + Interval iv = quantise_iv (a, abs (dy)/staff_space) * staff_space; Real q = (abs (dy) - iv[SMALLER] <= iv[BIGGER] - abs (dy)) ? iv[SMALLER] : iv[BIGGER]; - + return q * sign (dy); } @@ -542,75 +538,28 @@ Beam::quantise_dy_f (Real dy) const Prevent interference from stafflines and beams. See Documentation/tex/fonts.doc - TODO: get allowed-positions as scm list (aarg: from paper block) + We only need to quantise the (left) y-position of the beam, + since dy is quantised too. + if extend_b then stems must *not* get shorter */ Real Beam::quantise_y_f (Real y, Real dy, int quant_dir) { - /* - We only need to quantise the (left) y-position of the beam, - since dy is quantised too. - if extend_b then stems must *not* get shorter - */ - SCM s = get_elt_property ("slope-quantisation"); - if (s == ly_symbol2scm ("none")) - return y; - - /* - ---------------------------------------------------------- - ######## - ######## - ######## - --------------########------------------------------------ - ######## - - hang straddle sit inter hang - */ - + int multiplicity = get_multiplicity (); Staff_symbol_referencer_interface st (this); Real staff_space = st.staff_space (); - Real staffline_f = paper_l ()->get_var ("stafflinethickness"); - Real thick = gh_scm2double (get_elt_property ("beam-thickness"));; - - Real straddle = 0; - Real sit = thick / 2 - staffline_f / 2; - Real hang = staff_space - thick / 2 + staffline_f / 2; - - /* - Put all allowed positions into an array. - Whether a position is allowed or not depends on - strictness of quantisation, multiplicity and direction. - - For simplicity, we'll assume dir = UP and correct if - dir = DOWN afterwards. - */ - - int multiplicity = get_multiplicity (); - - - Array allowed_position; - if (s == ly_symbol2scm ("normal")) - { - if ((multiplicity <= 2) || (abs (dy) >= staffline_f / 2)) - allowed_position.push (straddle); - if ((multiplicity <= 1) || (abs (dy) >= staffline_f / 2)) - allowed_position.push (sit); - allowed_position.push (hang); - } - else if (s == ly_symbol2scm ("traditional")) - { - // TODO: check and fix TRADITIONAL - if ((multiplicity <= 2) || (abs (dy) >= staffline_f / 2)) - allowed_position.push (straddle); - if ((multiplicity <= 1) && (dy <= staffline_f / 2)) - allowed_position.push (sit); - if (dy >= -staffline_f / 2) - allowed_position.push (hang); - } + SCM quants = scm_eval (gh_list ( + ly_symbol2scm ("beam-vertical-position-quants"), + gh_int2scm (multiplicity), + gh_double2scm (dy/staff_space), + SCM_UNDEFINED)); + Array a; + scm_to_array (quants, &a); + if (a.size () <= 1) + return y; - allowed_position.push (staff_space); Real up_y = get_direction () * y; - Interval iv = quantise_iv (allowed_position, up_y); + Interval iv = quantise_iv (a, up_y/staff_space) * staff_space; Real q = up_y - iv[SMALLER] <= iv[BIGGER] - up_y ? iv[SMALLER] : iv[BIGGER]; diff --git a/lily/chord-name.cc b/lily/chord-name.cc index a202812d32..4b6eff78a9 100644 --- a/lily/chord-name.cc +++ b/lily/chord-name.cc @@ -13,40 +13,7 @@ #include "molecule.hh" #include "paper-def.hh" #include "lookup.hh" - -SCM -to_scm (Musical_pitch p) -{ - return gh_list (gh_int2scm (p.notename_i_), gh_int2scm (p.accidental_i_), gh_int2scm (p.octave_i_), SCM_UNDEFINED); -} - -Musical_pitch -from_scm (SCM s) -{ - return Musical_pitch (gh_scm2int (gh_car (s)), - gh_scm2int (gh_cadr (s)), - gh_scm2int (gh_caddr (s))); -} - -templateSCM -array_to_scm (Array arr) -{ - SCM list = SCM_EOL; - for (int i = arr.size (); i--;) - list = gh_cons (to_scm (arr[i]), list); - return list; -} - -/* - Silly templates - Array scm_to_array (SCM s) - */ -templatevoid -scm_to_array (SCM s, Array* arr) -{ - for (; gh_pair_p (s); s= gh_cdr (s)) - arr->push (from_scm (gh_car (s))); -} +#include "lily-guile.icc" /* ugh, move to chord-name-engraver @@ -64,6 +31,10 @@ Chord_name::set (Chord const& c) set_elt_property ("bass", to_scm (c.bass_pitch_)); } +/* + junkme + */ + SCM notename2scm (Musical_pitch p) { @@ -307,7 +278,9 @@ Chord_name::do_brew_molecule_p () const if (s != SCM_UNDEFINED) { name.inversion_mol = lookup_l ()->text ("", "/", paper_l ()); - Molecule mol = pitch2molecule (from_scm (s)); + Musical_pitch p; + scm_to (s, &p); + Molecule mol = pitch2molecule (p); name.inversion_mol.add_at_edge (X_AXIS, RIGHT, mol, 0); } @@ -315,7 +288,9 @@ Chord_name::do_brew_molecule_p () const if (s != SCM_UNDEFINED) { name.bass_mol = lookup_l ()->text ("", "/", paper_l ()); - Molecule mol = pitch2molecule (from_scm (s)); + Musical_pitch p; + scm_to (s, &p); + Molecule mol = pitch2molecule (p); name.bass_mol.add_at_edge (X_AXIS, RIGHT, mol, 0); } diff --git a/lily/include/lily-guile.hh b/lily/include/lily-guile.hh index 84af73262b..f66caa760a 100644 --- a/lily/include/lily-guile.hh +++ b/lily/include/lily-guile.hh @@ -46,6 +46,16 @@ unsigned int ly_scm_hash (SCM s); SCM index_cell (SCM cellp, Direction d); SCM index_set_cell (SCM cellp, Direction d, SCM val); +templateSCM array_to_scm (Array arr); +templatevoid scm_to_array (SCM s, Array* arr); + +//URG how templates suck! +SCM to_scm (int i); +void scm_to (SCM s, int* i); + +SCM to_scm (Real r); +void scm_to (SCM s, Real* r); + /* snarfing. */ @@ -61,6 +71,4 @@ public:\ } _ ## name ## _scm_initter; \ /* end define */ - - #endif // LILY_GUILE_HH diff --git a/lily/include/lily-guile.icc b/lily/include/lily-guile.icc new file mode 100644 index 0000000000..1152117f20 --- /dev/null +++ b/lily/include/lily-guile.icc @@ -0,0 +1,40 @@ +/* + lily-guile.icc -- implement guile templates + + source file of the GNU LilyPond music typesetter + + (c) 1999 Jan Nieuwenhuizen +*/ + +#ifndef LILY_GUILE_ICC +#define LILY_GUILE_ICC + +#include "lily-guile.hh" + +templateSCM +array_to_scm (Array arr) +{ + SCM list = SCM_EOL; + for (int i = arr.size (); i--;) + list = gh_cons (to_scm (arr[i]), list); + return list; +} + +/* + Silly templates + Array scm_to_array (SCM s) + + check scm? + */ +templatevoid +scm_to_array (SCM s, Array* arr) +{ + for (; gh_pair_p (s); s= gh_cdr (s)) + { + T t; + scm_to (gh_car (s), &t); + arr->push (t); + } +} + +#endif /* LILY_GUILE_ICC */ diff --git a/lily/include/musical-pitch.hh b/lily/include/musical-pitch.hh index d4d0a60854..54899cabb4 100644 --- a/lily/include/musical-pitch.hh +++ b/lily/include/musical-pitch.hh @@ -12,6 +12,7 @@ #include "lily-proto.hh" #include "input.hh" +#include "lily-guile.hh" // we need SCM /** A "tonal" pitch. This is a pitch as it figures in diatonal western music (12 semitones in an octave), as opposed to a frequence in Hz @@ -43,6 +44,9 @@ struct Musical_pitch : public Input void print () const; }; +SCM to_scm (Musical_pitch p); +void scm_to (SCM s, Musical_pitch* p); + #include "compare.hh" INSTANTIATE_COMPARE(Musical_pitch, Musical_pitch::compare); diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index 3a32c03d69..be56d94587 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -197,19 +197,6 @@ index_set_cell (SCM s, Direction d, SCM v) return s; } -#if 0 -SCM -array_to_list (SCM *a , int l) -{ - SCM list = SCM_EOL; - for (int i= l; i--; ) - { - list = gh_cons (a[i], list); - } - return list; -} -#endif - SCM ly_warning (SCM str) { @@ -284,3 +271,28 @@ to_dir (SCM s) } +SCM +to_scm (int i) +{ + return gh_int2scm (i); +} + +void +scm_to (SCM s, int* i) +{ + // urg + *i = gh_number_p (s) ? gh_scm2int (s) : 0; +} + +SCM +to_scm (Real r) +{ + return gh_double2scm (r); +} + +void +scm_to (SCM s, Real* r) +{ + // urg + *r = gh_number_p (s) ? gh_scm2double (s) : 0; +} diff --git a/lily/musical-pitch.cc b/lily/musical-pitch.cc index 409c71d92b..d60a1fb832 100644 --- a/lily/musical-pitch.cc +++ b/lily/musical-pitch.cc @@ -10,6 +10,26 @@ #include "debug.hh" #include "main.hh" +SCM +to_scm (Musical_pitch p) +{ + return gh_list (gh_int2scm (p.notename_i_), + gh_int2scm (p.accidental_i_), + gh_int2scm (p.octave_i_), + SCM_UNDEFINED); +} + +/* + TODO: check -- is_pitch () ? + */ +void +scm_to (SCM s, Musical_pitch* p) +{ + *p = Musical_pitch (gh_scm2int (gh_car (s)), + gh_scm2int (gh_cadr (s)), + gh_scm2int (gh_caddr (s))); +} + Musical_pitch::Musical_pitch (int n, int a, int o) { notename_i_ = n; diff --git a/lily/stem.cc b/lily/stem.cc index d1bb8f5553..7c76a571f6 100644 --- a/lily/stem.cc +++ b/lily/stem.cc @@ -563,7 +563,7 @@ Stem::calc_stem_info () const if (gh_number_p (s)) info.idealy_f_ -= gh_double2scm (s); - Real interstaff_f = -beam_dir* calc_interstaff_dist (this, beam_l ()); + Real interstaff_f = -beam_dir* calc_interstaff_dist (this, beam_l ()); info.idealy_f_ += interstaff_f; info.miny_f_ += interstaff_f; diff --git a/ly/generic-paper.ly b/ly/generic-paper.ly index a4140bb73b..3e3f28c450 100644 --- a/ly/generic-paper.ly +++ b/ly/generic-paper.ly @@ -1,3 +1,6 @@ + +#(eval-string (ly-gulp-file "paper.scm")) + \paper { texsetting = ""; pssetting = ""; diff --git a/ly/params.ly b/ly/params.ly index bbeba93841..07ec6cf89d 100644 --- a/ly/params.ly +++ b/ly/params.ly @@ -97,28 +97,14 @@ grace_forced_stem_shorten3 = \grace_forced_stem_shorten2; % #'beam-dir-algorithm = #'majority %urg. -#'Stem_tremolo::beam-width = 1.5 * \quartwidth ; - -% The beams should be prevented to conflict with the stafflines, -% especially at small slopes. -#'slope-quantisation = #'normal +#'Stem_tremolo::beam-width = 1.5 * \quartwidth ; #'Clef_item::visibility-lambda = #postbreak-only-visibility #'Key_item::visibility-lambda = #postbreak-only-visibility #'Breathing_sign::visibility-lambda = #non-postbreak-visibility - -%{ -dit(code(beam_dir_algorithm)) Specify algorithm for determining -whether beams go up or down. It is real valued. If set to 2.0 then -majority selection is used. If set to 3.0, then mean selection is -used based on the mean center distance. If set to 4.0 then median -selection is used, based on the median center distance. -%} - - % catch suspect beam slopes, set slope to zero if % outer stem is lengthened more than beam_lengthened = 0.2 * \interline; diff --git a/scm/lily.scm b/scm/lily.scm index ce8c9eec87..f35e747fef 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -142,10 +142,6 @@ '(minimum-space 0.0))))) -;; Measured in interlines (urg: how to say #interline?) -(define (stem-shorten flags) 0.5) -(define (beamed-stem-shorten multiplicity) 0.5) - ;;;;;;;; TeX diff --git a/scm/paper.scm b/scm/paper.scm new file mode 100644 index 0000000000..d4eb2d3520 --- /dev/null +++ b/scm/paper.scm @@ -0,0 +1,65 @@ +;;; paper.scm -- scm paper variables and functions +;;; +;;; source file of the GNU LilyPond music typesetter +;;; +;;; (c) 1999 Jan Nieuwenhuizen + +;;; All dimensions are measured in staff-spaces + +;; TODO +;; - make easily customisable from mudela +;; - take #forced stems into account (now done in C++) +;; - take y-position of chord or beam into account +(define (stem-shorten flags) 0.5) +(define (beamed-stem-shorten multiplicity) 0.5) + + +;; Beams should be prevented to conflict with the stafflines, +;; especially at small slopes +;; ---------------------------------------------------------- +;; ######## +;; ######## +;; ######## +;; --------------########------------------------------------ +;; ######## +;; +;; hang straddle sit inter hang + +;; inter seems to be a modern quirk, we don't use that + +(define beam-normal-dy-quants + '(0 (/2 (+ beam-thickness staff-line) 2) (+ beam-thickness staff-line) 1)) + +;; two popular veritcal beam quantings +;; see params.ly: #'beam-vertical-quants +(define (beam-normal-y-quants multiplicity dy) + (let ((quants `(,beam-hang 1))) + (if (or (<= multiplicity 1) (>= (abs dy) (/ staff-line 2))) + (set! quants (cons beam-sit quants))) + (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2))) + (set! quants (cons beam-straddle quants))) + quants)) + +(define (beam-traditional-y-quants multiplicity dy) + (let ((quants '(1))) + (if (>= dy (/ staff-line -2)) + (set! quants (cons beam-hang quants))) + (if (and (<= multiplicity 1) (<= dy (/ staff-line 2))) + (set! quants (cons beam-sit quants))) + (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2))) + (set! quants (cons beam-straddle quants))) + quants)) + + +;;; Default variables and settings + +(define staff-line 0.10) +(define beam-thickness (* 0.52 (- 1 staff-line))) +(define beam-straddle 0) +(define beam-sit (/ (+ beam-thickness staff-line) 2)) +(define beam-hang (- 1 (/ (- beam-thickness staff-line) 2))) + +(define beam-height-quants beam-normal-dy-quants) +(define beam-vertical-position-quants beam-normal-y-quants) + +