]> git.donarmstrong.com Git - lilypond.git/commitdiff
Fix 453.
authorJoe Neeman <joeneeman@gmail.com>
Tue, 9 Jun 2009 17:25:10 +0000 (20:25 +0300)
committerPatrick McCarty <pnorcks@gmail.com>
Fri, 17 Jul 2009 09:47:33 +0000 (02:47 -0700)
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
lily/chord-tremolo-iterator.cc
scm/define-music-properties.scm
scm/music-functions.scm

index 140ab102373d266347d8775914e0c4382ccdaea4..28790b5a868019d928deada7a9d305f50d5d55eb 100644 (file)
@@ -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)
        {
index c5371a2c4d2c875a8bf907b190e39e25c56a0376..e7d9d495b15bb64960e5ca9138b0180f1c45edb1 100644 (file)
@@ -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);
     }
index c89a519576f82e2945ba3178b8c842f293df20d7..6fa69e9e2f71f0ebcde16e070e680efeb8c9be81 100644 (file)
@@ -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
index 7a8f940b6010b6f5f12fcaa2c7735a8e003b5bcb..8edb6586270efe444476505a5cd5871077147419 100644 (file)
@@ -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))