From 05286945fcf2083341d94fd18cf66393183ef276 Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Tue, 9 Jun 2009 20:25:10 +0300 Subject: [PATCH] Fix 453. Calculate tremolo beaming only from the repeat-count and the duration-log of the original notes. In particular, don't use any information about scaled durations when calculating the tremolo beaming. (cherry picked from commit 1ace1688c305ecf144b29673fde94fccce4cc595) --- lily/chord-tremolo-engraver.cc | 21 ++++++++------------- lily/chord-tremolo-iterator.cc | 13 ++++--------- scm/define-music-properties.scm | 2 -- scm/music-functions.scm | 22 +++++++++++++++++++++- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/lily/chord-tremolo-engraver.cc b/lily/chord-tremolo-engraver.cc index 140ab10237..28790b5a86 100644 --- a/lily/chord-tremolo-engraver.cc +++ b/lily/chord-tremolo-engraver.cc @@ -43,13 +43,11 @@ class Chord_tremolo_engraver : public Engraver protected: Stream_event *repeat_; - int flags_; - // number of beams for short tremolos - int expected_beam_count_; // current direction of beam (first RIGHT, then LEFT) Direction beam_dir_; Spanner *beam_; + protected: virtual void finalize (); void process_music (); @@ -61,8 +59,6 @@ Chord_tremolo_engraver::Chord_tremolo_engraver () { beam_ = 0; repeat_ = 0; - flags_ = 0; - expected_beam_count_ = 0; beam_dir_ = CENTER; } @@ -75,10 +71,6 @@ Chord_tremolo_engraver::listen_tremolo_span (Stream_event *ev) { if (ASSIGN_EVENT_ONCE (repeat_, ev)) { - int type = scm_to_int (ev->get_property ("tremolo-type")); - /* e.g. 1 for type 8, 2 for type 16 */ - flags_ = intlog2 (type) - 2; - expected_beam_count_ = scm_to_int (ev->get_property ("expected-beam-count")); beam_dir_ = RIGHT; } } @@ -88,7 +80,6 @@ Chord_tremolo_engraver::listen_tremolo_span (Stream_event *ev) ev->origin ()->warning (_ ("No tremolo to end")); repeat_ = 0; beam_ = 0; - expected_beam_count_ = 0; beam_dir_ = CENTER; } } @@ -118,12 +109,16 @@ Chord_tremolo_engraver::acknowledge_stem (Grob_info info) { if (beam_) { - Grob *s = info.grob (); + int tremolo_type = robust_scm2int (repeat_->get_property ("tremolo-type"), 1); + int flags = max (0, intlog2 (tremolo_type) - 2); + int repeat_count = robust_scm2int (repeat_->get_property ("repeat-count"), 1); + int gap_count = min (flags, intlog2 (repeat_count) + 1); - Stem::set_beaming (s, flags_, beam_dir_); + Grob *s = info.grob (); + Stem::set_beaming (s, flags, beam_dir_); if (Stem::duration_log (s) != 1) - beam_->set_property ("gap-count", scm_from_int (flags_ - expected_beam_count_)); + beam_->set_property ("gap-count", scm_from_int (gap_count)); if (beam_dir_ == RIGHT) { diff --git a/lily/chord-tremolo-iterator.cc b/lily/chord-tremolo-iterator.cc index c5371a2c4d..e7d9d495b1 100644 --- a/lily/chord-tremolo-iterator.cc +++ b/lily/chord-tremolo-iterator.cc @@ -36,18 +36,13 @@ Chord_tremolo_iterator::get_music_list () const if (elt_count <= 0) elt_count = 1; - - Rational total_dur = l.main_part_; - Rational note_dur = total_dur / Rational (elt_count * Repeated_music::repeat_count (mus)); - - SCM tremolo_type = scm_int2num (note_dur.den ()); - int expected_beaming_ = max (0, (intlog2 (total_dur.den ()) - intlog2 (total_dur.num () + 1) - 1)); if (elt_count == 1) { Music *ev = make_music_by_name (ly_symbol2scm ("TremoloEvent")); ev->set_spot (*origin); - ev->set_property ("tremolo-type", tremolo_type); + ev->set_property ("repeat-count", mus->get_property ("repeat-count")); + ev->set_property ("tremolo-type", mus->get_property ("tremolo-type")); return scm_list_2 (ev->unprotect (), body->self_scm ()); } else @@ -61,8 +56,8 @@ Chord_tremolo_iterator::get_music_list () const Music *stop_event = unsmob_music (stop_event_scm); start_event->set_spot (*origin); stop_event->set_spot (*origin); - start_event->set_property ("tremolo-type", tremolo_type); - start_event->set_property ("expected-beam-count", scm_int2num (expected_beaming_)); + start_event->set_property ("repeat-count", mus->get_property ("repeat-count")); + start_event->set_property ("tremolo-type", mus->get_property ("tremolo-type")); return scm_list_3 (start_event_scm, body->self_scm (), stop_event_scm); } diff --git a/scm/define-music-properties.scm b/scm/define-music-properties.scm index c89a519576..6fa69e9e2f 100644 --- a/scm/define-music-properties.scm +++ b/scm/define-music-properties.scm @@ -73,8 +73,6 @@ or the body of a repeat.") simultaneous music, or the alternatives of repeated music.") (elements-callback ,procedure? "Return a list of children, for use by a sequential iterator. Takes a single music parameter.") - (expected-beam-count ,integer? "Expected number of non-tremolo beams -in a tremolo repeat.") (figure ,integer? "A bass figure.") (force-accidental ,boolean? "If set, a cautionary accidental should diff --git a/scm/music-functions.scm b/scm/music-functions.scm index 7a8f940b60..8edb658627 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -223,6 +223,20 @@ Returns `obj'. (define-public (make-repeat name times main alts) "create a repeat music expression, with all properties initialized properly" + (define (first-note-duration music) + "Finds the duration of the first NoteEvent by searching depth-first +through MUSIC." + (if (memq 'note-event (ly:music-property music 'types)) + (ly:music-property music 'duration) + (let loop ((elts (if (ly:music? (ly:music-property music 'element)) + (list (ly:music-property music 'element)) + (ly:music-property music 'elements)))) + (and (pair? elts) + (let ((dur (first-note-duration (car elts)))) + (if (ly:duration? dur) + dur + (loop (cdr elts)))))))) + (let ((talts (if (< times (length alts)) (begin (ly:warning (_ "More alternatives than repeats. Junking excess alternatives")) @@ -235,7 +249,13 @@ Returns `obj'. (if (equal? name "tremolo") (let* ((dots (1- (logcount times))) (mult (/ (* times (ash 1 dots)) (1- (ash 2 dots)))) - (shift (- (ly:intlog2 (floor mult))))) + (shift (- (ly:intlog2 (floor mult)))) + (note-duration (first-note-duration r)) + (duration-log (if (ly:duration? note-duration) + (ly:duration-log note-duration) + 1)) + (tremolo-type (ash 1 duration-log))) + (set! (ly:music-property r 'tremolo-type) tremolo-type) (if (not (integer? mult)) (ly:warning (_ "invalid tremolo repeat count: ~a") times)) (if (memq 'sequential-music (ly:music-property main 'types)) -- 2.39.2