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(); | |
} | |
} |
分数コード/UST等が課題
root以外に base 基準の度数も取れるようにする
表示方法は後で検討。(オプションで選択・両方表示)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
インストール方法
使用上の注意
既存の譜表の、一番上の楽器のみを対象とします。(リードシートを想定)
歌詞のデータを上書きしてしまうため、元データがある場合はバックアップを取るなどしてください。
スコアを閉じる前なら、元に戻すでプラグインの実行結果を戻すことはできます。
※ 和音は想定していません。単音のみ。(現在作業中)
注釈
ノートのピッチは、TPC(Tonal Pitch Class)で管理されていて、
5度圏の順序に沿って番号が割り振られています。
これは、Gb (b5) と F# (#4) は異なるデータ値ですが、
12 の剰余を求めると同じ値になる仕組みです。
5線上のフラット・シャープを判断してインターバルを決定しているため、
Abm 上の B 音が #9 とされます。 Cb が b3