From 2268cf364b6b2ae67034b2e8921355e94e7a8452 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Wed, 2 Jul 2003 16:15:24 +0000 Subject: [PATCH] * lily/parser.yy (Repeated_music): bug fix beam multiplicity was completely borked * lily/chord-tremolo-engraver.cc (try_music): warnings for user-errors. (try_music): bug fix: beam multiplicity was completely borked. --- ChangeLog | 6 +++++ input/regression/chord-tremolo.ly | 39 +++++++++++++++++-------------- lily/chord-tremolo-engraver.cc | 30 ++++++++++++++++++++---- lily/duration.cc | 5 +++- lily/parser.yy | 37 +++++++++++++++++++---------- scm/define-music-types.scm | 4 ++-- 6 files changed, 83 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index 890a39f534..17a831b2ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2003-07-02 Han-Wen Nienhuys + * lily/parser.yy (Repeated_music): bug fix beam multiplicity was + completely borked + + * lily/chord-tremolo-engraver.cc (try_music): warnings for user-errors. + (try_music): bug fix: beam multiplicity was completely borked. + * scm/lily.scm: remove tail, filter-list, filter-out-list, first-n, butfirst-n in favor of srfi-1 functions. remove string-join, string-pad in favor of srfi-13 functions. diff --git a/input/regression/chord-tremolo.ly b/input/regression/chord-tremolo.ly index 4a7cddf3ff..8312a186f1 100644 --- a/input/regression/chord-tremolo.ly +++ b/input/regression/chord-tremolo.ly @@ -8,33 +8,36 @@ leave a gap. Chord tremolo beams on half notes are not ambiguous, as half notes cannot appear in a regular beam, and should reach the stems. +In this example, each tremolo lasts exactly one measure. + (To ensure that the spacing engine is not confused we add some regular notes as well.) " } \score { \context Voice \notes\relative c' { - % huh -> one beam missing! - \repeat "tremolo" 16 { d16 e } + \time 4/4 + \repeat "tremolo" 16 { d32 e } \repeat "tremolo" 8 { d16 e } - \repeat "tremolo" 4 { d e } - \repeat "tremolo" 2 { d e } - c4 - \break - \repeat "tremolo" 4 { f'8 e } - \repeat "tremolo" 2 { f e } - c4 c4 - - \repeat "tremolo" 3 { f8 e } - c4 - c4 c4 c4 c4 - c4 c4 c4 c4 - c4 c4 c4 c4 + \repeat "tremolo" 4 { d8 e } + + \time 3/4 + \repeat "tremolo" 12 { d32 e } + \repeat "tremolo" 6 { d16 e } + \repeat "tremolo" 3 { d8 e } + + \time 2/4 + \repeat "tremolo" 8 { d32 e } + \repeat "tremolo" 4 { d16 e } + \repeat "tremolo" 2 { d8 e } + \time 1/4 + \repeat "tremolo" 4 { d32 e } + \repeat "tremolo" 2 { d16 e } + + c4 c4 c4 c4 c4 } - \paper { - linewidth = 90*\staffspace - } + \midi { } } %% new-chords-done %% diff --git a/lily/chord-tremolo-engraver.cc b/lily/chord-tremolo-engraver.cc index 9f41805805..ad72b7f769 100644 --- a/lily/chord-tremolo-engraver.cc +++ b/lily/chord-tremolo-engraver.cc @@ -86,11 +86,33 @@ Chord_tremolo_engraver::try_music (Music * m) repeat_ = rp; start_mom_ = now_mom (); stop_mom_ = start_mom_ + l; - sequential_body_b_ = dynamic_cast (rp->body ()); + Sequential_music * seq = dynamic_cast (rp->body ()); + sequential_body_b_ = seq; + + int elt_count = seq ? scm_ilength (seq-> music_list ()) : 1; + + if (elt_count != 2) + { + rp->origin ()->warning (_f ("Chord tremolo with %d elements. Must have two elements.", elt_count)); + } + + if (elt_count <= 0) + elt_count = 1; + Rational total_dur = l.main_part_; - Rational note_dur = (total_dur / Rational (repeat_->repeat_count ())); - flags_ = intlog2 ((total_dur / note_dur).num ()); + Rational note_dur = total_dur / Rational (elt_count * repeat_->repeat_count ()); + + if (total_dur < Rational (1,4)) + { + /* + This would require beams between flagged (8th) notes. + */ + rp->origin ()->warning ("Chord tremolo is too short to denote properly."); + } + + Rational written_note_dur = total_dur / Rational (elt_count); + flags_ = intlog2 (note_dur.den ()) -2 ; return true; } @@ -116,14 +138,12 @@ Chord_tremolo_engraver::process_music () } else if (!sequential_body_b_ && !stem_tremolo_) { - if (flags_) { stem_tremolo_ = new Item (get_property ("StemTremolo")); announce_grob(stem_tremolo_, repeat_->self_scm()); stem_tremolo_->set_grob_property ("flag-count", scm_int2num (flags_)); - } } } diff --git a/lily/duration.cc b/lily/duration.cc index 3847353d26..6443153f51 100644 --- a/lily/duration.cc +++ b/lily/duration.cc @@ -180,7 +180,10 @@ LY_DEFINE(make_duration, num = gh_int2scm (1); if (den != SCM_UNDEFINED) - SCM_ASSERT_TYPE(gh_number_p (den), length, SCM_ARG4, __FUNCTION__, "integer"); + { + SCM_ASSERT_TYPE(gh_number_p (den), length, SCM_ARG4, __FUNCTION__, "integer"); + compress = true; + } else den = gh_int2scm (1); diff --git a/lily/parser.yy b/lily/parser.yy index 72086b41a8..aff60db1e3 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -71,7 +71,7 @@ TODO: #include "input-smob.hh" #include "event.hh" #include "text-item.hh" - +#include "music-list.hh" #define MY_MAKE_MUSIC(x) make_music_by_name (ly_symbol2scm (x)) @@ -794,17 +794,30 @@ Repeated_music: r->set_mus_property ("repeat-count", gh_int2scm (times >? 1)); r-> set_mus_property ("elements",alts); - if (gh_equal_p ($2, scm_makfrom0str ("tremolo"))) - { - /* - we can not get durations and other stuff correct down the line, so we have to - add to the duration log here. - */ - SCM func = scm_primitive_eval (ly_symbol2scm ("shift-duration-log")); - if (($3 % 3) == 0) - gh_call3 (func, r->self_scm (), gh_int2scm(-intlog2 ($3*2/3)),gh_int2scm(1)); - else - gh_call3 (func, r->self_scm (), gh_int2scm(-intlog2 ($3)), gh_int2scm(0)); + if (gh_equal_p ($2, scm_makfrom0str ("tremolo"))) { + /* + we can not get durations and other stuff correct down the line, so we have to + add to the duration log here. + */ + static SCM func; + + if (!func) + func = scm_primitive_eval (ly_symbol2scm ("shift-duration-log")); + + int dots = ($3 % 3) ? 0 : 1; + int shift = -intlog2 ((dots) ? ($3*2/3) : $3); + + Sequential_music * seq = dynamic_cast ($4); + + if (seq) { + int list_len =scm_ilength (seq->music_list ()); + if (list_len != 2) + seq->origin ()->warning ("Chord tremolo must have 2 elements."); + shift -= 1; + r->compress (Moment (Rational (1,list_len))); + } + gh_call3 (func, r->self_scm (), gh_int2scm(shift),gh_int2scm(dots)); + } r->set_spot (*$4->origin ()); diff --git a/scm/define-music-types.scm b/scm/define-music-types.scm index e44981c176..d0fdce20c8 100644 --- a/scm/define-music-types.scm +++ b/scm/define-music-types.scm @@ -607,7 +607,7 @@ For example, transposed music.") (types . (general-music repeated-music percent-repeated-music)) )) - (TremoloRepeteadMusic + (TremoloRepeatedMusic . ( (iterator-ctor . ,Chord_tremolo_iterator::constructor) (description . "Repeated notes denoted by tremolo beams.") @@ -682,7 +682,7 @@ For example, transposed music.") '(("volta" . VoltaRepeatedMusic) ("unfold" . UnfoldedRepeatedMusic) ("percent" . PercentRepeatedMusic) - ("tremolo" . TremoloRepeteadMusic) + ("tremolo" . TremoloRepeatedMusic) ("fold" . FoldedRepeatedMusic) ))) (music-name -- 2.39.5