之前的分解和弦要针对不同的输入模式提供不同的命令,不实用
除此之外,如果和弦与和弦之间有插入类似于谱号切换的指令,命令也会报错。
最近研究了如何识别不同的模式,新开发的命令\ArpeggioChord可以对单个和弦、一般模式、和弦模式都做分解和弦,并且自动忽略掉临时谱号等信息
要能应用,就需要把命令区里的指令都复制过去
效果如图
\version "2.22.1" \language "english" abc= \chordmode { c4 \clef bass d } abccommon= { <c' e' g'>4 \clef bass <d' f' a'>4 } %%%%%% 命令区 %%%%% 基础指令,后面使用map的时候会用得上 #(define (get-elements mymusic) (ly:music-property mymusic 'elements) ) %%%%% 获取音乐序列 #(define (get-sequential-music m) (cond ;;第一种情况,如果是chordmode,此时m的'name属性为'UnrelativableMusic ((eq? (ly:music-property m 'name) 'UnrelativableMusic) (ly:music-property (ly:music-property m 'element) 'elements)) ;;第二种情况,如果一般模式,此时m的'name属性为'SequentialMusic ((eq? (ly:music-property m 'name) 'SequentialMusic) (ly:music-property m 'elements)) ) ) %%%%%% 获取和弦序列,只保留'EventChord的部分 #(define (getChord m) (cond ((null? m) '()) ((eq? (ly:music-property (car m) 'name) 'EventChord) (cons (car m) (getChord (cdr m)))) (else (getChord (cdr m))) ) ) #(display-scheme-music (getChord (ly:music-property (ly:music-property abc 'element) 'elements)) ) #(display-scheme-music (cond ((eq? (ly:music-property abc 'name) 'UnrelativableMusic) (getChord(ly:music-property (ly:music-property abc 'element) 'elements))) ) ) %%%%%%%%%% 开始处理 ArpeggioChord= #(define-music-function (mymusic) (ly:music?) (cond ((or (eq?(ly:music-property mymusic 'name) 'UnrelativableMusic) (eq?(ly:music-property mymusic 'name) 'SequentialMusic)) (make-sequential-music (apply append (map get-elements (getChord (get-sequential-music mymusic)))))) ((eq? (ly:music-property mymusic 'name) 'EventChord) (make-sequential-music (get-elements mymusic))) ) ) %%%%%%% 命令区结束 { \mark "和弦模式" \abc \ArpeggioChord \abc } { \mark "一般模式" \abccommon \ArpeggioChord \abccommon } { \mark "单个和弦" <c' e'> \ArpeggioChord <c' e'> }