lilypond-user
[Top][All Lists]
Advanced

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

Re: In octaves


From: Jonathan Kulp
Subject: Re: In octaves
Date: Thu, 24 Apr 2008 21:26:38 -0500
User-agent: Thunderbird 2.0.0.12 (X11/20080227)

Got it. Thanks Valentin. It's working for me exactly as you describe, with the unfortunate \relative trouble. I'd try to fix it myself but I can't make heads nor tails of that code. Much to learn...

Still, thanks both to you and Jay for the code. Even with the \relative bug it'll still save me lots of typing and make my code look much more tidy. :-)

Jon

Valentin Villenave wrote:

Hi Jonathan, here's the function I proposed earlier. it takes a number
as an argument: if you want to add upper octaves, specify #1, if you
want lower octaves, type #-1. Its very dirty and it suffers from the
same bug (i.e. it's probably a bad idea to use it inside a \relative
block when you have to use commas and single quotes), but hopefully
someone will clean the code and address the issue.

#(define (octave-up m t)
          (make-music 'NoteEvent
            'duration (ly:music-property m 'duration)
            'pitch (ly:make-pitch (+ t (ly:pitch-octave
(ly:music-property m 'pitch)))
                        (ly:pitch-notename (ly:music-property m 'pitch))
                        (ly:pitch-alteration (ly:music-property m '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))))
 music)

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

 \relative { c d e \octaves #-1 { f g c }}


Cheers,
Valentin


--
Jonathan Kulp
http://www.jonathankulp.com




reply via email to

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