MIDI to Flash (the free way)

I recently bought an AKAI APC-40 for my late night Ableton jam sessions and within moments of deciding to buy it in the first place, I thought about wiring it up to Flash. I’ve already wired up my iPhone to Flash through flOSC (sorry for not blogging about that one) and wanted to do MIDI. Turns out MIDI is a bit more convoluted than OSC, because I can’t keep myself in the TCP/IP stack. I have to kick it to the system level.

Obviously, I wasn’t the first nut to think of this one. In fact, there have been many attempts to do just that. The only problem is those attempts involved MAX/MSP, an expensive program. There is a blogger out there who did WAY more homework than me to find a totally opensource solution. Surya, over at mmmlabs, figured out a method to do it with opensource software. The method includes installing Red5, which impressively decided to include a level of MIDI support in broadcasting NetStreams. I specialize in NetStreams at Current TV so this should be cake.

It will take a couple days to get a proper gateway to the APC going, and when I do I’ll of course post my source-code. I just wanted to let you all get a head start :) Happy coding!

Rotated Gradient Using beginGradientFill ()

Making a rotated gradient in Actionscript is not a trivial task. It turns out there’s only one method to do it that works correctly for me (all other Matrix type voodoo produce funky results). This did exactly what I wanted though:

var matrix:Matrix = new Matrix();

// This line of code is the magic ingredient:
matrix.createGradientBox(_h, _w, (0.5*Math.PI), 0, 0);

with(_bg.graphics) {
clear();
beginGradientFill("linear", [0x656565,0x323232], [100,100], [0,255], matrix);
drawRect(0,0,_w,_h);
endFill();
}

In the createGradientBox, I am doing two things. First I’m creating a box with the precise dimensions of my final gradient, except pre-rotated (flipping width and height) so that when the gradient draws itself out, it does so in its normal way (horizontally across). Secondly, I’m rotating it 90 degrees (or 1/2 PI in radians), so that the width and height flip back to normal as a result of the rotation. What this also accomplishes, however, is it rotates the horizontally rendered gradient to be vertical.