| 1 |
// SiON TENORION |
|---|
| 2 |
package { |
|---|
| 3 |
import flash.display.Sprite; |
|---|
| 4 |
import flash.events.*; |
|---|
| 5 |
import flash.text.TextField; |
|---|
| 6 |
import org.si.sion.*; |
|---|
| 7 |
import org.si.sion.events.*; |
|---|
| 8 |
import org.si.sion.utils.SiONPresetVoice; |
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
public class Tenorion extends Sprite { |
|---|
| 12 |
// driver |
|---|
| 13 |
public var driver:SiONDriver = new SiONDriver(); |
|---|
| 14 |
|
|---|
| 15 |
// preset voice |
|---|
| 16 |
public var presetVoice:SiONPresetVoice = new SiONPresetVoice(); |
|---|
| 17 |
|
|---|
| 18 |
// voices, notes and tracks |
|---|
| 19 |
public var voices:Vector.<SiONVoice> = new Vector.<SiONVoice>(16); |
|---|
| 20 |
public var notes :Vector.<int> = Vector.<int>([36,48,60,72, 43,48,55,60, 65,67,70,72, 77,79,82,84]); |
|---|
| 21 |
public var length:Vector.<int> = Vector.<int>([ 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4]); |
|---|
| 22 |
|
|---|
| 23 |
// beat counter |
|---|
| 24 |
public var beatCounter:int; |
|---|
| 25 |
|
|---|
| 26 |
// control pad |
|---|
| 27 |
public var matrixPad:MatrixPad; |
|---|
| 28 |
|
|---|
| 29 |
// constructor |
|---|
| 30 |
function Tenorion() { |
|---|
| 31 |
var i:int; |
|---|
| 32 |
|
|---|
| 33 |
// set voices from preset |
|---|
| 34 |
var percusVoices:Array = presetVoice["valsound.percus"]; |
|---|
| 35 |
voices[0] = percusVoices[0]; // bass drum |
|---|
| 36 |
voices[1] = percusVoices[27]; // snare drum |
|---|
| 37 |
voices[2] = percusVoices[16]; // close hihat |
|---|
| 38 |
voices[3] = percusVoices[22]; // open hihat |
|---|
| 39 |
for (i=4; i<8; i++) voices[i] = presetVoice["valsound.bass18"]; // others |
|---|
| 40 |
|
|---|
| 41 |
// listen |
|---|
| 42 |
driver.setBeatCallbackInterval(1); |
|---|
| 43 |
driver.addEventListener(SiONTrackEvent.BEAT, _onBeat); |
|---|
| 44 |
driver.setTimerInterruption(1, _onTimerInterruption); |
|---|
| 45 |
|
|---|
| 46 |
// control pad |
|---|
| 47 |
matrixPad = new MatrixPad(stage); |
|---|
| 48 |
addChild(matrixPad); |
|---|
| 49 |
|
|---|
| 50 |
// start streaming |
|---|
| 51 |
beatCounter = 0; |
|---|
| 52 |
driver.play(); |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
// _onBeat (SiONTrackEvent.BEAT) is called back in each beat at the sound timing. |
|---|
| 57 |
private function _onBeat(e:SiONTrackEvent) : void |
|---|
| 58 |
{ |
|---|
| 59 |
matrixPad.beat(e.eventTriggerID & 15); |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
// _onTimerInterruption (SiONDriver.setTimerInterruption) is called back in each beat at the buffering timing. |
|---|
| 64 |
private function _onTimerInterruption() : void |
|---|
| 65 |
{ |
|---|
| 66 |
var beatIndex:int = beatCounter & 15; |
|---|
| 67 |
for (var i:int=0; i<16; i++) { |
|---|
| 68 |
if (matrixPad.sequences[i] & (1<<beatIndex)) driver.noteOn(notes[i], voices[i], length[i]); |
|---|
| 69 |
} |
|---|
| 70 |
beatCounter++; |
|---|
| 71 |
} |
|---|
| 72 |
} |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
import flash.display.*; |
|---|
| 78 |
import flash.events.*; |
|---|
| 79 |
import flash.geom.*; |
|---|
| 80 |
|
|---|
| 81 |
class MatrixPad extends Bitmap { |
|---|
| 82 |
public var sequences:Vector.<int> = new Vector.<int>(16); |
|---|
| 83 |
private var canvas:Shape = new Shape(); |
|---|
| 84 |
private var buffer:BitmapData = new BitmapData(320, 320, true, 0); |
|---|
| 85 |
private var padOn:BitmapData = _pad(0x303050, 0x6060a0); |
|---|
| 86 |
private var padOff:BitmapData = _pad(0x303050, 0x202040); |
|---|
| 87 |
private var pt:Point = new Point(); |
|---|
| 88 |
private var colt:ColorTransform = new ColorTransform(1,1,1,0.1) |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
function MatrixPad(stage:Stage) { |
|---|
| 92 |
super(new BitmapData(320, 320, false, 0)); |
|---|
| 93 |
var i:int; |
|---|
| 94 |
for (i=0; i<256; i++) { |
|---|
| 95 |
pt.x = (i&15)*20; |
|---|
| 96 |
pt.y = (i&240)*1.25; |
|---|
| 97 |
buffer.copyPixels(padOff, padOff.rect, pt); |
|---|
| 98 |
bitmapData.copyPixels(padOff, padOff.rect, pt); |
|---|
| 99 |
} |
|---|
| 100 |
for (i=0; i<16; i++) sequences[i] = 0; |
|---|
| 101 |
addEventListener("enterFrame", _onEnterFrame); |
|---|
| 102 |
stage.addEventListener("click", _onClick); |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
private function _pad(border:int, face:int) : BitmapData { |
|---|
| 107 |
var pix:BitmapData = new BitmapData(20, 20, false, 0); |
|---|
| 108 |
canvas.graphics.clear(); |
|---|
| 109 |
canvas.graphics.lineStyle(1, border); |
|---|
| 110 |
canvas.graphics.beginFill(face); |
|---|
| 111 |
canvas.graphics.drawRect(1, 1, 17, 17); |
|---|
| 112 |
canvas.graphics.endFill(); |
|---|
| 113 |
pix.draw(canvas); |
|---|
| 114 |
return pix; |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
private function _onEnterFrame(e:Event) : void { |
|---|
| 119 |
bitmapData.draw(buffer, null, colt); |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
private function _onClick(e:Event) : void { |
|---|
| 124 |
if (mouseX>=0 && mouseX<320 && mouseY>=0 && mouseY<320) { |
|---|
| 125 |
var track:int = 15-int(mouseY*0.05), beat:int = int(mouseX*0.05); |
|---|
| 126 |
sequences[track] ^= 1<<beat; |
|---|
| 127 |
pt.x = beat*20; |
|---|
| 128 |
pt.y = (15-track)*20; |
|---|
| 129 |
if (sequences[track] & (1<<beat)) buffer.copyPixels(padOn, padOn.rect, pt); |
|---|
| 130 |
else buffer.copyPixels(padOff, padOff.rect, pt); |
|---|
| 131 |
} |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
public function beat(beat16th:int) : void { |
|---|
| 136 |
for (pt.x=beat16th*20, pt.y=0; pt.y<320; pt.y+=20) bitmapData.copyPixels(padOn, padOn.rect, pt); |
|---|
| 137 |
} |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
|
|---|