Giter Site home page Giter Site logo

web-midi-test's Introduction

web-midi-test

npm npm build Coverage Status Try web-midi-test on RunKit

Fake Web MIDI API for testing Web MIDI applications

See also: Web MIDI API

See also: midi-test, jazz-midi-headless, test-midi-files

Install: npm install web-midi-test --save-dev

Usage

Node.js

var WMT = require('web-midi-test');
var navigator = { requestMIDIAccess: WMT.requestMIDIAccess };
var performance = { now: WMT.now }; // if required...
// ...

HTML

<script src="node_modules/web-midi-test/wmt.js"></script>
// this will add an object named WMT into the global scope
// ...
if (typeof navigator.requestMIDIAccess == 'undefined') {
  navigator.requestMIDIAccess = WMT.requestMIDIAccess;
}
// ...

TypeScript

tsc myscript.ts --lib es2015,dom

import * as WMT from 'web-midi-test';
// ...

With JSDOM

API

MIDI access

function onSuccess() { console.log('Success!'); }
function onFail() { console.log('Fail!'); }

// normal scenario
WMT.requestMIDIAccess().then(onSuccess, onFail); // Success!
WMT.requestMIDIAccess({ sysex: true }).then(onSuccess, onFail); // Success!

// no sysex permission scenario
WMT.sysex = false;
WMT.requestMIDIAccess().then(onSuccess, onFail); // Success!
WMT.requestMIDIAccess({ sysex: true }).then(onSuccess, onFail); // Fail!

// no midi permission scenario
WMT.midi = false;
WMT.requestMIDIAccess().then(onSuccess, onFail); // Fail!

MIDI Source (Virtual MIDI-In)

var port = new WMT.MidiSrc('VIRTUAL MIDI-In');
port.connect();
port.emit([0x90, 0x40, 0x7f]);
//...
port.busy = true;  // "another application" captured the port
// Web MIDI can see the port, but can not connect to it
port.busy = false; // "another application" released the port
//...
port.disconnect();

MIDI Destination (Virtual MIDI-Out)

var port = new WMT.MidiDst('VIRTUAL MIDI-Out');
port.receive = function(msg) { console.log('received:', msg); };
port.connect();
//...
port.busy = true;  // "another application" captured the port
// Web MIDI can see the port, but can not connect to it
port.busy = false; // "another application" released the port
//...
port.disconnect();

web-midi-test's People

Contributors

jazz-soft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

jusdel37

web-midi-test's Issues

feat: support `access.addEventListener('statechange')`

Right now only setting the onstatechange property is supported

const access = await navigator.requestMIDIAccess()
access.onstatechange = () => {}

But the Web Midi API also allows using an event listener:

const access = await navigator.requestMIDIAccess()
access.addEventListener('statechange', () => {})

This can be useful if you want to have multiple listeners for the statechange event.

Timestamp in `MIDIOutput.send(data, timestamp)` not implemented correctly

It looks like the timestamp argument of MIDIOutput.send(data, timestamp) is not implemented correctly. According to the spec, this should be a delay value and not an absolute timestamp. The argument should probably be called delay and not timestamp. It looks like it's implemented this way in both the test/mocha.js file and the MIDIOutput.send() method in wmt.js.

So if we wanted an event to happen 100ms from now, we would send

midiOutput.send([1,2,3], 100)

not

midiOutput.send([1,2,3], performance.now() + 100)

So... I believe that line 389 in wmt.js:

      if (t > _now()) for (i = 0; i < data.length; i++) _insert([t, this, port, data[i]]);

becomes more like

      if (t > 0) for (i = 0; i < data.length; i++) _insert([_now() + t, this, port, data[i]]);

(untested)

And the tests will probably need to be updated too.

midi is read-only (typescript error?)

when i try to use the following i get an error in my ide midi is read-only.

WMT.midi = false;

I dont know why this is happening, but the code seems to complete anyway because midi is failing as expected. so I assume this is a problem with the typescript definition.

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.