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

AutoMarimba

先日のMorioka.as->lab0x08で発表したものを移植しています
http://wiki.morioka-as.org/index.cgi?page=lab0x08
Get Adobe Flash player
by gonoverdrive 30 Jan 2012
/**
 * Copyright gonoverdrive ( http://wonderfl.net/user/gonoverdrive )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/uIJo
 */

//SiONのFM音源エミュレータとMML再生を使った簡易的なフレーズ生成機です。
//音でます。UI、グラフィックはちゃんと作ってません。

package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.geom.Point;
 //   import Synth;
  //  import Score;
  //  import Operator;
  //  import Pad;
     [SWF(width = "400", height = "400", backgroundColor = "0x000000", fps = "60")]
    public class AutoMarimba extends Sprite {
        private const CNT_DEF:int = 4;
        private var cnt:int = 0;
        private var synth:Synth;
        private var score:Score;
        private var pos:Point;
        private var markers:Vector.<Sprite> = new Vector.<Sprite>(CNT_DEF);
        private var pad:Pad;
        public function AutoMarimba() {
            synth = new Synth();
            score = new Score(CNT_DEF);
            pad = new Pad(400, 400);
            addChild(pad);
            pad.buttonMode = true;
            pad.addEventListener(MouseEvent.CLICK, _onClick);
            pos = new Point();
        }
        private function _onClick(e:MouseEvent):void {
            var _q:String = "";
            pos.x = pad.mouseX;
            pos.y = pad.mouseY;
            //trace("click count: " + cnt);
            if(cnt < CNT_DEF) {
                markers[cnt] = new Operator(pos.x, pos.y);
                addChild(markers[cnt]);
                //ノートデータ生成
                _q = "d";
                score.setTrack(cnt, pos.x, pos.y, pad.width, pad.height);
                //ノートデータ追加
                synth.setTrack(score.getTrack(cnt));
                cnt++;
            } else if(cnt == CNT_DEF){
                synth.play();
                cnt++;
            } else {
                synth.stop();
                for(var i:int = 0; i < CNT_DEF; i++) {
                    removeChild(markers[i]);
                }
                cnt = 0;
            }
        }
    }
}


import flash.display.Sprite;
import org.si.sion.*;
import org.si.sion.sequencer.*;
import org.si.sion.utils.*;
//音源クラス
class Synth extends Sprite {
    private const TEMPO_DEF:String = "t90;";
    private const TONE_DEF:String = "#OPN@0{4,3, 31,24,00,12,15,32,0,14,2,0, 31,15,00,08,15,00,0,02,0,0, 31,20,00,04,15,27,0,15,0,0, 31,14,00,05,15,00,0,02,0,0};";
    private const TIME_DEF:String = "16";
    private var driver:SiONDriver = new SiONDriver();
    private var presetVoice:SiONPresetVoice = new SiONPresetVoice();
    private var track:SiONData;
    private var mml:String;
    
    public function Synth():void {
        _resetMML();
    }
    
    public function play():void {
        driver.play(mml);
    }
    
    public function stop():void {
        driver.stop();
        _resetMML();
    }
    
    public function setTrack(_notes:String = "d"):void {
        mml += "%6@0o4l" + TIME_DEF;
        mml += "$" + _notes + ";";
    }
    
    private function _resetMML():void {
        mml = TEMPO_DEF;
        mml += TONE_DEF;
    }
}
//譜面クラス
class Score extends Sprite {
    private const PHRASES_DEF:uint = 16;
    private var scales:Vector.<String> = new<String>[ 
        "e",
        "b",
        "f",
        "c",
        "g",
        "a",
        "d"
    ];
    private var notes:Vector.<String>;

    public function Score(_length:int) {
        notes = new Vector.<String>(_length);
        
    }
    
    public function setTrack(_id:int, _x:int, _y:int, _w:int, _h:int):void {
        var _mml:String = "";
        var st:uint;
        var du:uint;
        //開始の音程を決める(y軸)
        st = Math.floor(_y / (_h / scales.length));
        //長さを決める(x軸)
        du = Math.ceil(_x / (_w / PHRASES_DEF));
        //debug
        //trace("start:" + scales[st] + " / length:" + du);
        //フレーズ生成
        var j:uint = 0;
        var k:uint = 0;
        for(var i:int = 0; i < du; i++) {
            k = Math.ceil(PHRASES_DEF / du);
            j = (i*k + st) % scales.length;
            _mml += scales[j];
        }
        
        //trace("MML:" + _mml);
        notes[_id] = _mml;
    }
    
    public function getTrack(_id:int):String {
        return notes[_id]; 
    }
}
//まるいパーツ(グラフィックちゃんと作ってない)
class Operator extends Sprite {
    public function Operator(_x:int, _y:int):void {
        with(graphics) {
            beginFill(0xFFFFFF, 0.4);
            drawCircle(_x,_y,25);
            endFill();
        }
    }
}
//背景(グラフィックちゃんと作ってない)
class Pad extends Sprite {
    public function Pad(_w:int, _h:int):void {
        with(graphics) {
            beginFill(0x999999, 1);
            drawRect(0,0,_w,_h);
            endFill();
        }
    }

}