[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: In octaves

From: Jay Anderson
Subject: Re: In octaves
Date: Sun, 27 Apr 2008 21:15:11 -0700

> Let me know how it works!

A couple more changes:

#(define (octave-up m t)
  (let* ((octave (1- t))
        (new-note (ly:music-deep-copy m))
        (new-pitch (ly:make-pitch
          (ly:pitch-notename (ly:music-property m 'pitch))
          (ly:pitch-alteration (ly:music-property m 'pitch)))))
    (set! (ly:music-property new-note 'pitch) new-pitch)

#(define (octavize-chord elements t)
 (cond ((null? elements) elements)
       ((eq? (ly:music-property (car elements) 'name) 'NoteEvent)
         (cons (car elements)
               (cons (octave-up (car elements) t)
                     (octavize-chord (cdr elements) t))))
       (else (cons (car elements) (octavize-chord (cdr elements ) t)))))

#(define (octavize music t)
 (let* ((es (ly:music-property music 'elements))
        (e (ly:music-property music 'element))
        (name (ly:music-property music 'name)))
   (cond ((eq? name 'EventChord)
          (ly:music-set-property! music 'elements (octavize-chord es t)))
         ((pair? es)
          (for-each (lambda(x) (octavize x t)) es))
         ((ly:music? e)
          (octavize e))))

octaves = #(define-music-function (parser location arg mus) (integer? ly:music?)
 (octavize mus arg))

Now you can do silly things like: \relative c'{ \octaves #2 {c d e f'
g,,} } and it will make the new note two octaves up. I'm not sure why
you'd want that, but it seemed easy enough to do (and takes slightly
less code).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]