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

SiON Test

SiON Test
http://wonderfl.net/c/f5eXから音を借りてきた
Get Adobe Flash player
by shohei909 20 Jul 2010
/**
 * Copyright shohei909 ( http://wonderfl.net/user/shohei909 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/fp0Z
 */

//SiON Test
//http://wonderfl.net/c/f5eXから音を借りてきた


package {
    import flash.events.Event;
    import flash.display.Sprite;
    import org.si.sion.events.*;
    import org.si.sound.events.*;
    
    
    public class FlashTest extends Sprite {
        private var sion:SiON = new SiON();
        private var count:int = 0;
        private var color:uint = 0xFF000000;
        private var whiteOut:Boolean = false;
        private var soundMap:SoundMap = new SoundMap();
        
        public function FlashTest() {
            // write as3 code here..
            addChild(soundMap);
            sion.dm.addEventListener(SoundObjectEvent.ENTER_FRAME , onFrame);
            sion.addEventListener(SiONTrackEvent.BEAT, onBeat);
            sion.addEventListener(SiONTrackEvent.NOTE_ON_FRAME, onNote);
            sion.dm.addEventListener(SoundObjectEvent.ENTER_FRAME , soundMap.dram);
            sion.bs.addEventListener(SoundObjectEvent.ENTER_FRAME , soundMap.bass);
            sion.start();
        }
        
        
        private function onBeat(e:SiONEvent):void{
            sion.measure = ++count;
            if(count==80){sion.end()}
            if(count==100){sion.start();count=0;whiteOut=false}
        }

        
        private function onNote(e:SiONEvent):void{
            whiteOut=true;
        } 

        private function onFrame(e:Event):void{
            if(whiteOut){
                if(color<0xFFFFFFFF){color+=0x30303;soundMap.whiteOut(color)}
            }else{
                if(color>0xFF000000){color-=0x30303;soundMap.whiteOut(color)}
            }
        }
        
    }
}
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.events.Event;
import flash.display.*;


//---------------------------------------- SiON
import org.si.sion.*;
import org.si.sion.events.*;
import org.si.sion.effector.*;
import org.si.sion.sequencer.*;
import org.si.sound.*;
import org.si.sound.events.*;
import org.si.sound.synthesizers.*;
import org.si.sound.patterns.*;


class SiON extends SiONDriver {
    public var bs:BassSequencer = new BassSequencer("o3C", 15);
    public var dm:DrumMachine = new DrumMachine(0,0,0,2,2,2);
    private var back:SiONData, fill:SiONData, fill2:SiONData;
    private var analogSynth:AnalogSynth = new AnalogSynth();

    function SiON() : void {
        super();
        setVoice(0, new SiONVoice(5,2,63,63,-10,0,2,20));
        back = compile("#EFFECT1{delay312,30,1};%5@0,40@v64,32q1s24$o6b-r2.;");
        fill = compile("#A=o7[crgrfrcrgrfcrgfr];r1^1%6@0l16@v32,16q8$A(7)A(5);%2@f0,2,16q8s20@0,10%t1,1,0c1^1^8;%2q0s32l16v4[cc(]16;@v128%5@5q0s32,-128o3$c;");//)
        fill2= compile("#A=o7[drargrdrargaragr];%6@0l16@v16,8q8$AA");
        bpm = 132;
        setSamplerData(0, render("%2@v128q0s32o4g16"));
        setSamplerData(1, render("#A=%6@0q0s20o3c*<<<g;A;kt7A"));
        setSamplerData(37, render("%6@0o7q8l64cb-f"));
        setSamplerData(39, render("%6@0o7q8l64gcd"));
        setSamplerData(88, render("%6@0o4q8l32g*<<g"));
        setSamplerData(90, render("%6@0o4q8l32f*<<f"));
        addEventListener(SiONEvent.STREAM_STOP, _onStreamStop);
        dm.volume = 0.6;
        bs.synthesizer = analogSynth;
        bs.volume = 0.6;
        analogSynth.setVCAEnvelop(0,   0.3, 0.7, 0.2);
        analogSynth.setVCFEnvelop(0.4, 0.3, 0.1, 0.6, 0.7);
    }
    public function set measure(m:int) : void {
        switch (m) {
        case 3: dm.bass.mute = false; break;
        case 6: dm.hihat.mute = false; break;
        case 9: bs.mute = false; bs.fadeIn(4); break;
        case 12: bpm = 105; break;
        case 15: bpm = 110; analogSynth.setVCFEnvelop(0.45, 0.3, 0.1, 0.6, 0.75); break; 
        case 18: bpm = 115; analogSynth.setVCFEnvelop(0.5,  0.3, 0.1, 0.6, 0.8);  break;
        case 21: bpm = 120; analogSynth.setVCFEnvelop(0.55, 0.3, 0.1, 0.6, 0.85); break;
        case 24: bpm = 125; analogSynth.setVCFEnvelop(0.6,  0.3, 0.1, 0.6, 0.85); break;
        case 27: bpm = 132; dm.snare.mute = false; dm.hihatPatternNumber = 2; break;
        case 35: sequenceOn(fill, null, 0, 0, 16); break;
        case 43: sequenceOn(fill2, null, 0, 0, 16); break;
        }
    }

