Changeset 29939 for main/trunk
- Timestamp:
- 2015-05-30T11:10:57+12:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/model-sites-dev/respooled/collect/popup-video-respooled/js/midi/plugin.webmidi.js
r29863 r29939 1 1 /* 2 3 4 5 6 2 ---------------------------------------------------------------------- 3 Web MIDI API - Native Soundbanks 4 ---------------------------------------------------------------------- 5 http://webaudio.github.io/web-midi-api/ 6 ---------------------------------------------------------------------- 7 7 */ 8 8 9 9 (function(root) { 'use strict'; 10 10 11 var plugin = null;12 var output = null;13 var channels = [];14 var midi = root.WebMIDI = {api: 'webmidi'};15 midi.send = function(data, delay) { // set channel volume16 output.send(data, delay * 1000);17 };11 var plugin = null; 12 var output = null; 13 var channels = []; 14 var midi = root.WebMIDI = {api: 'webmidi'}; 15 midi.send = function(data, delay) { // set channel volume 16 output.send(data, delay * 1000); 17 }; 18 18 19 midi.setController = function(channel, type, value, delay) {20 output.send([channel, type, value], delay * 1000);21 };19 midi.setController = function(channel, type, value, delay) { 20 output.send([channel, type, value], delay * 1000); 21 }; 22 22 23 midi.setVolume = function(channel, volume, delay) { // set channel volume24 output.send([0xB0 + channel, 0x07, volume], delay * 1000);25 };23 midi.setVolume = function(channel, volume, delay) { // set channel volume 24 output.send([0xB0 + channel, 0x07, volume], delay * 1000); 25 }; 26 26 27 midi.programChange = function(channel, program, delay) { // change patch (instrument)28 output.send([0xC0 + channel, program], delay * 1000);29 };27 midi.programChange = function(channel, program, delay) { // change patch (instrument) 28 output.send([0xC0 + channel, program], delay * 1000); 29 }; 30 30 31 midi.pitchBend = function(channel, program, delay) { // pitch bend32 output.send([0xE0 + channel, program], delay * 1000);33 };31 midi.pitchBend = function(channel, program, delay) { // pitch bend 32 output.send([0xE0 + channel, program], delay * 1000); 33 }; 34 34 35 midi.noteOn = function(channel, note, velocity, delay) {36 output.send([0x90 + channel, note, velocity], delay * 1000);37 };35 midi.noteOn = function(channel, note, velocity, delay) { 36 output.send([0x90 + channel, note, velocity], delay * 1000); 37 }; 38 38 39 midi.noteOff = function(channel, note, delay) {40 output.send([0x80 + channel, note, 0], delay * 1000);41 };39 midi.noteOff = function(channel, note, delay) { 40 output.send([0x80 + channel, note, 0], delay * 1000); 41 }; 42 42 43 midi.chordOn = function(channel, chord, velocity, delay) {44 for (var n = 0; n < chord.length; n ++) {45 var note = chord[n];46 output.send([0x90 + channel, note, velocity], delay * 1000);47 }48 };43 midi.chordOn = function(channel, chord, velocity, delay) { 44 for (var n = 0; n < chord.length; n ++) { 45 var note = chord[n]; 46 output.send([0x90 + channel, note, velocity], delay * 1000); 47 } 48 }; 49 49 50 midi.chordOff = function(channel, chord, delay) {51 for (var n = 0; n < chord.length; n ++) {52 var note = chord[n];53 output.send([0x80 + channel, note, 0], delay * 1000);54 }55 };50 midi.chordOff = function(channel, chord, delay) { 51 for (var n = 0; n < chord.length; n ++) { 52 var note = chord[n]; 53 output.send([0x80 + channel, note, 0], delay * 1000); 54 } 55 }; 56 56 57 midi.stopAllNotes = function() {58 output.cancel();59 for (var channel = 0; channel < 16; channel ++) {60 output.send([0xB0 + channel, 0x7B, 0]);61 }62 };57 midi.stopAllNotes = function() { 58 output.cancel(); 59 for (var channel = 0; channel < 16; channel ++) { 60 output.send([0xB0 + channel, 0x7B, 0]); 61 } 62 }; 63 63 64 midi.connect = function(opts) { 65 root.setDefaultPlugin(midi); 66 /// 67 navigator.requestMIDIAccess().then(function(access) { 68 plugin = access; 69 output = plugin.outputs()[0]; 70 opts.onsuccess && opts.onsuccess(); 71 }, function(err) { // well at least we tried! 72 if (window.AudioContext) { // Chrome 73 opts.api = 'webaudio'; 74 } else if (window.Audio) { // Firefox 75 opts.api = 'audiotag'; 76 } else { // no support 77 return; 78 } 79 root.loadPlugin(opts); 80 }); 81 }; 64 midi.connect = function(opts) { 65 root.setDefaultPlugin(midi); 66 var errFunction = function(err) { // well at least we tried! 67 if (window.AudioContext) { // Chrome 68 opts.api = 'webaudio'; 69 } else if (window.Audio) { // Firefox 70 opts.api = 'audiotag'; 71 } else { // no support 72 return; 73 } 74 root.loadPlugin(opts); 75 }; 76 /// 77 navigator.requestMIDIAccess().then(function(access) { 78 plugin = access; 79 var pluginOutputs = plugin.outputs; 80 if (typeof pluginOutputs == 'function') { // Chrome pre-43 81 output = pluginOutputs()[0]; 82 } else { // Chrome post-43 83 output = pluginOutputs[0]; 84 } 85 if (output === undefined) { // nothing there... 86 errFunction(); 87 } else { 88 opts.onsuccess && opts.onsuccess(); 89 } 90 }, errFunction); 91 }; 82 92 83 93 })(MIDI);
Note:
See TracChangeset
for help on using the changeset viewer.