]> git.donarmstrong.com Git - lilypond.git/commitdiff
patch::: 1.3.15.jcn2
authorJan Nieuwenhuizen <janneke@gnu.org>
Tue, 21 Dec 1999 10:44:57 +0000 (11:44 +0100)
committerJan Nieuwenhuizen <janneke@gnu.org>
Tue, 21 Dec 1999 10:44:57 +0000 (11:44 +0100)
pl 15.jcn2
- beam quanting using scm lists

15 files changed:
CHANGES
VERSION
input/test/beam-quanting.ly [new file with mode: 0644]
lily/beam.cc
lily/chord-name.cc
lily/include/lily-guile.hh
lily/include/lily-guile.icc [new file with mode: 0644]
lily/include/musical-pitch.hh
lily/lily-guile.cc
lily/musical-pitch.cc
lily/stem.cc
ly/generic-paper.ly
ly/params.ly
scm/lily.scm
scm/paper.scm [new file with mode: 0644]

diff --git a/CHANGES b/CHANGES
index 87bebcbd4b82442c121c6d872a4cf1992fb718c8..cfc164b2bb603044c3ce762474e42798378af5f3 100644 (file)
--- 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 538ce3a83ba67a3eff873055db77372af30b2cea..8644a073a413cbdd22f6511f8687e0c4db031746 100644 (file)
--- 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 (file)
index 0000000..f0f9cc1
--- /dev/null
@@ -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
+    }
+}
index 8620f8747c69b8351700c0624d3cd6b07674e8c7..7305ff69c6f7baf79e11c63918c51fe81157855a 100644 (file)
@@ -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<Real> 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<Real> 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<Real> 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<Real> 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];
index a202812d32c057d209261269c78f705fee21b677..4b6eff78a91104e6649674a2863f17c026d8c633 100644 (file)
 #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)));
-}
-  
-template<class T>SCM
-array_to_scm (Array<T> arr)
-{
-  SCM list = SCM_EOL;
-  for (int i = arr.size (); i--;)
-    list =  gh_cons (to_scm (arr[i]), list);
-  return list;
-}
-
-/*
-  Silly templates
-  Array<T> scm_to_array (SCM s)
- */
-template<class T>void
-scm_to_array (SCM s, Array<T>* 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);
     }
 
index 84af73262bfa92093c2ac9477b85ba08cd353dcc..f66caa760add1770797eed1a08c9168a0e6f986d 100644 (file)
@@ -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);
 
+template<class T>SCM array_to_scm (Array<T> arr);
+template<class T>void scm_to_array (SCM s, Array<T>* 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 (file)
index 0000000..1152117
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+  lily-guile.icc -- implement guile templates
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 1999 Jan Nieuwenhuizen <janneke@gnu.org>
+*/
+
+#ifndef LILY_GUILE_ICC
+#define LILY_GUILE_ICC
+
+#include "lily-guile.hh"
+
+template<class T>SCM
+array_to_scm (Array<T> arr)
+{
+  SCM list = SCM_EOL;
+  for (int i = arr.size (); i--;)
+    list =  gh_cons (to_scm (arr[i]), list);
+  return list;
+}
+
+/*
+  Silly templates
+  Array<T> scm_to_array (SCM s)
+
+  check scm?
+ */
+template<class T>void
+scm_to_array (SCM s, Array<T>* 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 */
index d4d0a60854c2c9bf6e91bd07b2f026cd24deecd8..54899cabb430597a42a8e43d13edd2e46a0ab585 100644 (file)
@@ -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);
 
index 3a32c03d69eeecbddcd69ae5da80da3cce7bc819..be56d94587a97514513ab7c91f778eb9bdec48bb 100644 (file)
@@ -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;
+}
index 409c71d92b496b6fb63563cdb317d87498f86d3a..d60a1fb832f2e043ce0aee6d82bb94c618465eb6 100644 (file)
 #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;
index d1bb8f55539657390a2332daee46c0b25f44ae4a..7c76a571f65b685ed457121e373f1dd93ec817d1 100644 (file)
@@ -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;
index a4140bb73b209f9e8c5040953bc160cc2a28391a..3e3f28c4508733851cf63b117c79cb318c99ef99 100644 (file)
@@ -1,3 +1,6 @@
+
+#(eval-string (ly-gulp-file "paper.scm"))
+
 \paper {
        texsetting = "";
        pssetting = "";
index bbeba9384157dfdab38514ce3f44e95130e01dae..07ec6cf89d872aa684a3809d6d15116c258fea31 100644 (file)
@@ -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;
index ce8c9eec87cfed6aaaebd5ba314fbecce86af2a1..f35e747fef51aaea91eb68e76182d5e647a3c4aa 100644 (file)
               '(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 (file)
index 0000000..d4eb2d3
--- /dev/null
@@ -0,0 +1,65 @@
+;;; paper.scm -- scm paper variables and functions
+;;;
+;;;  source file of the GNU LilyPond music typesetter
+;;; 
+;;; (c) 1999 Jan Nieuwenhuizen <janneke@gnu.org>
+
+;;; 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)
+
+