    public function start() : void {
        bpm = 100;
        fadeIn(4);
        play(back);
        dm.snarePatternNumber = 0;
        dm.hihatPatternNumber = 13;
        dm.snare.mute = true;
        dm.hihat.mute = true;
        dm.bass.mute = true;
        bs.mute = true;
        dm.play();
        bs.play();
    }
    
    public function end() : void {
        fadeOut(8);
    }
    
    public function se(i:int, pan:int=0, len:int=0, qnt:int=1) : void {
        var t:SiMMLTrack = playSound(i, len, 0, qnt);
        t.effectSend1 = 32;
        t.pan = pan;
    }
    
    private function _onStreamStop(e:SiONEvent) : void {
        bs.stop();
        dm.stop();
    }
}

//背景
class SoundMap extends Bitmap{
    public static var W:int = 465;
    public static var H:int = 465;
    public var defaultMap:BitmapData = new BitmapData(W,H,false,0x000000); 
    private var hihatShape:Shape; 
    private var bassDramShape:Shape; 
    private var snareShape:Shape; 
    private var bassShape:Shape; 
    
    public function SoundMap():void{
        super( new BitmapData(W,H,false,0x000000) );
        addEventListener("enterFrame",enterFrame); 
        
        //ハイハット
        hihatShape= new Shape();
        hihatShape.graphics.beginFill(0x2244444,1);
        hihatShape.graphics.drawCircle(0,0,40);
        
        //バスドラム
        bassDramShape= new Shape();
        bassDramShape.graphics.beginFill(0x444444,1);
        bassDramShape.graphics.drawRoundRect(-50,-50,100,100,30,30);
        
        
        //スネア
        snareShape= new Shape();
        snareShape.graphics.beginFill(0x444444,1);
        snareShape.graphics.drawCircle(0,0,260);
        
        //バスシークエンサー
        bassShape= new Shape();
        bassShape.graphics.beginFill(0x442222,1);
        bassShape.graphics.drawRect(50,50,50,50);
        
    }
    
    private function enterFrame(e:Event):void{
        bitmapData.merge(defaultMap,defaultMap.rect,new Point(),40,40,40,40);
    }
    public function dram(e:SoundObjectEvent):void{
        var obj:DrumMachine = e.soundObject as DrumMachine;
        var t:int = Math.floor(obj.gateTime*16);
        
        
        if(obj.mute == false){
              if(obj.hihat.mute == false && obj.hihat.velocity  >=1){
                   bitmapData.draw(hihatShape,new Matrix(1,0,0,1,W*Math.random(),H*Math.random()),new ColorTransform(1,1,1,obj.volume));
              }
              if(obj.bass.mute == false && obj.bass.velocity  >=1){
                   bitmapData.draw(bassDramShape,new Matrix(1,0,0,1,W/2,H/2),new ColorTransform(1,1,1,obj.volume));
              }
              if(obj.snare.mute == false && obj.snare.velocity  >=1){
                   bitmapData.draw(snareShape,new Matrix(1,0,0,1,W*Math.random(),H*Math.random()),new ColorTransform(1,1,1,obj.volume) );
              }
        }
    }   
    public function bass(e:SoundObjectEvent):void{
        var obj:BassSequencer = e.soundObject as BassSequencer;
        var seq:Sequencer = obj.sequencer;
        if(obj.mute == false && seq.velocity >= 100){
               var mtr:Matrix =  new Matrix();
               var scale:Number = seq.note/30;
               mtr.rotate(seq.frameCount/5*Math.PI);
               mtr.scale(scale,scale);
               mtr.translate(W/2,H/2);
               bitmapData.draw(bassShape,mtr,new ColorTransform(1,1,1,seq.velocity/255));
        }
     }
     
    public function whiteOut(color:uint):void{
        defaultMap.fillRect(defaultMap.rect,color);
    }
}