[英]Lilypond: How can I map numbers to notes with Scheme
我正在嘗試創建一個函數,例如, \\generateNote #3 #4
將生成一個f4-這將有助於編寫函數以快速生成音階等。
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 #}
)
有什么想法為什么不起作用?
我已經嘗試過將" "
與{ }
和#{ #}
交換無濟於事。
我設法解決了一些問題
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)
)
)
#}
)
至少有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.