GithubHelp home page GithubHelp logo

imclab / webmidiapishim Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cwilso/webmidiapishim

0.0 1.0 0.0 421 KB

Polyfill using the Jazz NPAPI MIDI plugin to implement the Web MIDI API on Mac and Windows.

webmidiapishim's Introduction

Web MIDI API Polyfill

This JS library is a prototype polyfill and shim for the Web MIDI API (of which I am a co-author), using Jazz-Soft.net's Jazz-Plugin to enable MIDI support on Windows and OSX. You need to have at least version 1.2 of the Jazz-Plugin in order for this polyfill to work properly. This polyfill and the plugin should work on Chrome, Firefox, Safari, Opera and IE.

I'm currently using this polyfill to test usability of the API itself, but it's also useful to enable MIDI scenarios.

This polyfill now supports multiple simultaneous inputs and outputs, and sending and receiving long messages (sysem exclusive). It also properly dispatches events. Timestamps on send and receive should be properly implemented now, although of course timing will not be very precise on either.

Jazz doesn't expose the version number or manufacturer, so these are always null.

##Usage

  1. Copy the WebMIDIAPI.js file from /lib/ into your project.
  2. Add "<script src='lib/WebMIDIAPI.js'></script>" to your code.

You can use the Web MIDI API as captured in the specification - the polyfill will automatically check to see if the Web MIDI API is already implemented, and if not it will insert itself.

So, some sample usage:

var m = null;   // m = MIDIAccess object for you to make calls on
navigator.requestMIDIAccess().then( onsuccesscallback, onerrorcallback );

function onsuccesscallback( access ) { 
	m = access;

	// Things you can do with the MIDIAccess object:
    var inputs = m.inputs();   // inputs = array of MIDIPorts
    var outputs = m.outputs(); // outputs = array of MIDIPorts
    inputs[0].onmidimessage = myMIDIMessagehandler;	// onmidimessage( event ), event.data & event.receivedTime are populated
    var o = m.outputs()[0];           // grab first output device
    o.send( [ 0x90, 0x45, 0x7f ] );     // full velocity note on A4 on channel zero
    o.send( [ 0x80, 0x45, 0x7f ], window.performance.now() + 1000 );  // full velocity A4 note off in one second.
};

function onerrorcallback( err ) {
	console.log("uh-oh! Something went wrong!  Error code: " + err.code );
}

You can also take a look at index.html for a basic test, or multi.html for a multiple-simultaneous-input test. Better documentation later. :)

webmidiapishim's People

Contributors

cwilso avatar halfbyte avatar jaycliff-aov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.