In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: forked from: SiON Tenorion

SiON TENORION for v0.57
Get Adobe Flash player
by mirkofresa 09 Jan 2010
/**
 * Copyright mirkofresa ( http://wonderfl.net/user/mirkofresa )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/5Cek
 */

// forked from mirkofresa's forked from: SiON Tenorion
// forked from keim_at_Si's SiON Tenorion
// SiON TENORION for v0.57
package {
    import flash.display.*;
    import flash.events.*;
    import flash.text.TextField;
    import org.si.sion.*;
    import org.si.sion.events.*;
    import org.si.sion.utils.SiONPresetVoice;
   [SWF(width = 576, height = 120,backgroundColor=0xFFFFFF)]
    public class Tenorion extends Sprite {
        // driver
        public var driver:SiONDriver = new SiONDriver();
        
        // preset voice
        public var presetVoice:SiONPresetVoice = new SiONPresetVoice();
        
        // voices, notes and tracks
        public var voices:Vector.<SiONVoice> = new Vector.<SiONVoice>(16);
        public var notes :Vector.<int> = Vector.<int>([36,36,36,36,36,36,36,36,36, 36,35,36,36,36,36,36,]);
        public var length:Vector.<int> = Vector.<int>([ 1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1]);
        
        // beat counter
        public var beatCounter:int;
        
        // control pad
        public var matrixPad:MatrixPad;
        
        // constructor
        function Tenorion() {
            var i:int;
            
            // set voices from preset
            var percusVoices:Array = presetVoice["valsound.percus"];
          
	  voices[9] = percusVoices[0];  // bass drum
            voices [10] = percusVoices[2]; // blipbassd
            voices[13] = percusVoices[16]; // close hihat
            voices[14] = percusVoices[33]; // bli
             voices[11] = percusVoices[24];  // bass drum
            voices[12] = percusVoices[27]; // snare drum
           
            driver.setBeatCallbackInterval(1);
            driver.addEventListener(SiONTrackEvent.BEAT, _onBeat);
            driver.setTimerInterruption(1, _onTimerInterruption);
            
            // control pad
            with(addChild(matrixPad = new MatrixPad(stage))) {
                x = y =  0;
            }

            // start streaming
            beatCounter = 0;
            driver.play();
        }
        
        
        // _onBeat (SiONTrackEvent.BEAT) is called back in each beat at the sound timing.
        private function _onBeat(e:SiONTrackEvent) : void 
        {
            matrixPad.beat(e.eventTriggerID & 15);
        }
        
        
        // _onTimerInterruption (SiONDriver.setTimerInterruption) is called back in each beat at the buffering timing.
        private function _onTimerInterruption() : void
        {
            var beatIndex:int = beatCounter & 15;
            for (var i:int=0; i<15;  i++) {
                if (matrixPad.sequences[i+1] & (1<<beatIndex)) driver.noteOn(Math.round(Math.random()*6+36), voices[i], length[i]);
            }
            beatCounter++;
        }
    }
}



import flash.display.*;
import flash.events.*;
import flash.geom.*;

class MatrixPad extends Bitmap {
    public var sequences:Vector.<int> = new Vector.<int>(16);
    private var canvas:Shape = new Shape();
    private var buffer:BitmapData = new BitmapData(576, 120, true, 0);
    private var padOn:BitmapData  = _pad(0xFFFFFF, 0x4b7322);
    private var padOff:BitmapData = _pad(0xFFFFFF,0xCCCCCC);
    private var pt:Point = new Point();
    private var colt:ColorTransform = new ColorTransform(1,1,1,0.1)
    
    
    function MatrixPad(stage:Stage) {
        super(new BitmapData(576, 120, true, 0));
        var i:int;
        for (i=0; i<96; i++) {
            pt.x = (i&15)*36;
            pt.y = (i&240)*1.25;
            buffer.copyPixels(padOff, padOff.rect, pt);
            bitmapData.copyPixels(padOff, padOff.rect, pt);
        }
        for (i=0; i<16; i++) sequences[i] = 0;
        addEventListener("enterFrame", _onEnterFrame);
        stage.addEventListener("click",  _onClick);
    }
    
    
    private function _pad(border:int, face:int) : BitmapData {
        var pix:BitmapData = new BitmapData(36, 20, false, 0);
        canvas.graphics.clear();
        canvas.graphics.lineStyle(4, border);
        canvas.graphics.beginFill(face);
        canvas.graphics.drawRect(0, 0, 36,20);
        canvas.graphics.endFill();
        pix.draw(canvas);
        return pix;
    }
    
    
    private function _onEnterFrame(e:Event) : void {
        bitmapData.draw(buffer, null, colt);
    }
    
    
    private function _onClick(e:Event) : void {
        if (mouseX>=0 && mouseX<576 && mouseY>=0 && mouseY<120) {
            var track:int = 15-int(mouseY*0.05), beat:int = int(mouseX*0.027);
            sequences[track] ^= 1<<beat;
            pt.x = beat*36;
            pt.y = (15-track)*20;
            if (sequences[track] & (1<<beat)) buffer.copyPixels(padOn, padOn.rect, pt);
            else buffer.copyPixels(padOff, padOff.rect, pt);
        }
    }
    
    
    public function beat(beat16th:int) : void {
        for (pt.x=beat16th*36, pt.y=0; pt.y<120; pt.y+=20) bitmapData.copyPixels(padOn, padOn.rect, pt);
    }
}