lilypond-user
[Top][All Lists]
Advanced

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

Re: Custom Format


From: Aaron Hill
Subject: Re: Custom Format
Date: Thu, 01 Apr 2021 09:58:37 -0700
User-agent: Roundcube Webmail/1.4.9

On 2021-03-31 12:12 pm, Callum Cassidy-Nolan wrote:
Could you explain why 6 usually corresponds to the pitch B and not always?

B does not always mean B natural. In systems where H is a note, B is the name for B flat. The documentation here is perhaps a little misleading in that it implies the implementation is doing something conditionally.


Also I am new to Scheme and still trying to wrap my head around your
original function:

#(define (: n)
   (apply
    ly:make-pitch
    (cons (1- (floor (/ n 12)))
          (list-ref `((0 0) (0 ,SHARP) (1 0) (1 ,SHARP)
                      (2 0) (3 0) (3 ,SHARP) (4 0)
                      (4 ,SHARP) (5 0) (5 ,SHARP) (6 0))
                    (modulo n 12)))))

Here is my best guess, for each element in the following list - apply
the function make-pitch to each element.

There is no "for each" going on here. apply lets you call a procedure and supply the arguments as a list. Consider:

;;;;
(apply proc '(1 2 3))
; ...is equivalent to...
(proc 1 2 3)
;;;;

Upon reflection, I did not need to use cons to form the argument list. apply also supports this pattern:

;;;;
(apply proc 1 '(a b))
; ...is equivalent to...
(proc 1 'a 'b)
;;;;

The reason I need to use apply at all is because I need to customize the second and third arguments based on the input index n, and I wanted to avoid duplicating logic.


floor (/ n 12 ): is representing how many octaves fit into this
number? Why do you subtract this number from one?

The Scheme expression (1- n) must not be confused with the algebraic (1 - n) [which would be written in Scheme as (- 1 n)]. The procedures 1+ and 1- are the increment and decrement operations. So what I am doing is subtracting one from the number, not the other way around.

The reason for this is simply to follow existing LilyPond convention. The unadorned note { c } is (ly:make-pitch -1 0 0). To get Middle C, you need to say { c' } which puts you in octave 0.


The list-ref thing is choosing one of the elements from that list ,
but I don't fully understand what an arbitrary element from that list
actually is, for example what does (3, SHARP) mean?

These are the second and third arguments for ly:make-pitch. So using (3 ,SHARP) results in F#.

NOTE: As you are new to Scheme, the comma can be an unexpected item. The original list uses a feature called quasi-quotation. This is indicated by the leading backtick (`) as opposed to a straight quote (') which is the shorthand for normal quoting. Quasi-quoting lets you "unquote" by using the comma. Since we need the value of SHARP, not its name as a symbol, this is useful. Consider:

;;;;
'(3 SHARP)  ;; => (list 3 (quote SHARP))
`(3 ,SHARP) ;; => (list 3 1/2)
;;;;

I could avoid quasi-quoting by defining the list as follows:

;;;;
'((0 0) (0 1/2) (1 0) (1 1/2) (2 0) (3 0)
  (3 1/2) (4 0) (4 1/2) (5 0) (5 1/2) (6 0))
;;;;

But then one wonders what the magic 1/2 means. Technically, I should have used ,NATURAL in place of zero in the original list since that is also a magic number.


-- Aaron Hill



reply via email to

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