From: fred Date: Wed, 27 Mar 2002 01:20:26 +0000 (+0000) Subject: lilypond-1.5.2 X-Git-Tag: release/1.5.59~600 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=c9e0fe567e13a526982b37efddc01279f2cf1273;p=lilypond.git lilypond-1.5.2 --- diff --git a/flower/include/array.icc b/flower/include/array.icc index 6ede38df66..46194f587f 100644 --- a/flower/include/array.icc +++ b/flower/include/array.icc @@ -108,3 +108,41 @@ Array::slice (int lower, int upper) const return r; } + +/* + lookup with binsearch, return array index. +*/ +template +int +binary_search (Array const &table, + T const &key, int (*compare) (T const&, T const &), + int lo = 0, + int hi = -1 + ) +{ + int cmp; + int result; + if (hi < 0) + hi = table.size (); + + /* binary search */ + do + { + cmp = (lo + hi) / 2; + + result = (*compare) (key, table[cmp]); + + if (result < 0) + hi = cmp; + else + lo = cmp; + } + while (hi - lo > 1); + if (! (*compare) (key, table[lo])) + { + return lo; + } + else + return -1; /* not found */ +} + diff --git a/flower/include/parray.hh b/flower/include/parray.hh index 52399b1718..c39ec2500b 100644 --- a/flower/include/parray.hh +++ b/flower/include/parray.hh @@ -265,14 +265,13 @@ binsearch_array (Array const &arr, T t, int (*compare) (T const&,T const&)) template int binsearch_link_array (Link_array const &arr, T *t, - int (*compare) (T *const&,T *const&)) + int (*compare) (T *const&,T *const&), + int lo = 0, int hi = -1 ) { - int lo; - int hi; int cmp; int result; - lo = 0; - hi = arr.size (); + if (hi< 0) + hi = arr.size (); if (hi == 0) return -1; diff --git a/input/bugs/1st-note-spacing.ly b/input/bugs/1st-note-spacing.ly new file mode 100644 index 0000000000..f6170027fd --- /dev/null +++ b/input/bugs/1st-note-spacing.ly @@ -0,0 +1,8 @@ + +\score {\notes \relative c'' < +\context Staff = SA { \times 6/7 { [c8 c c c c c c] } } +\context Staff = SB { \times 6/6 { [c c c c c c] } } +> + +\paper { linewidth = -1. } +} diff --git a/input/bugs/standchen-space.ly b/input/bugs/standchen-space.ly new file mode 100644 index 0000000000..7d9e6322ab --- /dev/null +++ b/input/bugs/standchen-space.ly @@ -0,0 +1,9 @@ + +\score { +\notes \relative c' < +\context Staff = SA { c4. c8 \times 2/3 { [c8 c c] } } +\context Staff = SB { c8 c c c c c } +> + +\paper { linewidth = -1. } +} diff --git a/lily/include/keyword.hh b/lily/include/keyword.hh index c2c6338a0a..8518f958da 100644 --- a/lily/include/keyword.hh +++ b/lily/include/keyword.hh @@ -7,11 +7,13 @@ #ifndef KEYWORD_HH #define KEYWORD_HH +#include "array.hh" + /* for the keyword table */ struct Keyword_ent { - char const *name; - int tokcode; + char const *name_; + int tokcode_; }; /* @@ -19,8 +21,8 @@ struct Keyword_ent */ struct Keyword_table { - Keyword_ent *table; - int maxkey; + Array table_; + Keyword_table (Keyword_ent *); int lookup (char const *s) const; }; diff --git a/lily/include/paper-column.hh b/lily/include/paper-column.hh index 6660379575..507ba6f0fe 100644 --- a/lily/include/paper-column.hh +++ b/lily/include/paper-column.hh @@ -34,7 +34,7 @@ public: static int rank_i (Grob*); Paper_column (SCM); - bool musical_b () const; + static bool musical_b (Grob *); static Moment when_mom (Grob*); static bool used_b (Grob*) ; diff --git a/lily/keyword.cc b/lily/keyword.cc index e235d6a973..de6aca9e49 100644 --- a/lily/keyword.cc +++ b/lily/keyword.cc @@ -7,56 +7,29 @@ /* for qsort */ -int - tabcmp (void const * p1, void const * p2) +int tabcmp (Keyword_ent const &p1, Keyword_ent const &p2) { - return strcmp (( (Keyword_ent const *) p1)->name, - ((Keyword_ent const *) p2)->name); + return strcmp (p1.name_, p2.name_); } Keyword_table::Keyword_table (Keyword_ent *tab) { - table = tab; - - /* count keywords */ - for (maxkey = 0; table[maxkey].name; maxkey++) - ; + while (tab->name_) + { + table_.push (*tab++); + } - /* sort them */ - qsort (table, maxkey, sizeof (Keyword_ent), tabcmp); + table_.sort (tabcmp); } -/* - lookup with binsearch, return tokencode. -*/ int Keyword_table::lookup (char const *s) const { - int lo; - int hi; - int cmp; - int result; - lo = 0; - hi = maxkey; - - /* binary search */ - do - { - cmp = (lo + hi) / 2; - - result = strcmp (s, table[cmp].name); - - if (result < 0) - hi = cmp; - else - lo = cmp; - } - while (hi - lo > 1); - if (!strcmp (s, table[lo].name)) - { - return table[lo].tokcode; - } + Keyword_ent e ; + e.name_ = s; + int idx = binary_search (table_, e, tabcmp); + if (idx >= 0) + return table_[idx].tokcode_; else - return -1; /* not found */ + return -1; } - diff --git a/lily/paper-column.cc b/lily/paper-column.cc index e9cd3be70e..14774ed651 100644 --- a/lily/paper-column.cc +++ b/lily/paper-column.cc @@ -59,19 +59,20 @@ Paper_column::when_mom (Grob*me) } return s; } - + bool -Paper_column::musical_b () const +Paper_column::musical_b (Grob *me) { - SCM m = get_grob_property ("shortest-starter-duration"); + SCM m = me->get_grob_property ("shortest-starter-duration"); Moment s (0); if (unsmob_moment (m)) { s = *unsmob_moment (m); } return s != Moment (0); + } - + bool Paper_column::used_b (Grob*me) { diff --git a/lily/spacing-spanner.cc b/lily/spacing-spanner.cc index 31d44a0d7e..1bff342744 100644 --- a/lily/spacing-spanner.cc +++ b/lily/spacing-spanner.cc @@ -23,6 +23,73 @@ Spacing_spanner::set_interface (Grob*me) me->set_extent_callback (SCM_EOL, Y_AXIS) ; } +#if 0 +struct Note_run +{ + Array idxes; + int start, end; + Moment duration; + int count; +}; + +int +column_compare (Grob *const &t1, Grob *const &t2) +{ + return Moment::compare (Paper_column::when_mom (t1), + Paper_column::when_mom (t2)); +} + + +Note_run +run_length (Moment dt, int i, Array const &moms, + Link_array runs) +{ + int k = 0; + Array idxes; + + idxes.push (i); + while (1) + { + Moment next = moms[i] + dt; + while (i < moms.size () && moms[i] < next) + i++; + if (i == moms.size () || moms[i] != next) + break; + + idxes.push (i); + k++; + } + + Moment dur = idxes.size () +} + +void +find_runs (Grob*me, Link_array cols) +{ + Link_array filter_cols; + Array col_moments; + for (int i = 0; i < cols.size (); i++) + { + Moment w = Paper_column::when_mom (cols[i]); + + if (!w.grace_mom_ && Paper_column::musical_b (cols[i])) + { + filter_cols.push (cols[i]); + col_moments.push (w); + } + } + + Moment end_mom = col_moments.top (); + for (int i = 0; i < col_moments.size () ; i++) + { + for (int j = i+1; j < col_moments.size (); j++) + { + Moment dt = Paper_column::col_momentsfilter_cols + } + } +} +#endif + /* The algorithm is partly taken from : @@ -51,7 +118,7 @@ Spacing_spanner::do_measure (Grob*me, Link_array cols) int n = 0; for (int i =0 ; i < cols.size (); i++) { - if (dynamic_cast (cols[i])->musical_b ()) + if (Paper_column::musical_b (cols[i])) { Moment *when = unsmob_moment (cols[i]->get_grob_property ("when")); @@ -116,11 +183,11 @@ Spacing_spanner::do_measure (Grob*me, Link_array cols) left_distance = gh_scm2double (gh_cdr (hint)); } // 2nd condition should be (i+1 < col_count ()), ie. not the last column in score. FIXME - else if (!lc->musical_b () && i+1 < cols.size ()) + else if (!Paper_column::musical_b (lc) && i+1 < cols.size ()) { left_distance= default_bar_spacing (me,lc,rc,shortest musical_b ()) + else if (Paper_column::musical_b ( lc)) { left_distance = note_spacing (me,lc, rc, shortest cols) /* don't want to create too much extra space for accidentals */ - if (rc->musical_b ()) + if (Paper_column::musical_b (rc)) { if (to_boolean (rc->get_grob_property ("contains-grace"))) right_dist *= gh_scm2double (rc->get_grob_property ("before-grace-spacing-factor")); // fixme. @@ -271,7 +338,13 @@ Spacing_spanner::note_spacing (Grob*me, Grob *lc, Grob *rc, } Moment delta_t = Paper_column::when_mom (rc) - Paper_column::when_mom (lc); Real dist = get_duration_space (me, shortest_playing_len, shortest); - dist *= (double) (delta_t / shortest_playing_len); + + + /* + ugh: 0.1 is an arbitrary distance. + */ + dist *= (double) (delta_t.main_part_ / shortest_playing_len.main_part_) + + 0.1 * (double) (delta_t.grace_mom_ / shortest_playing_len.main_part_); diff --git a/ly/grace-init.ly b/ly/grace-init.ly index 54211cb4d9..92e9c30c2f 100644 --- a/ly/grace-init.ly +++ b/ly/grace-init.ly @@ -1,58 +1,38 @@ - - #(define (grace-beam-space-function multiplicity) - (* (if (<= multiplicity 3) 0.816 0.844) 0.8)) - - - #(define (make-text-checker text) - (lambda (elt) (equal? text (ly-get-grob-property elt 'text)))) +#(define (grace-beam-space-function multiplicity) + (* (if (<= multiplicity 3) 0.816 0.844) 0.8)) startGraceMusic = { - -%{ -from GraceContext - Stem \override #'flag-style = #"grace" - Stem \override #'stem-length = #6.0 - Stem \override #'direction = #1 - - NoteHead \override #'font-relative-size = #-1 - Stem \override #'font-relative-size = #-1 - Stem \override #'stem-shorten = #'(0) - Beam \override #'font-relative-size = #-1 - TextScript \override #'font-relative-size = #-1 - Slur \override #'font-relative-size = #-1 - Accidentals \override #'font-relative-size = #-1 - Beam \override #'thickness = #0.3 - Beam \override #'space-function = #(lambda (x) 0.5) - - Stem \override #'lengths = #(map (lambda (x) (* 0.8 x)) '(3.5 3.5 3.5 4.5 5.0)) - Stem \override #'beamed-lengths = - #'(0.0 2.5 2.0 1.5) - Stem \override #'beamed-minimum-lengths - = #(map (lambda (x) (* 0.8 x)) '(0.0 2.5 2.0 1.5)) -%} - - - \property Voice.NoteHead \override #'font-relative-size = #-1 + \property Voice.Stem \override #'direction = #1 \property Voice.Stem \override #'length = #6 + \property Voice.Stem \override #'lengths = + #(map (lambda (x) (* 0.8 x)) '(3.5 3.5 3.5 4.5 5.0)) \property Voice.Stem \override #'beamed-lengths = #(map (lambda (x) (* 1.25 x)) '(0.0 2.5 2.0 1.5)) \property Voice.Stem \override #'beamed-minimum-lengths = #(map (lambda (x) (* 1.25 x)) '(0.0 1.5 1.25 1.0)) - \property Voice.Beam \override #'space-function = #grace-beam-space-function - \property Voice.fontSize = #-2 \property Voice.Stem \override #'no-stem-extend = ##t + \property Voice.Stem \override #'flag-style = #"grace" -% \property Voice.Stem \override #'flag-style = #"grace" + \property Voice.Beam \override #'space-function = #grace-beam-space-function + \property Voice.Beam \override #'thickness = #0.3 + + % must use staff. Accidentals should also be smaller. + \property Staff.fontSize = #-2 } stopGraceMusic = { -% \property Voice.Stem \revert #'flag-style - \property Voice.Stem \override #'no-stem-extend = ##f - \property Voice.Stem \revert #'length + \property Voice.Beam \revert #'space-function + \property Voice.Beam \revert #'thickness + + \property Voice.Stem \revert #'flag-style + \property Voice.Stem \revert #'no-stem-extend \property Voice.Stem \revert #'beamed-lengths \property Voice.Stem \revert #'beamed-minimum-lengths - \property Voice.Beam \revert #'space-function - \property Voice.fontSize \unset + \property Voice.Stem \revert #'lengths + \property Voice.Stem \revert #'length + \property Voice.Stem \revert #'direction + + \property Staff.fontSize \unset }