2016-02-16 73 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) 
       ) 
      ) 
     #} 
     ) 

它至少工作下去。