Created
October 23, 2015 20:01
-
-
Save teamikl/f01d59e139dfff325a39 to your computer and use it in GitHub Desktop.
coloring chord notes plugin for MuseScore2
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
/** | |
* Coloring chord notes | |
* | |
* @author: tea <mikl.pudding at gmail dot com> | |
* @license: MIT | |
* | |
* | |
* 制限事項: 単一のリードシートのみを走査対象とします。 | |
* | |
* 複数トラックや、2段になったコード表記、2声以上のメロディ、装飾音には対応してません。 | |
* (@see Stuff/voice/element.graceNotes) | |
* | |
* 必要最小限の譜表でのみ実験しています。全てのデータ構造は把握しきれていないので、 | |
* 実際の譜表では、想定していない要素で意図しない動作になる可能性があります。 | |
* | |
* | |
* コード表記について検討課題 | |
* * 記号表記 ^ 0 o 等 (major, half-diminished, diminished) | |
* * 分数コードの bass/root | |
* * N.C. の扱い | |
* | |
* Harmonyオブジェクトについて | |
* * ルートのみの場合は .text プロパティは空 | |
* * 分数コードの分母は .baseTpc | |
* * USTの場合は? | |
* | |
* Noteオブジェクトについて | |
* * dotの考慮 | |
* | |
* | |
* https://musescore.org/en/handbook/plugins-0 | |
* https://musescore.org/en/developers-handbook/references/musescore-internal-score-representation | |
*/ | |
import QtQuick 2.0 | |
import MuseScore 1.0 | |
MuseScore { | |
version: "1.0" | |
description: "Coloring chord notes" | |
menuPath: "Plugins.Notes.ColorNotes" | |
// @see ./plugins/notenames.qml | |
property variant notenames: { | |
"-2": '', | |
"-1": 'Fbb', | |
0: 'Cbb', | |
1: 'Gbb', | |
2: 'Dbb', | |
3: 'Abb', | |
4: 'Ebb', | |
5: 'Bbb', | |
6: 'Fb', | |
7: 'Cb', | |
8: 'Gb', | |
9: 'Db', | |
10: 'Ab', | |
11: 'Eb', | |
12: 'Bb', | |
13: 'F', | |
14: 'C', | |
15: 'G', | |
16: 'D', | |
17: 'A', | |
18: 'E', | |
19: 'B', | |
20: 'F#', | |
21: 'C#', | |
22: 'G#', | |
23: 'D#', | |
24: 'A#', | |
25: 'E#', | |
26: 'B#', | |
27: 'F##', | |
28: 'C##', | |
29: 'G##', | |
30: 'D##', | |
31: 'A##', | |
32: 'E##', | |
33: 'B##', | |
} | |
property variant kindNames: { | |
"-1003": "M7", | |
"-1004": "7", | |
"-1005": "mi7", | |
"-1006": "mi11", | |
} | |
// NOTE: tonal pitch class で判定しているため | |
// circle of fifth 上での距離。例: sus4 = [0, -1, 1] | |
property variant kindNotes: { | |
"-1003": [0, 4, 1, 5], // ^7 | |
"-1004": [0, 4, 1, -2], // 7 | |
"-1005": [0, -3, 1, -2], // mi7 | |
"-1006": [0, -3, -1, -2, 2, -1], // mi11 | |
} | |
function forEach(elements, callback) { | |
for (var idx in elements) | |
callback(elements[idx], idx) | |
} | |
function dumpObject(obj) { | |
forEach(obj, function (value, key) { | |
console.log(key + ":" + value); | |
}); | |
} | |
function isChordTone(harmony, note) { | |
var v = (note.tpc - harmony.rootTpc) % 12 | |
return kindNotes[harmony.id].indexOf(v) != -1; | |
} | |
function testHarmony(harmony) { | |
// XXX: no harmony.text property after re-open | |
var root = notenames[harmony.rootTpc]; | |
var base = notenames[harmony.baseTpc]; | |
// console.log(root + " " + harmony.id) | |
// console.log(root + " " + kindNames[harmony.id]) | |
} | |
function colorNotes(harmony, element) { | |
if (element.type != Element.CHORD) | |
return; | |
forEach(element.notes, function(note){ | |
// console.log(note + " " + note.color); | |
if (isChordTone(harmony, note)) | |
note.color = "#ff0000"; | |
}); | |
} | |
onRun: { | |
// スコアが選択されていない場合、何もしないで実行を停止。 | |
if (typeof curScore === 'undefined') | |
return; | |
var TRACK = 0; // Zero for the first track | |
var measureNum = 1; // 現在の小節番号 | |
var curHarmony = null; // 現在のコード | |
// 各セグメントを走査 | |
for (var segment = curScore.firstSegment(); | |
segment != null; | |
segment = segment.next) { | |
/// Segment | |
// 小節の末尾(縦線) | |
if (segment.segmentType == Segment.EndBarLine) { | |
measureNum++; | |
console.log("----") | |
continue | |
} | |
// Chord, Rest 以外は、何もせず読み飛ばす | |
if (segment.segmentType != Segment.ChordRest) { | |
continue | |
} | |
/// Annotation | |
// harmony (コード表記) | |
forEach(segment.annotations, function(harmony){ | |
if (typeof harmony === 'undefined') | |
return; | |
if (harmony.type == Element.HARMONY) { | |
curHarmony = harmony; | |
testHarmony(harmony); | |
} | |
}); | |
/// Element | |
var element = segment.elementAt(TRACK); | |
switch (element.type) { | |
case Element.REST: // 休符 | |
// console.log(element) | |
break; | |
case Element.CHORD: // 音符 | |
// console.log(element) | |
colorNotes(curHarmony, element) | |
break; | |
default: | |
break; | |
} | |
} | |
Qt.quit(); | |
} | |
} |
制限事項
(2015/10/24現在) 対応しているコードは、"^7", "7", "mi7", "mi11" の4種類のみ。
コード表記は、ID で管理されている為、"m7", "mi7", "-7" はそれぞれ異なるIDです。
対応するコード表記を増やすには、harmony.id を調べて、kindNotesテーブルに追記する。
コードの表記とIDは、./styles/*.xml ファイル群を参照。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
閉じ括弧の位置は、プラグイン・クリエーターで生成されるデフォルトのコードの作法で揃えました。