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

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

Extending LilyPond: 1.3.4 Adding articulation to notes (example)

 

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

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

命令格式:\addStaccato { 音列 }

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

先贴效果,再贴代码

 

效果图:

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

 

 

 

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

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

#(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 }

 

上一篇:自动处理单个和弦、一般模式、chordmode下的分解和弦


下一篇:Java程序猿必学第二十三篇——网络编程(聊天室)与反射