Web MIDI とTeoria.JSを使用して、Web ベースの和音コントローラーを構築しようとしています。
teoria-chord-progression のおかげでスケールのコードを生成し、その MIDI コードを取得する方法を見つけました。今度は、同じコードの反転の MIDI ノートを取得したいと思います。
私がこれまでに行ったことは、最初の転回では 5 番目、2 番目の転回では 5 番目の元の MIDI ノートから 12 を減算することですが、もっと良い方法があると確信しています。
編集:ここで私が持っているコードは、反転されていない形式でコードのみを再生します:
'use strict';
const teoria = require('teoria');
const chordProgression = require('teoria-chord-progression');
const Combokeys = require("combokeys");
const document = global.document;
const cSharpHMinor = teoria.scale('c#', 'harmonicminor');
const chords = chordProgression(cSharpHMinor, [1, 2, 3, 4, 5, 6, 7], 3).chords;
const combokeys = new Combokeys(document.documentElement);
global.navigator.requestMIDIAccess()
.then((midiAccess) => {
return Array.from(midiAccess.outputs.values());
})
.then((midiOutputs)=> {
chords.forEach((chord, index) => {
buildPadForChord(index + 1, chord, midiOutputs);
});
});
function createPad(index, chordName, listener) {
let button = document.createElement('button');
button.setAttribute('type', 'button');
button.textContent = `${chordName} (${index})`;
button.addEventListener('click', listener);
let autorepeat = false;
combokeys.bind(index.toString(), () => {
if (!autorepeat) {
autorepeat = true;
listener();
}
}, 'keydown');
combokeys.bind(index.toString(), () => {
autorepeat = false;
}, 'keyup');
document.documentElement.appendChild(button);
}
function buildPadForChord(index, chord, midiOutputs) {
let listener = () => {
midiOutputs.forEach((midiOutput) => {
chord.notes().forEach((note)=> {
midiOutput.send([0x90, note.midi(), 127]);
midiOutput.send([0x80, note.midi(), 127], global.performance.now() + 1000.0);
});
});
};
createPad(index, chord.name, listener);
}