Last active
October 24, 2015 16:45
-
-
Save teamikl/36ad887fa28e6cfc259c to your computer and use it in GitHub Desktop.
MuseScore2 plugin - Add note interval as lyrics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.0 | |
import MuseScore 1.0 | |
MuseScore { | |
menuPath: "Plugins.NoteInterval" | |
/** | |
* TPC (Tonal pitch class) | |
* ピッチは5度圏上での距離で比較する | |
*/ | |
property variant intervalNames: { | |
"-11": "bb6", | |
"-10": "bb3", | |
"-9": "bb7", | |
"-8": "b4", | |
"-7": "b1", | |
"-6": "b5", | |
"-5": "b2", | |
"-4": "b6", // ??? | |
"-3": "b3", | |
"-2": "b7", | |
"-1": "4", // 11 | |
0: "1", | |
1: "5", | |
2: "2", | |
3: "6", | |
4: "3", | |
5: "7", | |
6: "#11", // #11 | |
7: "#8", | |
8: "#5", // 13 | |
9: "#9", | |
10: "#6", | |
11: "#10", | |
} | |
function map(callback, xs) { | |
var dest = []; | |
for (var idx in xs) | |
dest.push(callback(xs[idx])); | |
return dest; | |
} | |
function forEach(obj, callback) { | |
for (var key in obj) { | |
callback(obj[key], key); | |
} | |
} | |
function getIntervalText(root, note) { | |
return intervalNames[note - root]; | |
} | |
// lyrics 要素を生成 | |
function newLyric(element) { | |
var lyric = newElement(Element.LYRICS); | |
element.add(lyric); | |
lyric.text = "*"; | |
return lyric; | |
} | |
onRun: { | |
// スコアが選択されていない場合、何もせず終了 | |
if (typeof curScore === 'undefined') | |
Qt.quit(); | |
// コードのルート音を覚えておく変数 | |
var rootTpc = null; | |
// 全てのセグメントを走査 | |
for (var segment = curScore.firstSegment(); | |
segment != null; | |
segment = segment.next) | |
{ | |
// 音符・休符以外は読み飛ばす | |
if (segment.segmentType != Segment.ChordRest) | |
continue; | |
// コード・シンボルからルート音の TPC を得る | |
forEach(segment.annotations, function(anon) { | |
if (anon.type == Element.HARMONY) { | |
rootTpc = anon.rootTpc; | |
} | |
}); | |
// コードが設定されてない場合、何もしない | |
if (rootTpc === null) | |
continue; | |
// 最初のトラック(track=0)のみ対象 | |
var element = segment.elementAt(0); | |
// 音符のピッチを調べ、ルートからの距離を歌詞へ追加 | |
if (element && element.type == Element.CHORD) { | |
// 歌詞要素を所得。既にある場合は上書き、そうでなければ新規生成。 | |
var lyric = element.lyrics[0] || newLyric(element); | |
// 各音のインターバルを調べる | |
var xs = map(function(note){ | |
return getIntervalText(rootTpc, note.tpc); | |
}, element.notes); | |
// 歌詞のテキストへ追加 | |
if (lyric) | |
lyric.text = xs.join(","); | |
} | |
} | |
Qt.quit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
分数コード/UST等が課題
root以外に base 基準の度数も取れるようにする
表示方法は後で検討。(オプションで選択・両方表示)