用lilypond自带案例编命令:给一列音加Staccato

2021/12/12 6:19:42

本文主要是介绍用lilypond自带案例编命令:给一列音加Staccato,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

lilypond有一个教学,是如何设计一个命令为音符加accent的,具体可看:

Extending LilyPond: 1.3.4 Adding articulation to notes (example)

 

但是,这个命令只适合加单音,不适合加在一列音上,所以把它稍加改造,可以加到一串音上,这样就能节省很多打代码的时间

例子:给一列音加上断奏记号(staccato)

命令格式:\addStaccato { 音列 }

要命令生效,需要将下面命令区的内容全部复制。

先贴效果,再贴代码

 

效果图:

 

 

 

%%%%%%%%%%%%% 以下是命令区,要使用该命令请复制全部内容 %%%%%%%%%%%%%

%%%%%%%%%%%%% 基础指令区 %%%%%%

#(define (get-elements mymusic)
   (ly:music-property mymusic 'elements)
   )

#(define (get-sequential-music mymusic)
   (ly:music-deep-copy mymusic)
   )

%%%%%%%%%%%%% 根据官方文档改造得来 %%%%%%%%%%%%%%%%

addStaccatoSingle = 
#(define-music-function (note-event) (ly:music?)
  (set! (ly:music-property note-event 'articulations)
        (cons (make-music 'ArticulationEvent
                'articulation-type "staccato")
              (ly:music-property note-event 'articulations)))
  note-event)

%%%%%%%%%%%%% 把单音上的命令运用到音列上 %%%%%%%%%%%%

addStaccato=
#(define-music-function (mymusic) (ly:music?)
   (make-sequential-music
   (map addStaccatoSingle
         (get-elements(ly:music-deep-copy mymusic))
)))

%%%%%%%%%%%%%% 命令区结束,复制到此为止 %%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%% 下面是试验效果 %%%%%%%%%%%%%%%%%%

MyNote ={
  % 这是做实验用的音符
  c'4 d'
}

\markup {"这是原来的样子"}

{ \MyNote }

\markup {"这是加了命令的样子"}

{ \addStaccato \MyNote }

 



这篇关于用lilypond自带案例编命令:给一列音加Staccato的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程