lilypond-user
[Top][All Lists]
Advanced

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

Re: scheme --> (define-music-function ...)


From: David Kastrup
Subject: Re: scheme --> (define-music-function ...)
Date: Sat, 23 Nov 2013 13:55:13 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Paul <address@hidden> writes:

> I am having syntactic difficulties creating a macro.
>
> The end game is to notate "\midiOctaveCheck 4 c d e" and know that the
> notes (c, d, and e) are in the octave starting from Middle C.
>
> Here is the skeleton of what I planned to do:
>     midiOctaveCheck =
>         #(define-music-function (parser location oct-n) (integer?)
>             #{ ...music... #})
>
> This is the Scheme I want to apply:
>     (define midi-octave-check
>       (lambda (oct-n)
>         (string-append
>          "\\octaveCheck c"
>          (cond ((= oct-n 3) "")
>                ((< oct-n 3) (make-string (- 3 oct-n) #\,))
>                ((> oct-n 3) (make-string (- oct-n 3) #\'))))))
>
> Would somebody combine the two and put me out of my misery?

The former?  No.  The latter:

midiOctaveCheck =
#(define-music-function (parser location oct-n) (integer?)
  #{ \octaveCheck $(ly:make-pitch (- oct-n 3) 0) #})

However, that checks for the _previous_ note being with a fourth of
range around middle C (or whatever else), so that a following _c_ would
be a middle C (and a following g would be below middle C, and a
following f would be above).

If you are really talking about the octave _starting_ from middle C,
you'd write 3 instead of 0 as the second argument of ly:make-pitch.

-- 
David Kastrup




reply via email to

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