开发者

Interfacing a midi keyboard or other real-time midi input with javascript?

开发者 https://www.devze.com 2023-03-16 14:20 出处:网络
I want to create a simple visualization tool that would allow to represent my playing a midi keyboardon the screen. I play a relatively novel instrument type, called the harmonic table:

I want to create a simple visualization tool that would allow to represent my playing a midi keyboard on the screen. I play a relatively novel instrument type, called the harmonic table:

http://en.wikipedia.org/wiki/Harmonic_table_note_layout

http://www.soundonsound.com/newspix/image/axis49.jpg

And want to build tools to ease their use and to teach others how to use them.

However, I can't find a good way to get get midi into javascript environment (or, for that matter, Flash, or Java without a large helping of jiggery-pokery slightly beyond my reach, and the use of code from开发者_StackOverflow中文版 what look to be rather stale and abandoned open source projects. Neither language I am too enthused to work in for this project in any case).

Is there a suitable library or application that I have missed, that will enable me to do this?


While searching around for another solution (Flash based, using the functions of the Red5 Open source flash server - really ugly, but I'm desperate at this point) I found someone who had done exactly what I needed using Java to interface with the hardware. They had started with a flash solution and recently ported to Javascript. Yay!

http://www.abumarkub.net/abublog/?p=505

Don't let the caveats about 'proof of concept' discourage you: the basic functionality appears solid, at least with everything I have been able to throw at it.

So now I'm on my way, and so is anyone else who want to build javascript based midi interfaces/synths/what have you.

I can manipulate real-time midi in javascript! This is much better than flying cars and jetboots.


I have made a NPAPI browser plugin that lets you communicate in Javascript with MIDI devices.

Currently it works on OSX in Chrome and Safari, and on Windows in Chrome.

I am working on support for other browsers (Firefox, Internet Explorer) and other operating systems (Linux, Android, iOs)

See: http://abumarkub.net/abublog/?p=754


EDIT:

I recently published this module https://github.com/hems/midi2funk it's a node.js module that listens to midi and broadcast it through socket.io so if you have the luxury of running a node.js service locally together with your client side you might get some fun out of it...

~~~~~

A few others handy links, i kinda ordered in what i think would be most important for you:

  • midibridge.js - A Javascript API for interacting with MIDI devices

  • midi.js sequencing in javascript

  • jasmid - A Javascript MIDI file reader and synthesiser

  • Second web midi api working draft published - 11/12/2012

  • Jazz Soft - MIDI IN / OUT PLUGIN FOR BROWSER

edit: just realised the thread is old, hopefully the links will help someone ( :


The Web MIDI API is now real in Google Chrome 43+. I even wrote a library to make it easier to work with it. If you are still interested and do not care that it currently only works in Chrome, check it out: https://github.com/cotejp/webmidi


Nowadays browsers supports MIDI listening. All you need is

navigator.requestMIDIAccess().then(requestMIDIAccessSuccess, requestMIDIAccessFailure);

and listen keys

function requestMIDIAccessSuccess(midi) {
            var inputs = midi.inputs.values();
            for (var input = inputs.next(); input && !input.done; input = inputs.next()) {
                console.log('midi input', input);
                input.value.onmidimessage = midiOnMIDImessage;
            }
            midi.onstatechange = midiOnStateChange;
        }

See working example here


Most browsers don't allow access to any hardware except the keyboard and mouse - for obvious security reasons, so it's unlikely that you could access a midi device unless it's plugged in as one of those devices.

You could try finding a driver that would translate midi output to key presses, and then deal with those in the browser, but this would be a single-computer solution only.


I am really excited by the upcoming Web MIDI API. As far as I know, its only under discussion and hasn't made it into any browsers yet.

Combined with the Web Audio API which has started to be implemented in some browsers already, it will be possible to have complete software synthesis in the browser. Exciting times.


Since Web MIDI API is still a draft, there is no way of direct access to MIDI events in the browser.

A simple workaround could be to write a small server where you register MIDI events and communicate them to your javascript using a websocket. This could be done quite easily in Python.

0

精彩评论

暂无评论...
验证码 换一张
取 消