update loadPlugin to support multiple instruments in WebAudioAPI and AudioTag
This commit is contained in:
parent
50eb9cb6eb
commit
d53fe90663
1 changed files with 143 additions and 78 deletions
|
@ -1,17 +1,17 @@
|
||||||
/*
|
/*
|
||||||
-------------------------------------
|
--------------------------------------------
|
||||||
MIDI.Plugin : 0.3 : 11/20/2012
|
MIDI.Plugin : 0.3 : 11/20/2012
|
||||||
-------------------------------------
|
--------------------------------------------
|
||||||
https://github.com/mudx/MIDI.js
|
https://github.com/mudx/MIDI.js
|
||||||
-------------------------------------
|
--------------------------------------------
|
||||||
MIDI.WebAudioAPI
|
MIDI.WebAudioAPI
|
||||||
MIDI.Flash
|
MIDI.Flash
|
||||||
MIDI.HTML5
|
MIDI.HTML5
|
||||||
MIDI.instruments
|
MIDI.GeneralMIDI
|
||||||
MIDI.channels
|
MIDI.channels
|
||||||
MIDI.keyToNote
|
MIDI.keyToNote
|
||||||
MIDI.noteToKey
|
MIDI.noteToKey
|
||||||
-------------------------------------
|
--------------------------------------------
|
||||||
setMute?
|
setMute?
|
||||||
getInstruments?
|
getInstruments?
|
||||||
|
|
||||||
|
@ -23,9 +23,11 @@ if (typeof (MIDI.Plugin) === "undefined") MIDI.Plugin = {};
|
||||||
(function() { "use strict";
|
(function() { "use strict";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
--------------------------------------------
|
||||||
Web Audio API - OGG or MPEG Soundbank
|
Web Audio API - OGG or MPEG Soundbank
|
||||||
--------------------------------------
|
--------------------------------------------
|
||||||
https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html
|
https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html
|
||||||
|
--------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (typeof (MIDI.WebAudioAPI) === "undefined") MIDI.WebAudioAPI = {};
|
if (typeof (MIDI.WebAudioAPI) === "undefined") MIDI.WebAudioAPI = {};
|
||||||
|
@ -38,14 +40,17 @@ if (window.AudioContext || window.webkitAudioContext) (function () {
|
||||||
var sources = {};
|
var sources = {};
|
||||||
var masterVolume = 1;
|
var masterVolume = 1;
|
||||||
var audioBuffers = {};
|
var audioBuffers = {};
|
||||||
var audioLoader = function (urlList, index, bufferList, oncomplete) {
|
var audioLoader = function (instrument, urlList, index, bufferList, callback) {
|
||||||
|
var synth = MIDI.GeneralMIDI.byName[instrument];
|
||||||
|
var instrumentId = synth.number;
|
||||||
var url = urlList[index];
|
var url = urlList[index];
|
||||||
var base64 = MIDI.Soundfont[url].split(",")[1];
|
var base64 = MIDI.Soundfont[instrument][url].split(",")[1];
|
||||||
var buffer = Base64Binary.decodeArrayBuffer(base64);
|
var buffer = Base64Binary.decodeArrayBuffer(base64);
|
||||||
ctx.decodeAudioData(buffer, function (buffer) {
|
ctx.decodeAudioData(buffer, function (buffer) {
|
||||||
var msg = url; while(msg.length < 3) msg += " ";
|
var msg = url;
|
||||||
if (typeof(loader) !== "undefined") {
|
while (msg.length < 3) msg += " ";
|
||||||
loader.message("Downloading: 100%<br>Processing: "+(index/87 * 100 >> 0)+"%<br>" + msg);
|
if (typeof (loader) !== "undefined") {
|
||||||
|
loader.message(synth.instrument + "<br>Processing: " + (index / 87 * 100 >> 0) + "%<br>" + msg);
|
||||||
}
|
}
|
||||||
buffer.id = url;
|
buffer.id = url;
|
||||||
bufferList[index] = buffer;
|
bufferList[index] = buffer;
|
||||||
|
@ -53,10 +58,11 @@ if (window.AudioContext || window.webkitAudioContext) (function () {
|
||||||
if (bufferList.length === urlList.length) {
|
if (bufferList.length === urlList.length) {
|
||||||
while (bufferList.length) {
|
while (bufferList.length) {
|
||||||
buffer = bufferList.pop();
|
buffer = bufferList.pop();
|
||||||
|
if (!buffer) continue;
|
||||||
var nodeId = MIDI.keyToNote[buffer.id];
|
var nodeId = MIDI.keyToNote[buffer.id];
|
||||||
audioBuffers[nodeId] = buffer;
|
audioBuffers[instrumentId + "" + nodeId] = buffer;
|
||||||
}
|
}
|
||||||
oncomplete();
|
callback(instrument);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -65,19 +71,21 @@ if (window.AudioContext || window.webkitAudioContext) (function () {
|
||||||
masterVolume = n;
|
masterVolume = n;
|
||||||
};
|
};
|
||||||
|
|
||||||
root.programChange = function (instrument) {
|
root.programChange = function (channel, program) {
|
||||||
|
MIDI.channels[channel].instrument = program;
|
||||||
};
|
};
|
||||||
|
|
||||||
root.noteOn = function (channel, note, velocity, delay) {
|
root.noteOn = function (channel, note, velocity, delay) {
|
||||||
/// check whether the note exists
|
/// check whether the note exists
|
||||||
if (!audioBuffers[note]) return;
|
if (!MIDI.channels[channel]) return;
|
||||||
|
var instrument = MIDI.channels[channel].instrument;
|
||||||
|
if (!audioBuffers[instrument + "" + note]) return;
|
||||||
/// convert relative delay to absolute delay
|
/// convert relative delay to absolute delay
|
||||||
if (delay < ctx.currentTime) delay += ctx.currentTime;
|
if (delay < ctx.currentTime) delay += ctx.currentTime;
|
||||||
/// crate audio buffer
|
/// crate audio buffer
|
||||||
var source = ctx.createBufferSource();
|
var source = ctx.createBufferSource();
|
||||||
sources[channel + "" + note] = source;
|
sources[channel + "" + note] = source;
|
||||||
source.buffer = audioBuffers[note];
|
source.buffer = audioBuffers[instrument + "" + note];
|
||||||
source.connect(ctx.destination);
|
source.connect(ctx.destination);
|
||||||
///
|
///
|
||||||
var gainNode = ctx.createGainNode();
|
var gainNode = ctx.createGainNode();
|
||||||
|
@ -92,7 +100,7 @@ if (window.AudioContext || window.webkitAudioContext) (function () {
|
||||||
|
|
||||||
root.chordOn = function (channel, chord, velocity, delay) {
|
root.chordOn = function (channel, chord, velocity, delay) {
|
||||||
var ret = {}, note;
|
var ret = {}, note;
|
||||||
for (var n = 0, length = chord.length; n < length; n ++) {
|
for (var n = 0, length = chord.length; n < length; n++) {
|
||||||
ret[note = chord[n]] = root.noteOn(channel, note, velocity, delay);
|
ret[note = chord[n]] = root.noteOn(channel, note, velocity, delay);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -102,7 +110,7 @@ if (window.AudioContext || window.webkitAudioContext) (function () {
|
||||||
// POSSIBLE FIX: fade out smoothly using gain and ramping to value
|
// POSSIBLE FIX: fade out smoothly using gain and ramping to value
|
||||||
root.noteOff = function (channel, note, delay) {
|
root.noteOff = function (channel, note, delay) {
|
||||||
delay = delay || 0;
|
delay = delay || 0;
|
||||||
var source = sources[channel+""+note];
|
var source = sources[channel + "" + note];
|
||||||
if (!source) return;
|
if (!source) return;
|
||||||
source.gain.linearRampToValueAtTime(1, delay);
|
source.gain.linearRampToValueAtTime(1, delay);
|
||||||
source.gain.linearRampToValueAtTime(0, delay + 0.75);
|
source.gain.linearRampToValueAtTime(0, delay + 0.75);
|
||||||
|
@ -111,11 +119,14 @@ if (window.AudioContext || window.webkitAudioContext) (function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
root.chordOff = function (channel, chord, delay) {
|
root.chordOff = function (channel, chord, delay) {
|
||||||
|
var ret = {}, note;
|
||||||
|
for (var n = 0, length = chord.length; n < length; n++) {
|
||||||
|
ret[note = chord[n]] = root.noteOff(channel, note, delay);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
root.connect = function (callback) {
|
root.connect = function (callback) {
|
||||||
|
|
||||||
MIDI.lang = 'WebAudioAPI';
|
MIDI.lang = 'WebAudioAPI';
|
||||||
MIDI.setVolume = root.setVolume;
|
MIDI.setVolume = root.setVolume;
|
||||||
MIDI.programChange = root.programChange;
|
MIDI.programChange = root.programChange;
|
||||||
|
@ -130,47 +141,57 @@ if (window.AudioContext || window.webkitAudioContext) (function () {
|
||||||
var keyToNote = MIDI.keyToNote;
|
var keyToNote = MIDI.keyToNote;
|
||||||
for (var key in keyToNote) urlList.push(key);
|
for (var key in keyToNote) urlList.push(key);
|
||||||
var bufferList = [];
|
var bufferList = [];
|
||||||
for (var i = 0; i < urlList.length; i++) {
|
var pending = {};
|
||||||
audioLoader(urlList, i, bufferList, callback);
|
var oncomplete = function(instrument) {
|
||||||
|
delete pending[instrument];
|
||||||
|
for (var key in pending) break;
|
||||||
|
if (!key) callback();
|
||||||
|
};
|
||||||
|
for (var instrument in MIDI.Soundfont) {
|
||||||
|
pending[instrument] = true;
|
||||||
|
for (var i = 0; i < urlList.length; i++) {
|
||||||
|
audioLoader(instrument, urlList, i, bufferList, oncomplete);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
HTML5 <audio> - OGG or MPEG Soundbank
|
AudioTag <audio> - OGG or MPEG Soundbank
|
||||||
--------------------------------------
|
--------------------------------------
|
||||||
http://dev.w3.org/html5/spec/Overview.html#the-audio-element
|
http://dev.w3.org/html5/spec/Overview.html#the-audio-element
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (window.Audio) (function () {
|
if (window.Audio) (function () {
|
||||||
|
|
||||||
var root = MIDI.HTML5 = {};
|
var root = MIDI.AudioTag = {};
|
||||||
var note2id = {};
|
var note2id = {};
|
||||||
var volume = 1; // floating point
|
var volume = 1; // floating point
|
||||||
var channel_nid = -1; // current channel
|
var channel_nid = -1; // current channel
|
||||||
var channel_map = {}; // map to current playing <audio> elements
|
|
||||||
var channels = []; // the audio channels
|
var channels = []; // the audio channels
|
||||||
var notes = {}; // the piano keys
|
var notes = {}; // the piano keys
|
||||||
for (var nid = 0; nid < 12; nid++) {
|
for (var nid = 0; nid < 12; nid++) {
|
||||||
channels[nid] = new Audio();
|
channels[nid] = new Audio();
|
||||||
}
|
}
|
||||||
|
|
||||||
var playChannel = function (id) {
|
var playChannel = function (channel, note) {
|
||||||
var note = notes[id];
|
if (!MIDI.channels[channel]) return;
|
||||||
|
var instrument = MIDI.channels[channel].instrument;
|
||||||
|
var id = MIDI.GeneralMIDI.byId[instrument].id;
|
||||||
|
var note = notes[note];
|
||||||
if (!note) return;
|
if (!note) return;
|
||||||
var nid = (channel_nid + 1) % channels.length;
|
var nid = (channel_nid + 1) % channels.length;
|
||||||
var time = (new Date()).getTime();
|
var time = (new Date()).getTime();
|
||||||
var audio = channels[nid];
|
var audio = channels[nid];
|
||||||
channel_map[note.id] = audio;
|
audio.src = MIDI.Soundfont[id][note.id];
|
||||||
audio.src = MIDI.Soundfont[note.id];
|
|
||||||
audio.volume = volume;
|
audio.volume = volume;
|
||||||
audio.play();
|
audio.play();
|
||||||
channel_nid = nid;
|
channel_nid = nid;
|
||||||
};
|
};
|
||||||
|
|
||||||
root.programChange = function () {
|
root.programChange = function (channel, program) {
|
||||||
|
MIDI.channels[channel].instrument = program;
|
||||||
};
|
};
|
||||||
|
|
||||||
root.setVolume = function (n) {
|
root.setVolume = function (n) {
|
||||||
|
@ -181,29 +202,32 @@ if (window.Audio) (function () {
|
||||||
var id = note2id[note];
|
var id = note2id[note];
|
||||||
if (!notes[id]) return;
|
if (!notes[id]) return;
|
||||||
if (delay) {
|
if (delay) {
|
||||||
var interval = window.setTimeout(function() {
|
var interval = window.setTimeout(function () {
|
||||||
playChannel(id);
|
playChannel(channel, id);
|
||||||
}, delay * 1000);
|
}, delay * 1000);
|
||||||
return interval;
|
return interval;
|
||||||
} else {
|
} else {
|
||||||
playChannel(id);
|
playChannel(channel, id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
root.noteOff = function (channel, note, delay) {
|
root.noteOff = function (channel, note, delay) {
|
||||||
// var nid = note2id[note];
|
|
||||||
// channel_map[nid].pause();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
root.chordOn = function (channel, chord, velocity, delay) {
|
root.chordOn = function (channel, chord, velocity, delay) {
|
||||||
for (var key in chord) {
|
for (var key in chord) {
|
||||||
var n = chord[key];
|
var n = chord[key];
|
||||||
var id = note2id[n];
|
var id = note2id[n];
|
||||||
if (!notes[id]) continue;
|
if (!notes[id]) continue;
|
||||||
playChannel(id);
|
playChannel(channel, id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
root.chordOff = function (channel, chord, delay) {
|
root.chordOff = function (channel, chord, delay) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
root.stopAllNotes = function () {
|
root.stopAllNotes = function () {
|
||||||
for (var nid = 0, length = channels.length; nid < length; nid++) {
|
for (var nid = 0, length = channels.length; nid < length; nid++) {
|
||||||
channels[nid].pause();
|
channels[nid].pause();
|
||||||
|
@ -217,24 +241,24 @@ if (window.Audio) (function () {
|
||||||
id: key
|
id: key
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MIDI.lang = 'HTML5';
|
MIDI.lang = 'AudioTag';
|
||||||
MIDI.setVolume = root.setVolume;
|
MIDI.setVolume = root.setVolume;
|
||||||
MIDI.programChange = root.programChange;
|
MIDI.programChange = root.programChange;
|
||||||
MIDI.noteOn = root.noteOn;
|
MIDI.noteOn = root.noteOn;
|
||||||
MIDI.noteOff = root.noteOff;
|
MIDI.noteOff = root.noteOff;
|
||||||
MIDI.chordOn = root.chordOn;
|
MIDI.chordOn = root.chordOn;
|
||||||
MIDI.chordOff = root.chordOff;
|
MIDI.chordOff = root.chordOff;
|
||||||
//
|
///
|
||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
//
|
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
--------------------------------------------
|
||||||
Flash - MP3 Soundbank
|
Flash - MP3 Soundbank
|
||||||
----------------------
|
--------------------------------------------
|
||||||
http://www.schillmania.com/projects/soundmanager2/
|
http://www.schillmania.com/projects/soundmanager2/
|
||||||
|
--------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
|
@ -242,42 +266,56 @@ if (window.Audio) (function () {
|
||||||
var root = MIDI.Flash = {};
|
var root = MIDI.Flash = {};
|
||||||
var noteReverse = {};
|
var noteReverse = {};
|
||||||
var notes = {};
|
var notes = {};
|
||||||
root.programChange = function () {
|
|
||||||
|
|
||||||
|
root.programChange = function (channel, program) {
|
||||||
|
MIDI.channels[channel].instrument = program;
|
||||||
};
|
};
|
||||||
|
|
||||||
root.setVolume = function (channel, note) {
|
root.setVolume = function (channel, note) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
root.noteOn = function (channel, note, velocity, delay) {
|
root.noteOn = function (channel, note, velocity, delay) {
|
||||||
var id = noteReverse[note];
|
if (!MIDI.channels[channel]) return;
|
||||||
if (!notes[id]) return;
|
var instrument = MIDI.channels[channel].instrument;
|
||||||
|
var id = MIDI.GeneralMIDI.byId[instrument].number;
|
||||||
|
note = id + "" + noteReverse[note];
|
||||||
|
if (!notes[note]) return;
|
||||||
if (delay) {
|
if (delay) {
|
||||||
var interval = window.setTimeout(function() {
|
var interval = window.setTimeout(function() {
|
||||||
notes[id].play({ volume: velocity * 2 });
|
notes[note].play({ volume: velocity * 2 });
|
||||||
}, delay * 1000);
|
}, delay * 1000);
|
||||||
return interval;
|
return interval;
|
||||||
} else {
|
} else {
|
||||||
notes[id].play({ volume: velocity * 2 });
|
notes[note].play({ volume: velocity * 2 });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
root.noteOff = function (channel, note, delay) {
|
root.noteOff = function (channel, note, delay) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
root.chordOn = function (channel, chord, velocity, delay) {
|
root.chordOn = function (channel, chord, velocity, delay) {
|
||||||
|
if (!MIDI.channels[channel]) return;
|
||||||
|
var instrument = MIDI.channels[channel].instrument;
|
||||||
|
var id = MIDI.GeneralMIDI.byId[instrument].number;
|
||||||
for (var key in chord) {
|
for (var key in chord) {
|
||||||
var n = chord[key];
|
var n = chord[key];
|
||||||
var id = noteReverse[n];
|
var note = id + "" + noteReverse[n];
|
||||||
if (notes[id]) {
|
if (notes[note]) {
|
||||||
notes[id].play({ volume: velocity * 2 });
|
notes[note].play({ volume: velocity * 2 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
root.chordOff = function (channel, chord, delay) {
|
root.chordOff = function (channel, chord, delay) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
root.stopAllNotes = function () {
|
root.stopAllNotes = function () {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
root.connect = function (callback) {
|
root.connect = function (callback) {
|
||||||
soundManager.flashVersion = 9;
|
soundManager.flashVersion = 9;
|
||||||
soundManager.useHTML5Audio = true;
|
soundManager.useHTML5Audio = true;
|
||||||
|
@ -287,22 +325,30 @@ if (window.Audio) (function () {
|
||||||
soundManager.flashPollingInterval = 1;
|
soundManager.flashPollingInterval = 1;
|
||||||
soundManager.debugMode = false;
|
soundManager.debugMode = false;
|
||||||
soundManager.onload = function () {
|
soundManager.onload = function () {
|
||||||
var loaded = [];
|
var createBuffer = function(instrument, id, onload) {
|
||||||
var onload = function () {
|
var synth = MIDI.GeneralMIDI.byName[instrument];
|
||||||
loaded.push(this.sID);
|
var instrumentId = synth.number;
|
||||||
if (typeof (loader) === "undefined") return;
|
notes[instrumentId+""+id] = soundManager.createSound({
|
||||||
loader.message("Processing: " + this.sID);
|
|
||||||
};
|
|
||||||
for (var i = 0; i < 88; i++) {
|
|
||||||
var id = noteReverse[i + 21];
|
|
||||||
notes[id] = soundManager.createSound({
|
|
||||||
id: id,
|
id: id,
|
||||||
url: './soundfont/mp3/' + id + '.mp3',
|
url: "./soundfont/"+instrument+"-mp3/" + id + ".mp3",
|
||||||
multiShot: true,
|
multiShot: true,
|
||||||
autoLoad: true,
|
autoLoad: true,
|
||||||
onload: onload
|
onload: onload
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
for (var instrument in MIDI.Soundfont) {
|
||||||
|
var loaded = [];
|
||||||
|
var onload = function () {
|
||||||
|
loaded.push(this.sID);
|
||||||
|
if (typeof (loader) === "undefined") return;
|
||||||
|
loader.message("Processing: " + this.sID);
|
||||||
|
};
|
||||||
|
for (var i = 0; i < 88; i++) {
|
||||||
|
var id = noteReverse[i + 21];
|
||||||
|
createBuffer(instrument, id, onload);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
///
|
||||||
MIDI.lang = 'Flash';
|
MIDI.lang = 'Flash';
|
||||||
MIDI.setVolume = root.setVolume;
|
MIDI.setVolume = root.setVolume;
|
||||||
MIDI.programChange = root.programChange;
|
MIDI.programChange = root.programChange;
|
||||||
|
@ -327,10 +373,12 @@ if (window.Audio) (function () {
|
||||||
})();
|
})();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
--------------------------------------------
|
||||||
Java - Native Soundbank
|
Java - Native Soundbank
|
||||||
----------------------------
|
--------------------------------------------
|
||||||
https://github.com/abudaan/midibridge-js
|
https://github.com/abudaan/midibridge-js
|
||||||
http://java.sun.com/products/java-media/sound/soundbanks.html
|
http://java.sun.com/products/java-media/sound/soundbanks.html
|
||||||
|
--------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
|
@ -350,13 +398,17 @@ if (window.Audio) (function () {
|
||||||
iframe.height = 1;
|
iframe.height = 1;
|
||||||
document.body.appendChild(iframe);
|
document.body.appendChild(iframe);
|
||||||
};
|
};
|
||||||
|
|
||||||
root.confirm = function (plugin) {
|
root.confirm = function (plugin) {
|
||||||
MIDI.programChange = function (program) {
|
|
||||||
plugin.sendMidiEvent(0xC0, 0, program, 0);
|
MIDI.programChange = function (channel, program) {
|
||||||
|
plugin.sendMidiEvent(0xC0, channel, program, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
MIDI.setVolume = function (n) {
|
MIDI.setVolume = function (n) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MIDI.noteOn = function (channel, note, velocity, delay) {
|
MIDI.noteOn = function (channel, note, velocity, delay) {
|
||||||
if (delay) {
|
if (delay) {
|
||||||
var interval = window.setTimeout(function() {
|
var interval = window.setTimeout(function() {
|
||||||
|
@ -367,6 +419,7 @@ if (window.Audio) (function () {
|
||||||
plugin.sendMidiEvent(0x90, channel, note, velocity);
|
plugin.sendMidiEvent(0x90, channel, note, velocity);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MIDI.noteOff = function (channel, note, delay) {
|
MIDI.noteOff = function (channel, note, delay) {
|
||||||
if (delay) {
|
if (delay) {
|
||||||
var interval = window.setTimeout(function() {
|
var interval = window.setTimeout(function() {
|
||||||
|
@ -377,25 +430,29 @@ if (window.Audio) (function () {
|
||||||
plugin.sendMidiEvent(0x80, channel, note, 0);
|
plugin.sendMidiEvent(0x80, channel, note, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MIDI.chordOn = function (channel, chord, velocity, delay) {
|
MIDI.chordOn = function (channel, chord, velocity, delay) {
|
||||||
for (var key in chord) {
|
for (var key in chord) {
|
||||||
var n = chord[key];
|
var n = chord[key];
|
||||||
plugin.sendMidiEvent(0x90, channel, n, 100);
|
plugin.sendMidiEvent(0x90, channel, n, 100);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MIDI.chordOff = function (channel, chord, delay) {
|
MIDI.chordOff = function (channel, chord, delay) {
|
||||||
for (var key in chord) {
|
for (var key in chord) {
|
||||||
var n = chord[key];
|
var n = chord[key];
|
||||||
plugin.sendMidiEvent(0x80, channel, n, 100);
|
plugin.sendMidiEvent(0x80, channel, n, 100);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MIDI.stopAllNotes = function () {
|
MIDI.stopAllNotes = function () {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MIDI.getInstruments = function() {
|
MIDI.getInstruments = function() {
|
||||||
return [];
|
return [];
|
||||||
};
|
};
|
||||||
///
|
|
||||||
if (plugin.ready) {
|
if (plugin.ready) {
|
||||||
MIDI.lang = "Java";
|
MIDI.lang = "Java";
|
||||||
if (MIDI.Java.callback) {
|
if (MIDI.Java.callback) {
|
||||||
|
@ -412,8 +469,15 @@ if (window.Audio) (function () {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// instrument-tracker
|
// instrument-tracker
|
||||||
MIDI.instruments = (function (arr) {
|
MIDI.GeneralMIDI = (function (arr) {
|
||||||
var instruments = {};
|
var clean = function(v) {
|
||||||
|
return v.replace(/[^a-z0-9 ]/gi, "").replace(/[ ]/g, "_").toLowerCase();
|
||||||
|
};
|
||||||
|
var ret = {
|
||||||
|
byName: {},
|
||||||
|
byId: {},
|
||||||
|
byCategory: {}
|
||||||
|
};
|
||||||
for (var key in arr) {
|
for (var key in arr) {
|
||||||
var list = arr[key];
|
var list = arr[key];
|
||||||
for (var n = 0, length = list.length; n < length; n++) {
|
for (var n = 0, length = list.length; n < length; n++) {
|
||||||
|
@ -421,17 +485,17 @@ MIDI.instruments = (function (arr) {
|
||||||
if (!instrument) continue;
|
if (!instrument) continue;
|
||||||
var num = parseInt(instrument.substr(0, instrument.indexOf(" ")), 10);
|
var num = parseInt(instrument.substr(0, instrument.indexOf(" ")), 10);
|
||||||
instrument = instrument.replace(num + " ", "");
|
instrument = instrument.replace(num + " ", "");
|
||||||
instruments[--num] = {
|
ret.byId[--num] =
|
||||||
|
ret.byName[clean(instrument)] =
|
||||||
|
ret.byCategory[clean(key)] = {
|
||||||
|
id: clean(instrument),
|
||||||
instrument: instrument,
|
instrument: instrument,
|
||||||
category: key
|
|
||||||
};
|
|
||||||
instruments[instrument] = {
|
|
||||||
number: num,
|
number: num,
|
||||||
category: key
|
category: key
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return instruments;
|
return ret;
|
||||||
})({
|
})({
|
||||||
'Piano': ['1 Acoustic Grand Piano', '2 Bright Acoustic Piano', '3 Electric Grand Piano', '4 Honky-tonk Piano', '5 Electric Piano 1', '6 Electric Piano 2', '7 Harpsichord', '8 Clavinet'],
|
'Piano': ['1 Acoustic Grand Piano', '2 Bright Acoustic Piano', '3 Electric Grand Piano', '4 Honky-tonk Piano', '5 Electric Piano 1', '6 Electric Piano 2', '7 Harpsichord', '8 Clavinet'],
|
||||||
'Chromatic Percussion': ['9 Celesta', '10 Glockenspiel', '11 Music Box', '12 Vibraphone', '13 Marimba', '14 Xylophone', '15 Tubular Bells', '16 Dulcimer'],
|
'Chromatic Percussion': ['9 Celesta', '10 Glockenspiel', '11 Music Box', '12 Vibraphone', '13 Marimba', '14 Xylophone', '15 Tubular Bells', '16 Dulcimer'],
|
||||||
|
@ -467,6 +531,9 @@ MIDI.channels = (function () { // 0 - 15 channels
|
||||||
return channels;
|
return channels;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
//
|
||||||
|
MIDI.pianoKeyOffset = 21;
|
||||||
|
|
||||||
// note conversions
|
// note conversions
|
||||||
MIDI.keyToNote = {}; // C8 == 108
|
MIDI.keyToNote = {}; // C8 == 108
|
||||||
MIDI.noteToKey = {}; // 108 == C8
|
MIDI.noteToKey = {}; // 108 == C8
|
||||||
|
@ -483,5 +550,3 @@ MIDI.noteToKey = {}; // 108 == C8
|
||||||
})();
|
})();
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
MIDI.pianoKeyOffset = 21;
|
|
Loading…
Add table
Add a link
Reference in a new issue