Categories
midi

midi bridge code updated

Deprecated, please Chris Wilson’s WebMIDIAPI Shim

As developers started to use the midi-to-flash bridge i realized that the organization of code was not flexible enough. So i rearranged the code rather drastically. The code is now split up into two pieces: the midi bridge and the midi client. The midi bridge comprises 3 parts:

  • a Java applet that receives the midi data from your system
  • some JavaScript code that enables 2-way communication between Java and Flash
  • a small Flash application that broadcasts the midi data to other Flash applications thru a LocalConnection

See the generated asdocs.

This is a sample of a midi bridge. You can set the bridge id and select the midi device that you want to connect to the midi bridge. These parameters can also be set as flashvars in the containing html file.

You can run multiple instances of a midi bridge at the same time, and you can connect each instance to different midi device.

Because a midi client receives midi data thru a LocalConnection it can be any type of Flash application: a swf running in a browser or in a standalone player, a projector or an AIR application.

For a midi client to receive midi data from a midi bridge, you need to create an instance of the MidiClient class in your code and pass it a midi bridge id. If a bridge with the same bridge id is running, this will get your client automatically connected to desired bridge at runtime:
var bridgeId:String = stage.loaderInfo.parameters["midiBridgeId"];
bridgeId = bridgeId == null ? "_device1" : bridgeId;
_midiClient = new MidiClient(bridgeId,false);
_midiClient.addEventListener(MidiDataEvent.CONNECTED, handleMidiDataEvent);
_midiClient.addEventListener(MidiDataEvent.MIDI_DATA, handleMidiDataEvent);

Subsequently you have to implement event listeners and actually do something with the received midi data. In the package you’ll find some handy and efficient midi data parse utilities; these might help you kick-start writing your own code.

You can connect as many midi clients to a midi bridge as you like, and you can disconnect and reconnect them at any time. You can also set up a single client to receive midi data from several bridges, or let your client connect to different midi bridges successively.

This can be very handy if you create an installation with multiple monitors, or if your application has to run on a huge plasma screen.

You can find a sample of a very simple midi client overhere, go ahead and open and close as many clients as you like. Don’t forget to start up the midi bridge first.

multi bridge scenario’s

It is advisable that you have 2 midi devices attached to your computer to test the multi bridge scenario. This is how you set it up:

  • open a bridge, give it an id and press ‘ok’
  • open another bridge, give it a different id and press ‘ok’
  • choose a midi device that you wish to connect to this bridge, play some notes to check connectivity
  • switch to the other bridge and select a different midi device, play some notes or move some controllers to check connectivity
  • open a client and enter either of the 2 bridge ids you have used above and press ‘ok’
  • play some notes on the midi device that is connected to the chosen bridge and you’ll see the data appearing in the client
  • repeat last 2 steps for another client and connect this one to the other bridge
  • connect as many clients as you like to either of the 2 bridges

Obviously, you can make set ups with more than 2 bridges as well.

5 replies on “midi bridge code updated”

Leave a Reply to admin Cancel reply

Your email address will not be published.