2016-02-16 109 views
0

我試圖創建一個函數,其中對於一個例子,\generateNote #3 #4將產生F4映射數字來說明 - 這將有助於編寫函數快速生成秤等LilyPond的:我怎樣纔能有計劃

generateNote = 
#(define-music-function 
    (parser location note) 
    (number?) 
    (define notes 
     '((0 . "c4") 
     (1 . "d4") 
     (2 . "e4") 
     (3 . "f4") 
     (4 . "g4") 
     (5 . "a4") 
     (6 . "b4"))) 
    #{ #(cdr (assoc (modulo note 7) notes)) #} 
) 

這不起作用,因爲error: music function cannot generate f4。但是,以下,但是,工作:

generateF = 
#(define-music-function 
    (parser location) 
    #{ f4 #} 
) 

任何想法,爲什麼這不工作?

我已經試過將" "換成{ }#{ #}無濟於事。

回答

0

我設法得到的東西與

generateNote = 
    #(define-music-function 
    (parser location note duration) 
     (number? number?) 
     (define notes 
      '((0 . "c") 
      (1 . "d") 
      (2 . "e") 
      (3 . "f") 
      (4 . "g") 
      (5 . "a") 
      (6 . "b"))) 
     #{ 
      $(ly:parser-include-string 
       parser 
       (string-append 
       (cdr (assoc (modulo note 7) notes)) 
       (number->string duration) 
       ) 
      ) 
     #} 
     ) 

它至少工作下去。