[Top][All Lists]

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

Re: In octaves

From: Valentin Villenave
Subject: Re: In octaves
Date: Fri, 25 Apr 2008 02:52:17 +0200

2008/4/24 Jonathan Kulp <address@hidden>:
> Ok, so if I wanted to have both options available, how would I do the scheme
> code to define, say, "octavesUp = " and "octavesDown = ".  I see from
> Valentin's tip how to change it so that \octaves will be either up down, but
> it would be great to be able to do both.  Either that, or for the \relative
> stuff to work.  I sent a message to the list with examples of what happened
> when I tried using a , or ' with the \octaves command but I think the
> message got blocked somehow (it hasn't shown up in my box anyway). Thanks
> guys,

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))))

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 }}


reply via email to

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