| 1 |
// SiON KAOS PAD |
|---|
| 2 |
package { |
|---|
| 3 |
import flash.display.Sprite; |
|---|
| 4 |
import flash.events.*; |
|---|
| 5 |
import org.si.sion.*; |
|---|
| 6 |
import org.si.sion.events.*; |
|---|
| 7 |
import org.si.sion.effector.*; |
|---|
| 8 |
import org.si.sion.utils.SiONPresetVoice; |
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
public class KaosPad extends Sprite { |
|---|
| 12 |
// driver |
|---|
| 13 |
public var driver:SiONDriver = new SiONDriver(); |
|---|
| 14 |
|
|---|
| 15 |
// preset voice |
|---|
| 16 |
public var presetVoice:SiONPresetVoice = new SiONPresetVoice(); |
|---|
| 17 |
|
|---|
| 18 |
// MML data |
|---|
| 19 |
public var drumLoop:SiONData; |
|---|
| 20 |
|
|---|
| 21 |
// low pass filter effector |
|---|
| 22 |
public var lpf:SiCtrlFilterLowPass = new SiCtrlFilterLowPass(); |
|---|
| 23 |
|
|---|
| 24 |
// control pad |
|---|
| 25 |
public var controlPad:ControlPad; |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
// constructor |
|---|
| 29 |
function KaosPad() { |
|---|
| 30 |
// compile mml. |
|---|
| 31 |
drumLoop = driver.compile("t132; %6@0o3l8$c2cc.c.; %6@1o3$rcrc; %6@2v8l16$[crccrrcc]; %6@3v8o3$[rc8r8];") |
|---|
| 32 |
|
|---|
| 33 |
// set voices of "%6@0-3" from preset |
|---|
| 34 |
var percusVoices:Array = presetVoice["valsound.percus"]; |
|---|
| 35 |
drumLoop.setVoice(0, percusVoices[0]); // bass drum |
|---|
| 36 |
drumLoop.setVoice(1, percusVoices[27]); // snare drum |
|---|
| 37 |
drumLoop.setVoice(2, percusVoices[16]); // close hihat |
|---|
| 38 |
drumLoop.setVoice(3, percusVoices[21]); // open hihat |
|---|
| 39 |
|
|---|
| 40 |
// listen click |
|---|
| 41 |
driver.addEventListener(SiONEvent.STREAM, _onStream); |
|---|
| 42 |
driver.addEventListener(SiONTrackEvent.BEAT, _onBeat); |
|---|
| 43 |
|
|---|
| 44 |
// set parameters of low pass filter |
|---|
| 45 |
lpf.initialize(); |
|---|
| 46 |
lpf.control(1, 0.5); |
|---|
| 47 |
|
|---|
| 48 |
// connect low pass filter on slot0. |
|---|
| 49 |
driver.effector.initialize(); |
|---|
| 50 |
driver.effector.connect(0, lpf); |
|---|
| 51 |
|
|---|
| 52 |
// control pad |
|---|
| 53 |
controlPad = new ControlPad(stage, 320, 320, 0.5, 1, 0x301010); |
|---|
| 54 |
addChild(controlPad); |
|---|
| 55 |
|
|---|
| 56 |
// play with an argument of resetEffector = false. |
|---|
| 57 |
driver.play(drumLoop, false); |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
private function _onStream(e:SiONEvent) : void |
|---|
| 62 |
{ |
|---|
| 63 |
var x:Number = 1-controlPad.controlX; |
|---|
| 64 |
lpf.control(controlPad.controlY*0.9+0.1, (1-x*x)*0.96); |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
private function _onBeat(e:SiONTrackEvent) : void |
|---|
| 69 |
{ |
|---|
| 70 |
controlPad.beat(32); |
|---|
| 71 |
} |
|---|
| 72 |
} |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
import flash.display.*; |
|---|
| 78 |
import flash.events.*; |
|---|
| 79 |
import flash.filters.BlurFilter; |
|---|
| 80 |
|
|---|
| 81 |
class ControlPad extends Bitmap { |
|---|
| 82 |
public var controlX:Number; |
|---|
| 83 |
public var controlY:Number; |
|---|
| 84 |
public var isDragging:Boolean; |
|---|
| 85 |
public var color:int; |
|---|
| 86 |
|
|---|
| 87 |
private var buffer:BitmapData; |
|---|
| 88 |
private var ratX:Number, ratY:Number; |
|---|
| 89 |
private var prevX:Number, prevY:Number; |
|---|
| 90 |
private var clsDrawer:Shape = new Shape(); |
|---|
| 91 |
private var canvas:Shape = new Shape(); |
|---|
| 92 |
private var blur:BlurFilter = new BlurFilter(5, 5); |
|---|
| 93 |
private var pointerSize:Number = 8; |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
function ControlPad(stage:Stage, width:int, height:int, initialX:Number=0, initialY:Number=0, color:int=0x101030) { |
|---|
| 97 |
super(new BitmapData(width+32, height+32, false, 0)); |
|---|
| 98 |
buffer = new BitmapData(width+32, height+32, false, 0); |
|---|
| 99 |
|
|---|
| 100 |
clsDrawer.graphics.clear(); |
|---|
| 101 |
clsDrawer.graphics.lineStyle(1, 0xffffff); |
|---|
| 102 |
clsDrawer.graphics.drawRect(16, 16, width, height); |
|---|
| 103 |
|
|---|
| 104 |
bitmapData.draw(clsDrawer); |
|---|
| 105 |
buffer.fillRect(buffer.rect, 0); |
|---|
| 106 |
|
|---|
| 107 |
this.color = color; |
|---|
| 108 |
controlX = initialX; |
|---|
| 109 |
controlY = initialY; |
|---|
| 110 |
ratX = 1 / width; |
|---|
| 111 |
ratY = 1 / height; |
|---|
| 112 |
prevX = buffer.width * controlX; |
|---|
| 113 |
prevY = buffer.height * controlY; |
|---|
| 114 |
addEventListener("enterFrame", _onEnterFrame); |
|---|
| 115 |
stage.addEventListener("mouseMove", _onMouseMove); |
|---|
| 116 |
stage.addEventListener("mouseDown", function(e:Event):void { isDragging = true; } ); |
|---|
| 117 |
stage.addEventListener("mouseUp", function(e:Event):void { isDragging = false; }); |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
private function _onEnterFrame(e:Event) : void { |
|---|
| 122 |
var x:Number = (buffer.width-32) * controlX + 16; |
|---|
| 123 |
var y:Number = (buffer.height-32) * (1-controlY) + 16; |
|---|
| 124 |
canvas.graphics.clear(); |
|---|
| 125 |
canvas.graphics.lineStyle(pointerSize, color); |
|---|
| 126 |
canvas.graphics.moveTo(prevX, prevY); |
|---|
| 127 |
canvas.graphics.lineTo(x, y); |
|---|
| 128 |
buffer.applyFilter(buffer, buffer.rect, buffer.rect.topLeft, blur); |
|---|
| 129 |
buffer.draw(canvas, null, null, "add"); |
|---|
| 130 |
bitmapData.copyPixels(buffer, buffer.rect, buffer.rect.topLeft); |
|---|
| 131 |
bitmapData.draw(clsDrawer); |
|---|
| 132 |
prevX = x+Math.random(); |
|---|
| 133 |
prevY = y; |
|---|
| 134 |
pointerSize *= 0.96; |
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
private function _onMouseMove(e:MouseEvent) : void { |
|---|
| 139 |
if (isDragging) { |
|---|
| 140 |
controlX = (mouseX - 16) * ratX; |
|---|
| 141 |
controlY = 1 - (mouseY - 16) * ratY; |
|---|
| 142 |
if (controlX < 0) controlX = 0; |
|---|
| 143 |
else if (controlX > 1) controlX = 1; |
|---|
| 144 |
if (controlY < 0) controlY = 0; |
|---|
| 145 |
else if (controlY > 1) controlY = 1; |
|---|
| 146 |
} |
|---|
| 147 |
} |
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
public function beat(size:int) : void { |
|---|
| 151 |
pointerSize = size; |
|---|
| 152 |
} |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|