Ignore:
Timestamp:
2015-05-30T11:10:57+12:00 (9 years ago)
Author:
davidb
Message:

This version has patch that allows it to work with latest (May 2015) version of Chrome

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-sites-dev/respooled/collect/popup-video-respooled/js/midi/plugin.webmidi.js

    r29863 r29939  
    11/*
    2     ----------------------------------------------------------------------
    3     Web MIDI API - Native Soundbanks
    4     ----------------------------------------------------------------------
    5     http://webaudio.github.io/web-midi-api/
    6     ----------------------------------------------------------------------
     2  ----------------------------------------------------------------------
     3  Web MIDI API - Native Soundbanks
     4  ----------------------------------------------------------------------
     5  http://webaudio.github.io/web-midi-api/
     6  ----------------------------------------------------------------------
    77*/
    88
    99(function(root) { 'use strict';
    1010
    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     };
     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              };
    1818
    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              };
    2222
    23     midi.setVolume = function(channel, volume, delay) { // set channel volume
    24         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              };
    2626
    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              };
    3030
    31     midi.pitchBend = function(channel, program, delay) { // pitch bend
    32         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              };
    3434
    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              };
    3838
    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              };
    4242
    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              };
    4949
    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              };
    5656
    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              };
    6363
    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              };
    8292
    8393})(MIDI);
Note: See TracChangeset for help on using the changeset viewer.