[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Fix 1676: Properly count the notes in a chord tremolo (ignore all no
From: |
reinhold . kainhofer |
Subject: |
Re: Fix 1676: Properly count the notes in a chord tremolo (ignore all non-note events) (issue4685049) |
Date: |
Mon, 11 Jul 2011 11:44:19 +0000 |
Reviewers: Neil Puttock, J_lowe,
Message:
On 2011/07/10 23:03:21, J_lowe wrote:
This passes a make but fails a reg test check
New patch uploaded that uses Neil's suggestions about
extract-named-music. That function also correctly works with repeated
chords, so the crash also goes away with the new patch.
Cheers,
Reinhold
Description:
Fix 1676: Properly count the notes in a chord tremolo (ignore all
non-note events)
Please review this at http://codereview.appspot.com/4685049/
Affected files:
A input/regression/chord-tremolo-other-commands.ly
M scm/music-functions.scm
Index: input/regression/chord-tremolo-other-commands.ly
diff --git a/input/regression/chord-tremolo-other-commands.ly
b/input/regression/chord-tremolo-other-commands.ly
new file mode 100644
index
0000000000000000000000000000000000000000..f8c347bb38ddd24bdb57599fccbd249a815f0d62
--- /dev/null
+++ b/input/regression/chord-tremolo-other-commands.ly
@@ -0,0 +1,24 @@
+\version "2.15.5"
+
+\header {
+ texidoc = "
+To calculate the total duration of chord tremolos, only real notes shall be
+counted, no other commands.
+"
+}
+
+right = \relative c'' {
+ s2
+}
+
+left = \relative c' {
+ % This tremolo contains just two notes (but three lilypond
events/commands!)
+ \repeat tremolo 4 { f,16 \change Staff = "right" f'}
+}
+
+\score {
+ \new PianoStaff <<
+ \new Staff = "right" { \right }
+ \new Staff = "left" { \clef bass \left }
+ >>
+}
Index: scm/music-functions.scm
diff --git a/scm/music-functions.scm b/scm/music-functions.scm
index
7c52d41846632b8ffda35086e6cdf49b032949ec..6c424bab504e9bf46995d1655f1f37718c43c5e6
100644
--- a/scm/music-functions.scm
+++ b/scm/music-functions.scm
@@ -246,6 +246,17 @@ scales the music up by a factor address@hidden * (2 -
(1/2)address@hidden)'."
(music-map (lambda (x) (shift-one-duration-log x shift dot))
music))
+(define (note-count music-elements)
+"Count how many notes the argument list contains (ignores all other
commands)."
+ (let count
+ ((lst music-elements))
+ (if (pair? lst)
+ ;; Increment only for EventChord entries
+ (if (eqv? (ly:music-property (car lst) 'name) 'EventChord)
+ (1+ (count (cdr lst)))
+ (count (cdr lst)))
+ 0)))
+
(define-public (make-repeat name times main alts)
"Create a repeat music expression, with all properties initialized
properly."
@@ -278,11 +289,11 @@ through MUSIC."
;; This works for single-note and multi-note tremolos!
(let* ((children (if (music-is-of-type? main 'sequential-music)
;; \repeat tremolo n { ... }
- (length (ly:music-property main 'elements))
+ (length (extract-named-music main 'EventChord))
;; \repeat tremolo n c4
1))
;; # of dots is equal to the 1 in bitwise representation (minus
1)!
- (dots (1- (logcount (* times children))))
+ (dots (1- (logcount (* times children))))
;; The remaining missing multiplicator to scale the notes by
;; times * children
(mult (/ (* times children (ash 1 dots)) (1- (ash 2 dots))))
@@ -304,7 +315,7 @@ through MUSIC."
(define (calc-repeat-slash-count music)
"Given the child-list @var{music} in @code{PercentRepeatMusic},
calculate the number of slashes based on the durations. Returns @code{0}
-if durations in in @var{music} vary, allowing slash beats and
double-percent
+if durations in @var{music} vary, allowing slash beats and double-percent
beats to be distinguished."
(let* ((durs (map (lambda (elt)
(duration-of-note elt))