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

beatmania (2012-6-24)

以前、書いたコードが出てきたので移植。
譜面(StepMania:smファイル)は、2550行目あたりから(F#MS)。

thanks :
http://wonderfl.net/c/bB5h
http://www.libspark.org/wiki/BeatTimer/en

KeyConfig : 
[ShiftKey, A], [Z], [S], [X], [D], [C], [F], [V], Select : [Q]

HiSpeedUp : [Q] + [S, D, F]
HiSpeedDown : [Q] + [Z, X, C, V]
Get Adobe Flash player
by TmskSt 24 Jun 2012
package {
    import com.bit101.components.ComboBox;
    import com.bit101.components.Label;
    import com.bit101.components.PushButton;
    import com.bit101.components.TextArea;
    import flash.display.BitmapData;
    import flash.display.MovieClip;
    import flash.display.PixelSnapping;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.KeyboardEvent;
    import flash.events.TimerEvent;
    import flash.geom.Point;
    import flash.media.Sound;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.text.TextField;
    import flash.utils.setTimeout;
    import flash.utils.Timer;
    import org.libspark.betweenas3.BetweenAS3;
    import org.libspark.betweenas3.events.TweenEvent;
    import org.libspark.betweenas3.tweens.ITween;
    
    /**
     * ...
     * @author TmskSt
     */
    public class Main extends Sprite {
        
        /* Var
        // /////////////////////////////////////////////////////// */
        private var musicPlayMovieClip:MusicPlayMovieClip;
        private var readyMovieClip:MovieClip;
        
        private var hiSpeed:HiSpeed;
        private var hiSpeedWindow:MovieClip;
        private var hiSpeedPoint:Point;
        private var hiSpeedClosePoint:Point;
        
        private var hiSpeedView:MovieClip;
        private var difficultyView:MovieClip;
        
        private var laneCoverSUD:LaneCoverDefaultSUD;
        private var laneCoverHID:LaneCoverDefaultHID;
        
        private var laneCoverSUDClosePoint:Point;
        private var laneCoverHIDClosePoint:Point;
        private var laneCoverSUDOpenPoint:Point;
        private var laneCoverHIDOpenPoint:Point;
        
        private var autoPlayPart5Keys:AutoPlayPart5Keys;
        private var autoPlayPartScr:AutoPlayPartScr;
        
        private var gauge:MovieClip;
        private var gaugePoint:Point;
        private var gaugeValue:Number;
        private var gaugeAlpha:Number;
        
        private var totalNotes:int;
        private var addedNotes:int;
        private var maxCombo:int;
        private var currentComboValue:int;
        
        private var numPGreat:int;
        private var numGreat:int;
        private var numGood:int;
        
        private var exScore:Number;
        private var score:Number;
        private var comboScore:Number;
        
        private var fieldScore:Label;
        private var fieldScoreShadow:Label;
        private var fieldMaxCombo:Label;
        private var fieldMaxComboShadow:Label;
        
        /** coords.x */
        private var line:Number;
        
        private var laneScratch:Number;
        private var lane1:Number;
        private var lane2:Number;
        private var lane3:Number;
        private var lane4:Number;
        private var lane5:Number;
        private var lane6:Number;
        private var lane7:Number;
        
        private var beamScratch:BeamDefaultScr;
        private var beam1:BeamDefaultWhite;
        private var beam2:BeamDefaultBlack;
        private var beam3:BeamDefaultWhite;
        private var beam4:BeamDefaultBlack;
        private var beam5:BeamDefaultWhite;
        private var beam6:BeamDefaultBlack;
        private var beam7:BeamDefaultWhite;
        
        private var graphCover:/*GraphCover*/MovieClip;
        
        /** keyDown */
        private var keyDownScratch:Boolean = false;
        private var keyDown1:Boolean = false;
        private var keyDown2:Boolean = false;
        private var keyDown3:Boolean = false;
        private var keyDown4:Boolean = false;
        private var keyDown5:Boolean = false;
        private var keyDown6:Boolean = false;
        private var keyDown7:Boolean = false;
        private var keyDownSelect:Boolean = false;
        private var keyDownStart:Boolean = false;
        
        private var isStopped:Boolean = false;
        private var isStarted:Boolean = false;
        
        // 最適化
        private var maxLines:uint;
        private var maxNotesBlue:uint;
        private var maxNotesWhite:uint;
        private var maxNotesRed:uint;
        
        private var noteBlue:BitmapData;
        private var noteWhite:BitmapData;
        private var noteRed:BitmapData;
        
        private var linesPool:Vector.<Line>;
        private var notesPoolBlue:Vector.<Note>;
        private var notesPoolWhite:Vector.<Note>;
        private var notesPoolRed:Vector.<Note>;
        
        /** container */
        private var containerLines:Vector.<Line>;
        private var containerLaneScratch:Vector.<Note>;
        private var containerLane1:Vector.<Note>;
        private var containerLane2:Vector.<Note>;
        private var containerLane3:Vector.<Note>;
        private var containerLane4:Vector.<Note>;
        private var containerLane5:Vector.<Note>;
        private var containerLane6:Vector.<Note>;
        private var containerLane7:Vector.<Note>;
        private var positionContainerLine:Vector.<Number>;
        private var positionContainerBPM:Vector.<BPM>;
        
        private var gaugePGreat:Number;
        private var gaugeGreat:Number;
        private var gaugeGood:Number;
        private var gaugeBad:Number;
        private var gaugePoor:Number;
        private var gaugeNullPoor:Number;
        
        private var percent:MovieClip;
        
        private var beatTimer:BeatTimer;
        
        private var playerConfig:MusicPlayConfig;
        
        private var coverVy:Number = 0;
        private var accelerator:Number = 1;
        private var notes:Sprite;
        
        
        /** Judge gfx */
        private var judgeTimer:Timer;
        
        private var judgePoint:Point;
        
        private var judgeBridge:MovieClip;
        private var judgePoor:JudgePoor;
        private var judgeBad:JudgeBad;
        private var judgeGood:JudgeGood;
        private var judgeGreat:JudgeGreat;
        private var judgeJustGreat:JudgeJustGreat;
        
        private var bpm:Number;
        private var offset:Number;
        private var sound:Sound;
        
        private var oldPos:Number = 0;
        private var pos:Number = 0;
        
        private var positionContainer:Vector.<Vector.<Number>>;
        
        private var soundTimer:Timer;
        private var bpms:Vector.<BPM>;
        
        /* Const
        // /////////////////////////////////////////////////////// */
        private static const GADGET_NAME:String = "MusicPlayGadget";
        
        private static const BEAM_Y_COORD:Number = 314;
        public static const NOTE_DESTINATION_Y_COORD:Number = 314;
        private static const GRAPH_COVER1P_POINT:Point = new Point(642, -2);
        private static const GRAPH_COVER2P_POINT:Point = new Point( -3, -2);
        
        private static const AUTO_PLAY_FIVE_KEYS_POINT_1P:Point = new Point(211, -2);
        private static const AUTO_PLAY_SCR_POINT_1P:Point = new Point(47, -2);
        
        private static const AUTO_PLAY_FIVE_KEYS_POINT_2P:Point = new Point(428, -2);
        private static const AUTO_PLAY_SCR_POINT_2P:Point = new Point(592, -2);
        
        private static const MUSIC_DATA_FIRST_TWEEN_APPLY_OBJECT:Object = { _blurFilter: { blurX: 0, blurY: 0 }};
        private static const MUSIC_DATA_TWEEN_TO_OBJECT:Object = { _blurFilter : { blurX: 0 }, alpha : 1 };
        private static const MUSIC_DATA_TWEEN_FROM_OBJECT:Object = { _blurFilter : { blurX: 64 }, alpha : 0 };
        private static const MUSIC_DATA_TWEEN_TIME:Number = 0.2;
        private static const MUSIC_DATA_FIRST_TWEEN_POST_DELAY_MILLISECONDS:Number = 3000;
        private static const MUSIC_DATA_SECOND_TWEEN_DELAY:Number = 3;
        private static const MUSIC_DATA_SECOND_TWEEN_POST_DELAY:Number = 2;
        
        private static const RANGE_BAD_JUST_AFTER:Number    = 0.3 + 0.02;
        private static const RANGE_GREAT_JUST_AFTER:Number    = 0.03 + 0.02;
        private static const RANGE_JUST_GREAT:Number        = 0.016 + 0.02;
        private static const RANGE_GREAT_JUST_BEFORE:Number    = 0.03 + 0.02;
        private static const RANGE_GOOD_JUST_BEFORE:Number    = 0.12 + 0.02;
        private static const RANGE_BAD_JUST_BEFORE:Number    = 0.3 + 0.02;
        private static const RANGE_NULL_POOR:Number            = 0.188 + 0.02;
        
        private static const JUDGE_BAD_JUST_AFTER:Number     =    RANGE_BAD_JUST_AFTER;
        private static const JUDGE_GREAT_JUST_AFTER:Number    =    RANGE_BAD_JUST_AFTER + RANGE_GREAT_JUST_AFTER;
        private static const JUDGE_JUST_GREAT:Number        =    RANGE_BAD_JUST_AFTER + RANGE_GREAT_JUST_AFTER + RANGE_JUST_GREAT + RANGE_JUST_GREAT;
        private static const JUDGE_GREAT_JUST_BEFORE:Number    =    RANGE_BAD_JUST_AFTER + RANGE_GREAT_JUST_AFTER + RANGE_JUST_GREAT + RANGE_JUST_GREAT + RANGE_GREAT_JUST_BEFORE;
        private static const JUDGE_GOOD_JUST_BEFORE:Number    =    RANGE_BAD_JUST_AFTER + RANGE_GREAT_JUST_AFTER + RANGE_JUST_GREAT + RANGE_JUST_GREAT + RANGE_GREAT_JUST_BEFORE + RANGE_GOOD_JUST_BEFORE;
        private static const JUDGE_BAD_JUST_BEFORE:Number     =    RANGE_BAD_JUST_AFTER + RANGE_GREAT_JUST_AFTER + RANGE_JUST_GREAT + RANGE_JUST_GREAT + RANGE_GREAT_JUST_BEFORE + RANGE_GOOD_JUST_BEFORE + JUDGE_BAD_JUST_BEFORE;
        private static const JUDGE_NULL_POOR:Number         =    RANGE_BAD_JUST_AFTER + RANGE_GREAT_JUST_AFTER + RANGE_JUST_GREAT + RANGE_JUST_GREAT + RANGE_GREAT_JUST_BEFORE + RANGE_GOOD_JUST_BEFORE + JUDGE_BAD_JUST_BEFORE + RANGE_NULL_POOR;
        private static const NOTE_POOR_DELAY:Number            =    RANGE_BAD_JUST_AFTER + RANGE_GREAT_JUST_AFTER + RANGE_JUST_GREAT;
        
        private static const VELOCITY_CONSTANT_SEC:Number    = 174 * 1.6666666666;
        private static const VELOCITY_CONSTANT_MSEC:Number    = VELOCITY_CONSTANT_SEC * 1000;
        
        private static const GAUGE_CONSTANT_A:Number        = -7.46035E-4;
        private static const GAUGE_CONSTANT_B:Number        = 1.46138;
        
        private static const GRAPH_HEIGHT:Number = 252;
        
        private static const JUDGE_SHOWING_TIME_MSEC:Number = 2000;
        
        private static const READY_DELAY_TIME_MSEC:Number = 2000;
        private var playMusicDataViewTweenFirst:ITween;
        private var playMusicDataViewSecondTween:ITween;
        
        
        private var debug:Debug;
        
        public function Main() {
            this.addEventListener(Event.ADDED, init);
        }
        
        private var hiSp:ComboBox;
        private var stl:ComboBox;
        private var rng:ComboBox;
        
        private var bt:PushButton;
        
        private var lblHisp:Label;
        private var lblStl:Label;
        private var lblRng:Label;
        
        private function init(e:Event):void {
            this.removeEventListener(Event.ADDED, init);
            
            lblHisp = new Label(this, 10, 10, "HiSpeed");
            hiSp = new ComboBox(this, 50, 10, null,
                [
                    HiSpeed.SPEEDS[0].speed, HiSpeed.SPEEDS[1].speed, HiSpeed.SPEEDS[2].speed, HiSpeed.SPEEDS[3].speed,
                    HiSpeed.SPEEDS[4].speed, HiSpeed.SPEEDS[5].speed, HiSpeed.SPEEDS[6].speed, HiSpeed.SPEEDS[7].speed, 
                    HiSpeed.SPEEDS[8].speed, HiSpeed.SPEEDS[9].speed, HiSpeed.SPEEDS[10].speed
                ]
            );
            hiSp.selectedIndex = 0;
            
            lblStl = new Label(this, 10, 40, "Style");
            stl = new ComboBox(this, 50, 40, null,
                [
                    Style.OFF, Style.MIRROR, Style.MIRROR_PLUS, Style.RANDOM, Style.RANDOM_PLUS,
                    Style.S_RANDOM, Style.S_RANDOM_PLUS
                ]
            );
            stl.selectedIndex = 0;
            
            lblRng = new Label(this, 10, 70, "Range");
            rng = new ComboBox(this, 50, 70, null,
                [
                    Range.OFF//, Range.HID_PLUS, Range.HID_SUD, Range.HID_SUD_PLUS, Range.HIDDEN,
                    //Range.SUD_PLUS, Range.SUDDEN
                ]
            );
            rng.selectedIndex = 0;
            
            bt = new PushButton(this, 10, 100, "Next", next);
        }
        private function next(e:Event):void {
            
            this.removeChild(hiSp);
            this.removeChild(rng);
            this.removeChild(stl);
            this.removeChild(bt);
            
            this.removeChild(lblHisp);
            this.removeChild(lblStl);
            this.removeChild(lblRng);
            
            debug = new Debug(this);
            debug.log("init");
            
            this.graphics.beginFill(0);
            this.graphics.drawRect(0, 0, 465, 465);
            this.graphics.endFill();
            
            var config:MusicPlayConfig = new MusicPlayConfig(
                Player.PLAYER_1,
                HiSpeed.SPEEDS[hiSp.selectedIndex],
                Assist.OFF,
                Gauge.OFF,
                Ghost.OFF,
                String(rng.selectedItem),
                String(stl.selectedItem),
                Timing.OFF,
                Difficulty.DARK_ANOTHER
            );
            
            this.load(config);
        }
        
        public function load(config:MusicPlayConfig):void {
            this.playerConfig = config;
            
            sound = new Sound();
            //sound.load(new URLRequest("./res/test10.mp3"));
            sound.load(new URLRequest("http://www.takasumi-nagai.com/soundfiles/sound004.mp3"));
            sound.addEventListener(Event.COMPLETE, loadSM);
        }
        
        private function loadSM(e:Event = null):void {
            
            sound.removeEventListener(Event.COMPLETE, loadSM);
            //
            //var loader:URLLoader = new URLLoader();
            //loader.load(new URLRequest("./res/sm.sm"));
            //loader.load(new URLRequest("./res/test10.sm"));
            //loader.addEventListener (Event.COMPLETE, handler);
            //
            ///** handler */
            //function handler(e:Event):void {
                //e.target.removeEventListener(e.type, arguments.callee);
                //parse(loader.data);
            //}
            parse(F.MS);
        }
        
        private function parse(data:String):void {
            debug.log("parse");
            
            var result:String = "";
            
            for (var b:int = 0; b < data.length; b++) {
                var char:String = data.charAt(b);
                
                if (char == "/" && data.charAt(b + 1) == "/") {
                    while (data.charAt(++b) != "\n") { };
                    continue;
                }
                
                // control character
                if (char.charCodeAt() < 0x1F) { continue; }
                
                // concatenation assignment
                result += char;
            }
            
            var lines:Array = result.split(";");
            lines.pop();
            
            var elems:Array = [];
            for (var a:int = 0; a < lines.length; a++) {
                elems.push(lines[a].slice(1).split(":"));
            }
            
            bpms = new Vector.<BPM>();
            var notes:Vector.<Measure> = new Vector.<Measure>();
            this.positionContainer = new Vector.<Vector.<Number>>();
            this.positionContainer.push(
                new Vector.<Number>(), new Vector.<Number>(), new Vector.<Number>(), new Vector.<Number>(),
                new Vector.<Number>(), new Vector.<Number>(), new Vector.<Number>(), new Vector.<Number>()
            );
            
            this.positionContainerBPM = new Vector.<BPM>();
            this.positionContainerLine = new Vector.<Number>();
            
            
            for (var c:int = 0; c < lines.length; c++) {
                switch(elems[c][0]) {
                    case ChartElement.OFFSET    : offset = elems[c][1]; break;
                    case ChartElement.BPMS        : bpms = parseBPMs(elems[c][1].split(",")); break;
                    case ChartElement.NOTES        : notes = parseNotes(elems[c][1]); break;
                    case ChartElement.TITLE        : break;
                    default : continue; break;
                }
            }
            
            var time:Number = 0;
            
            totalNotes = 0;
            addedNotes = 0;
            
            // All Measure
            for (var d:int = 0; d < notes.length; d++) {
                
                // Beat
                for (var e:int = 0; e < notes[d].beats.length; e++) {
                    var oneBeat:String = notes[d].beats[e];
                    
                    for (var f:int = 0; f < oneBeat.length; f++) {
                        if (oneBeat.charCodeAt(f) == ControlCharacter.FLAG_TRUE) {
                            var target:int = f;
                            var t:int = 0;
                            
                            switch(playerConfig.player) {
                                case Player.PLAYER_1 :
                                    switch(playerConfig.style) {
                                        case Style.S_RANDOM :
                                            switch (playerConfig.assist) {
                                                // [ 0 1 2 3 4 5 X X ] , [ 0 R R R R R X X ]
                                                case Assist.FIVE_KEYS :
                                                    if (f == 6 || f == 7) { continue; }
                                                    else { target = (Math.random() * 5) >> 0; }
                                                break;
                                                
                                                // [ X 1 2 3 4 5 6 7 ] , [ X R R R R R R R ]
                                                case Assist.AUTO_SCRATCH :
                                                    if (f == Lane.LANE_SCRATCH) { continue; }
                                                    else { target = ((Math.random() * 6) >> 0 + 1); }
                                                break;
                                                
                                                // [ X 1 2 3 4 5 X X ] , [ X R R R R R X X ]
                                                case Assist.A_SCR_FIVE_KEYS :
                                                    if (f == 0 || f == 6 || f == 7) { continue; }
                                                    else { target = ((Math.random() * 4) >> 0 + 1); }
                                                break;
                                            }
                                        break;
                                        
                                        // [ 0 1 2 3 4 5 6 7 ] , [ R R R R R R R R ]
                                        case Style.S_RANDOM_PLUS :
                                            target = (Math.random() * 7) >> 0;
                                        break;
                                    }
                                break;
                                
                                case Player.PLAYER_2 :
                                    switch(playerConfig.style) {
                                        case Style.S_RANDOM :
                                            switch (playerConfig.assist) {
                                                // [ 1 2 3 4 5 X X 0 ] , [ X X 1 2 3 4 5 0 ]
                                                case Assist.FIVE_KEYS :
                                                    if (f == 6 || f == 7) { continue; }
                                                    else {
                                                        t = (Math.random() * 5) >> 0;
                                                        target = (t) ? t + 2 : 0;
                                                    }
                                                break;
                                                
                                                // [ 1 2 3 4 5 6 7 X ] , [ 1 2 3 4 5 6 7 X ]
                                                case Assist.AUTO_SCRATCH :
                                                    if (f == Lane.LANE_SCRATCH) { continue; }
                                                    else { target = ((Math.random() * 6) >> 0 + 1); }
                                                break;
                                                
                                                // [ 1 2 3 4 5 X X X ] , [ X X 1 2 3 4 5 X ]
                                                case Assist.A_SCR_FIVE_KEYS :
                                                    if (f == 6 || f == 7 || f == 0) { continue; }
                                                    else {
                                                        t = (Math.random() * 4) >> 0;
                                                        target = (t) ? t + 2 : 0;
                                                    }
                                                break;
                                            }
                                        break;
                                        
                                        // [ 0 1 2 3 4 5 6 7 ] , [ R R R R R R R R ]
                                        case Style.S_RANDOM_PLUS :
                                            target = (Math.random() * 7) >> 0;
                                        break;
                                    }
                                break;
                            }
                            
                            /** addPosition */
                            this.addPosition(target, time);
                            totalNotes += 1;
                        }
                    }
                    
                    // BEAT TIME
                    time += 4 / notes[d].metrical;
                }
                
                this.addPosition(-1, time);
            }
            
            
            var element:Vector.<Number>;
            var nullement:Vector.<Number> = new Vector.<Number>();
            
            switch (playerConfig.player) {
                case Player.PLAYER_1 :
                    switch (playerConfig.assist) {
                        case Assist.OFF :
                            switch (playerConfig.style) {
                                case Style.OFF : break;
                                case Style.RANDOM :
                                    element = this.positionContainer.shift();
                                    this.positionContainer = shuffle(positionContainer);
                                    this.positionContainer.unshift(element);
                                break;
                                case Style.MIRROR :
                                    element = this.positionContainer.shift();
                                    this.positionContainer.reverse();
                                    this.positionContainer.unshift(element);
                                break;
                                case Style.MIRROR_PLUS :
                                    this.positionContainer.reverse();
                                break;
                                case Style.RANDOM_PLUS :
                                    this.positionContainer = shuffle(positionContainer);
                                break;
                            }
                        break;
                        case Assist.FIVE_KEYS :
                            switch (playerConfig.style) {
                                case Style.OFF :
                                    this.positionContainer[Lane.LANE_6].length = 0;
                                    this.positionContainer[Lane.LANE_7].length = 0;
                                break;
                                case Style.RANDOM :
                                    this.positionContainer.splice(Lane.LANE_6, 2);
                                    this.positionContainer = shuffle(positionContainer);
                                    this.positionContainer.push(nullement, nullement);
                                break;
                                case Style.MIRROR :
                                    this.positionContainer.splice(Lane.LANE_6, 2);
                                    element = this.positionContainer.shift();
                                    this.positionContainer.reverse();
                                    this.positionContainer.push(nullement, nullement);
                                    this.positionContainer.unshift(element);
                                break;
                            }
                        break;
                        case Assist.AUTO_SCRATCH :
                            switch (playerConfig.style) {
                                case Style.OFF :
                                    this.positionContainer[Lane.LANE_SCRATCH].length = 0;
                                break;
                                case Style.RANDOM :
                                    this.positionContainer.shift();
                                    this.positionContainer = shuffle(positionContainer);
                                    this.positionContainer.unshift(nullement);
                                break;
                                case Style.MIRROR :
                                    this.positionContainer.shift();
                                    this.positionContainer.reverse();
                                    this.positionContainer.unshift(nullement);
                                break;
                            }
                        break;
                        case Assist.A_SCR_FIVE_KEYS :
                            switch (playerConfig.style) {
                                case Style.OFF :
                                    this.positionContainer[Lane.LANE_SCRATCH].length = 0;
                                    this.positionContainer[Lane.LANE_6].length = 0;
                                    this.positionContainer[Lane.LANE_7].length = 0;
                                break;
                                case Style.RANDOM :
                                    this.positionContainer.splice(Lane.LANE_6, 2);
                                    this.positionContainer.shift();
                                    this.positionContainer = shuffle(positionContainer);
                                    this.positionContainer.unshift(nullement);
                                    this.positionContainer.push(nullement, nullement);
                                break;
                                case Style.MIRROR :
                                    this.positionContainer.splice(Lane.LANE_6, 2);
                                    this.positionContainer.shift();
                                    this.positionContainer.reverse();
                                    this.positionContainer.unshift(nullement);
                                    this.positionContainer.push(nullement, nullement);
                                break;
                            }
                        break;
                    }
                break;
                
                case Player.PLAYER_2 :
                    switch (playerConfig.assist) {
                        case Assist.OFF :
                            switch (playerConfig.style) {
                                case Style.OFF : break;
                                case Style.RANDOM :
                                    element = this.positionContainer.shift();
                                    this.positionContainer = shuffle(positionContainer);
                                    this.positionContainer.unshift(element);
                                break;
                                case Style.MIRROR :
                                    element = this.positionContainer.shift();
                                    this.positionContainer.reverse();
                                    this.positionContainer.unshift(element);
                                break;
                                case Style.MIRROR_PLUS :
                                    element = this.positionContainer.shift();
                                    this.positionContainer.reverse();
                                    this.positionContainer.push(element);
                                break;
                                case Style.RANDOM_PLUS :
                                    this.positionContainer = shuffle(positionContainer);
                                break;
                            }
                        break;
                        case Assist.FIVE_KEYS :
                            switch (playerConfig.style) {
                                case Style.OFF :
                                    this.positionContainer.splice(Lane.LANE_6, 2);
                                    this.positionContainer.splice(Lane.LANE_1, 0, nullement, nullement);
                                break;
                                case Style.RANDOM :
                                    this.positionContainer.splice(Lane.LANE_6, 2);
                                    element = this.positionContainer.shift();
                                    this.positionContainer = shuffle(positionContainer);
                                    this.positionContainer.splice(Lane.LANE_SCRATCH, 0, element, nullement, nullement);
                                break;
                                case Style.MIRROR :
                                    this.positionContainer.splice(Lane.LANE_6, 2);
                                    element = this.positionContainer.shift();
                                    this.positionContainer.reverse();
                                    this.positionContainer.splice(Lane.LANE_SCRATCH, 0, element, nullement, nullement);
                                break;
                            }
                        break;
                        case Assist.AUTO_SCRATCH :
                            switch (playerConfig.style) {
                                case Style.OFF :
                                    this.positionContainer[Lane.LANE_SCRATCH].length = 0;
                                break;
                                case Style.RANDOM :
                                    this.positionContainer.shift();
                                    this.positionContainer = shuffle(positionContainer);
                                    this.positionContainer.unshift(nullement);
                                break;
                                case Style.MIRROR :
                                    this.positionContainer.shift();
                                    this.positionContainer.reverse();
                                    this.positionContainer.unshift(nullement);
                                break;
                            }
                        break;
                        case Assist.A_SCR_FIVE_KEYS :
                            switch (playerConfig.style) {
                                case Style.OFF :
                                    this.positionContainer[0].length = 0;
                                    this.positionContainer.splice(Lane.LANE_6, 2);
                                    this.positionContainer.splice(Lane.LANE_1, 0, nullement, nullement);
                                break;
                                case Style.RANDOM :
                                    this.positionContainer.splice(Lane.LANE_6, 2);
                                    this.positionContainer.shift();
                                    this.positionContainer = shuffle(positionContainer);
                                    this.positionContainer.splice(Lane.LANE_SCRATCH, 0, nullement, nullement, nullement);
                                break;
                                case Style.MIRROR :
                                    this.positionContainer.splice(Lane.LANE_6, 2);
                                    this.positionContainer.shift();
                                    this.positionContainer.reverse();
                                    this.positionContainer.splice(Lane.LANE_SCRATCH, 0, nullement, nullement, nullement);
                                break;
                            }
                        break;
                    }
                break;
            }
            
            this.initialize();
        }
        
        private function initialize():void {
            debug.log("initialize");
            
            /** 最適化 **/
            
            // BitmapData
            noteBlue    = new NoteBlue();
            noteWhite    = new NoteWhite();
            noteRed        = new NoteRed();
            
            // Objects
            maxLines = 500;
            maxNotesBlue = 500;
            maxNotesWhite = 500;
            maxNotesRed = 500;
            
            // ObjectPool
            linesPool        = new Vector.<Line>(maxLines, false);
            notesPoolBlue    = new Vector.<Note>(maxNotesBlue, false);
            notesPoolWhite    = new Vector.<Note>(maxNotesWhite, false);
            notesPoolRed    = new Vector.<Note>(maxNotesRed, false);
            
            // container
            containerLines            = new Vector.<Line>();
            containerLaneScratch    = new Vector.<Note>();
            containerLane1            = new Vector.<Note>();
            containerLane2            = new Vector.<Note>();
            containerLane3            = new Vector.<Note>();
            containerLane4            = new Vector.<Note>();
            containerLane5            = new Vector.<Note>();
            containerLane6            = new Vector.<Note>();
            containerLane7            = new Vector.<Note>();
            
            for (var a:int = 0; a < Math.max(maxLines, maxNotesBlue, maxNotesRed, maxNotesWhite); a++) {
                if (a < maxLines)        linesPool.push(new Line());
                if (a < maxNotesBlue)    notesPoolBlue.push(new Note(noteBlue, PixelSnapping.NEVER, false));
                if (a < maxNotesWhite)    notesPoolWhite.push(new Note(noteWhite, PixelSnapping.NEVER, false))
                if (a < maxNotesRed)    notesPoolRed.push(new Note(noteRed, PixelSnapping.NEVER, false));
            }
            
            musicPlayMovieClip = new MusicPlayMovieClip();
            musicPlayMovieClip.cacheAsBitmap = true;
            musicPlayMovieClip.mouseChildren = false;
            musicPlayMovieClip.mouseEnabled = false;
            this.addChild(musicPlayMovieClip);
            
            switch(playerConfig.gauge) {
                case Gauge.OFF : case Gauge.EASY :
                    gaugeAlpha = GAUGE_CONSTANT_A * totalNotes + GAUGE_CONSTANT_B;
                break;
                default :
                    gaugeAlpha = 0;
                break;
            }
            
            score = 0;
            exScore = 0;
            maxCombo = 0;
            comboScore = 0;
            currentComboValue = 0;
            
            
            switch (playerConfig.gauge) {
                case Gauge.OFF :
                    gaugePGreat        = gaugeAlpha;
                    gaugeGreat        = gaugeAlpha;
                    gaugeGood        = gaugeAlpha * 0.5;
                    gaugeBad        =  -2.0;
                    gaugePoor        = -6.0;
                    gaugeNullPoor    = -2.0;
                break;
                case Gauge.EASY :
                    gaugePGreat        = gaugeAlpha;
                    gaugeGreat        = gaugeAlpha;
                    gaugeGood        = gaugeAlpha * 0.5;
                    gaugeBad        =  -1.6;
                    gaugePoor        = -4.8;
                    gaugeNullPoor    = -1.6;
                break;
                case Gauge.HARD :
                    gaugePGreat        = 0.16;
                    gaugeGreat        = 0.16;
                    gaugeGood        = 0;
                    gaugeBad        = -5;
                    gaugePoor        = -9;
                    gaugeNullPoor    = -5;
                break;
                case Gauge.HAZARD :
                    gaugePGreat        = 0;
                    gaugeGreat        = 0;
                    gaugeGood        = 0;
                    gaugeBad        = 0;
                    gaugePoor        = 0;
                    gaugeNullPoor    = 0;
                break;
                
                //case Gauge. :
                    //gaugePGreat = 0.16;
                    //gaugeGreat = 0.16;
                    //gaugeGood = 0.04;
                    //gaugeBad = -1.5;
                    //gaugePoor = -2.5;
                    //gaugeNullPoor = -1.5
                //break;
            }
            
            var difficultyIndex:int = 0;
            switch(playerConfig.difficulty) {
                case Difficulty.EASY            : difficultyIndex = DifficultyView.EASY; break;
                case Difficulty.NORMAL            : difficultyIndex = DifficultyView.NORMAL; break;
                case Difficulty.HYPER            : difficultyIndex = DifficultyView.HYPER; break;
                case Difficulty.ANOTHER            : difficultyIndex = DifficultyView.ANOTHER; break;
                case Difficulty.DARK_ANOTHER    : difficultyIndex = DifficultyView.DARK_ANOTHER; break;
            }
            
            beamScratch = new BeamDefaultScr();
            beam1 = new BeamDefaultWhite();
            beam2 = new BeamDefaultBlack();
            beam3 = new BeamDefaultWhite();
            beam4 = new BeamDefaultBlack();
            beam5 = new BeamDefaultWhite();
            beam6 = new BeamDefaultBlack();
            beam7 = new BeamDefaultWhite();
            
            switch(playerConfig.gauge) {
                case Gauge.HARD : case Gauge.HARD :
                    gauge = new GaugeHard();
                    gaugeValue = 100;
                break;
                default :
                    gauge = new GaugeNormal();
                    gaugeValue = 22;
                break;
            }
            gauge.cacheAsBitmap = true;
            gauge.opaqueBackground = 0;
            gauge.mouseChildren = false;
            gauge.mouseEnabled = false;
            
            autoPlayPart5Keys = new AutoPlayPart5Keys();
            autoPlayPart5Keys.cacheAsBitmap = true;
            autoPlayPart5Keys.opaqueBackground = 0;
            autoPlayPart5Keys.mouseChildren = false;
            autoPlayPart5Keys.mouseEnabled = false;
            
            autoPlayPartScr = new AutoPlayPartScr();
            autoPlayPartScr.cacheAsBitmap = true;
            autoPlayPartScr.opaqueBackground = 0;
            autoPlayPartScr.mouseChildren = false;
            autoPlayPartScr.mouseEnabled = false;
            
            switch (playerConfig.player) {
                case Player.PLAYER_1 :
                    hiSpeedWindow = new MovieClip();
                    //hiSpeedWindow = musicPlayMovieClip.hiSpeedWindow1P;
                    //musicPlayMovieClip.hiSpeedWindow2P.visible = false;
                    hiSpeedPoint = new Point(236, 0);
                    hiSpeedClosePoint = new Point(183.7, 0);
                    
                    hiSpeedWindow.x = hiSpeedClosePoint.x;
                    
                    graphCover = new GraphCover1P();
                    graphCover.x = GRAPH_COVER1P_POINT.x;
                    graphCover.y = GRAPH_COVER1P_POINT.y;
                    
                    //readyMovieClip = musicPlayMovieClip.playFrameSkin.ready1P;
                    
                    laneCoverSUDClosePoint = new Point(132, 0);
                    laneCoverHIDClosePoint = new Point(132, 318 + 2);
                    
                    laneCoverSUDOpenPoint = new Point(132, 314 + 1);
                    laneCoverHIDOpenPoint = new Point(132, 0);
                    
                    line = 29;
                    
                    laneScratch = 47;
                    lane1 = 78;
                    lane2 = 102;
                    lane3 = 126;
                    lane4 = 150;
                    lane5 = 174;
                    lane6 = 198;
                    lane7 = 222;
                    
                    judgePoint = new Point(131, 205);
                    gaugePoint = new Point(36, 384);
                    
                    //percent = musicPlayMovieClip.playFrameSkin.percent1P;
                    
                    //hiSpeedView = musicPlayMovieClip.playFrameSkin.hiSpeedView1P;
                    //musicPlayMovieClip.playFrameSkin.hiSpeedView2P.visible = false;
                    
                    //difficultyView = musicPlayMovieClip.playFrameSkin.difficultyView1P;
                    //musicPlayMovieClip.playFrameSkin.difficultyView2P.visible = false;
                    //
                    //fieldScore = musicPlayMovieClip.playFrameSkin.textFieldScore1P;
                    //fieldScoreShadow = musicPlayMovieClip.playFrameSkin.textFieldScoreShadow1P;
                    new Label(this, 270, 300, "Score");
                    new Label(this, 330, 300, "---");
                    fieldScore = new Label(/*this, 270, 300*/);
                    fieldScoreShadow = new Label();
                    //
                    //fieldMaxCombo = musicPlayMovieClip.playFrameSkin.textFieldCombo1P;
                    //fieldMaxComboShadow = musicPlayMovieClip.playFrameSkin.textFieldComboShadow1P;
                    new Label(this, 270, 320, "MAX Combo");
                    fieldMaxCombo = new Label(this, 330, 320);
                    fieldMaxComboShadow = new Label();
                    autoPlayPart5Keys.x = AUTO_PLAY_FIVE_KEYS_POINT_1P.x;
                    autoPlayPart5Keys.y = AUTO_PLAY_FIVE_KEYS_POINT_1P.y;
                    autoPlayPartScr.x = AUTO_PLAY_SCR_POINT_1P.x;
                    autoPlayPartScr.y = AUTO_PLAY_SCR_POINT_1P.y;
                break;
                case Player.PLAYER_2 :
                    //hiSpeedWindow = musicPlayMovieClip.hiSpeedWindow2P;
                    //musicPlayMovieClip.hiSpeedWindow1P.visible = false;
                    
                    hiSpeedPoint = new Point(403, 0);
                    hiSpeedClosePoint = new Point(455.3, 0);
                    
                    hiSpeedWindow.x = hiSpeedClosePoint.x;
                    
                    graphCover = new GraphCover2P();
                    graphCover.x = GRAPH_COVER2P_POINT.x;
                    graphCover.y = GRAPH_COVER2P_POINT.y;
                    
                    //readyMovieClip = musicPlayMovieClip.playFrameSkin.ready2P;
                    
                    laneCoverSUDClosePoint = new Point(507, 0);
                    laneCoverHIDClosePoint = new Point(507, 314 + 2);
                    
                    laneCoverSUDOpenPoint = new Point(507, 314 + 1);
                    laneCoverHIDOpenPoint = new Point(507, 0);
                    
                    line = 406;
                    lane1 = 417;
                    lane2 = 441;
                    lane3 = 465;
                    lane4 = 489;
                    lane5 = 513;
                    lane6 = 537;
                    lane7 = 561;
                    laneScratch = 592;
                    
                    judgePoint = new Point(507, 207);
                    
                    gauge.scaleX *= -1;
                    gaugePoint = new Point(603, 384);
                    
                    //percent = musicPlayMovieClip.playFrameSkin.percent2P;
                    //
                    //hiSpeedView = musicPlayMovieClip.playFrameSkin.hiSpeedView2P;
                    //musicPlayMovieClip.playFrameSkin.hiSpeedView1P.visible = false;
                    //
                    //difficultyView = musicPlayMovieClip.playFrameSkin.difficultyView2P;
                    //musicPlayMovieClip.playFrameSkin.difficultyView1P.visible = false;
                    //
                    //fieldScore = musicPlayMovieClip.playFrameSkin.textFieldScore2P;
                    //fieldScoreShadow = musicPlayMovieClip.playFrameSkin.textFieldScoreShadow2P;
                    //
                    //fieldMaxCombo = musicPlayMovieClip.playFrameSkin.textFieldCombo2P;
                    //fieldMaxComboShadow = musicPlayMovieClip.playFrameSkin.textFieldComboShadow2P;
                    
                    autoPlayPart5Keys.x = AUTO_PLAY_FIVE_KEYS_POINT_2P.x;
                    autoPlayPart5Keys.y = AUTO_PLAY_FIVE_KEYS_POINT_2P.y;
                    autoPlayPartScr.x = AUTO_PLAY_SCR_POINT_2P.x;
                    autoPlayPartScr.y = AUTO_PLAY_SCR_POINT_2P.y;
                break;
            }
            
            var _this:Sprite = new Sprite();
            beamScratch.y = beam1.y = beam2.y = beam3.y = beam4.y = beam5.y = beam6.y = beam7.y = BEAM_Y_COORD;
            
            
            beamScratch.x = laneScratch;
            beam1.x = lane1;
            beam2.x = lane2;
            beam3.x = lane3;
            beam4.x = lane4;
            beam5.x = lane5;
            beam6.x = lane6;
            beam7.x = lane7;
            
            _this.addChild(beamScratch);
            _this.addChild(beam1);
            _this.addChild(beam2);
            _this.addChild(beam3);
            _this.addChild(beam4);
            _this.addChild(beam5);
            _this.addChild(beam6);
            _this.addChild(beam7);
            musicPlayMovieClip.addChild(_this);
            
            notes = new Sprite();
            notes.cacheAsBitmap = true;
            //notes.opaqueBackground = 0;
            notes.mouseChildren = false;
            notes.mouseEnabled = false;
            
            
            /*musicPlayMovieClip*/this.addChild(notes);
            
            laneCoverHID = new LaneCoverDefaultHID();
            laneCoverHID.cacheAsBitmap = true;
            laneCoverHID.opaqueBackground = 0;
            laneCoverHID.mouseChildren = false;
            laneCoverHID.mouseEnabled = false;
            
            laneCoverHID.x = laneCoverHIDClosePoint.x;
            laneCoverHID.y = laneCoverHIDClosePoint.y;
            
            if (playerConfig.range == Range.HID_PLUS ||
                playerConfig.range == Range.HID_SUD_PLUS) {
                /*musicPlayMovieClip*/this.addChild(laneCoverHID);
            }
            
            //musicPlayMovieClip.setChildIndex(
                //musicPlayMovieClip.playFrameSkin,
                //musicPlayMovieClip.numChildren - 1
            //);
            
            
            laneCoverSUD = new LaneCoverDefaultSUD();
            laneCoverSUD.cacheAsBitmap = true;
            laneCoverSUD.opaqueBackground = 0;
            laneCoverSUD.mouseChildren = false;
            laneCoverSUD.mouseEnabled = false;
            laneCoverSUD.x = laneCoverSUDClosePoint.x;
            laneCoverSUD.y = laneCoverSUDClosePoint.y;
            
            if (playerConfig.range == Range.SUD_PLUS ||
                playerConfig.range == Range.HID_SUD_PLUS ) {
                /*musicPlayMovieClip*/this.addChild(laneCoverSUD);
            }
            
            
            if (playerConfig.range == Range.HID_SUD_PLUS) {
                
                /** NOT VISIBLE FALSE */
                laneCoverSUD.textFieldGreen.alpha = laneCoverSUD.textFieldGreenShadow.alpha = 0;
                
                laneCoverHIDOpenPoint.y = laneCoverHIDClosePoint.y / 2 - 1;
                laneCoverSUDOpenPoint.y /= 2;
            }
            
            laneCoverSUD.textFieldWhite.visible = laneCoverSUD.textFieldWhiteShadow.visible = laneCoverSUD.textFieldGreen.visible = laneCoverSUD.textFieldGreenShadow.visible = laneCoverHID.textFieldWhite.visible = laneCoverHID.textFieldWhiteShadow.visible = false;
            
            gauge.x = gaugePoint.x;
            gauge.y = gaugePoint.y;
            
            ///*musicPlayMovieClip.playFrameSkin*/this.addChild(gauge);
            
            ///*musicPlayMovieClip*/this.addChild(graphCover);
            
            //musicPlayMovieClip.setChildIndex(
                //musicPlayMovieClip.playMusicDataView,
                //musicPlayMovieClip.numChildren - 1
            //);
            
            hiSpeed = playerConfig.hiSpeed;
            
            hiSpeedWindow.cacheAsBitmap = true;
            hiSpeedWindow.opaqueBackground = 0;
            hiSpeedWindow.mouseChildren = false;
            hiSpeedWindow.mouseEnabled = false;
            hiSpeedWindow.tween = BetweenAS3.tween(this, { } );
            hiSpeedWindow.gotoAndStop(playerConfig.hiSpeed.index);
            
            //difficultyView.gotoAndStop(difficultyIndex);
            
            if (playerConfig.assist == Assist.AUTO_SCRATCH ||
                playerConfig.assist == Assist.A_SCR_FIVE_KEYS) {
                this.addChild(autoPlayPartScr);
            }
            if (playerConfig.assist == Assist.FIVE_KEYS ||
                playerConfig.assist == Assist.A_SCR_FIVE_KEYS) {
                this.addChild(autoPlayPart5Keys);
            }
            
            //musicPlayMovieClip.playFrameSkin.progressBar1P.stop();
            //musicPlayMovieClip.playFrameSkin.progressBar2P.stop();
            
            //musicPlayMovieClip.playMusicDataView.visible = false;
            
            beatTimer = new BeatTimer();
            judgeTimer = new Timer(JUDGE_SHOWING_TIME_MSEC);
            judgeTimer.addEventListener(TimerEvent.TIMER, hideJudge);
            
            /** judge gfx */
            judgePoor = new JudgePoor();
            judgeBad = new JudgeBad();
            judgeGood = new JudgeGood();
            judgeGreat = new JudgeGreat();
            judgeJustGreat = new JudgeJustGreat();
            
            judgePoor.x = judgePoint.x - judgePoor.width * .5;
            judgeBad.x = judgePoint.x - judgeBad.width * .5;
            judgeGood.x = judgePoint.x - judgeGood.width * .5;
            judgeGreat.x = judgePoint.x - judgeGreat.width * .5;
            judgeJustGreat.x = judgePoint.x - judgeJustGreat.width * .5;
            judgePoor.y = judgeBad.y = judgeGood.y = judgeGreat.y = judgeJustGreat.y = judgePoint.y;
            
            
            /** addEventListener */
            stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDownHandler);
            stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUpHandler);
            
            /** Initialize */
            this.upDataGauge();
            this.upDataScore();
            this.currentCombo();
            this.changeBPM(bpms[0].bpm);
            this.initializeCompleted();
        }
        
        private function initializeCompleted():void {
            debug.log("initializeCompleted");
            //musicPlayMovieClip.playMusicDataView.visible = true;
            
            //BetweenAS3.apply(musicPlayMovieClip.playMusicDataView, MUSIC_DATA_FIRST_TWEEN_APPLY_OBJECT);
            
            //playMusicDataViewTweenFirst = BetweenAS3.tween(musicPlayMovieClip.playMusicDataView, MUSIC_DATA_TWEEN_TO_OBJECT, MUSIC_DATA_TWEEN_FROM_OBJECT, MUSIC_DATA_TWEEN_TIME);
            //playMusicDataViewTweenFirst.addEventListener(TweenEvent.COMPLETE, playMusicDataViewFirstTweenCompleted);
            //playMusicDataViewTweenFirst.play();
            
            playMusicDataViewFirstTweenCompleted(null);
        }
        
        private function playMusicDataViewFirstTweenCompleted(e:TweenEvent):void {
            //playMusicDataViewTweenFirst.stop();
            //playMusicDataViewTweenFirst.removeEventListener(TweenEvent.COMPLETE, playMusicDataViewFirstTweenCompleted);
            playMusicDataViewTweenFirst = null;
            
            
            setTimeout(timeOut, MUSIC_DATA_FIRST_TWEEN_POST_DELAY_MILLISECONDS);
        }
        
        private function timeOut():void {
            if ( ! (keyDownStart || keyDownSelect)) playMusicDataViewSecondTweenStart();
            else isStopped = true;
        }
        
        private function parseBPMs(data:/*String*/Array):Vector.<BPM> {
            var bpms:Vector.<BPM> = new Vector.<BPM>();
            for (var k:int = 0; k < data.length; k++) {
                var elem:Array = data[k].split("=");
                bpms.push(new BPM(elem[0], elem[1]));
                
                positionContainerBPM.push(new BPM(elem[0], elem[1]));
            }
            
            return bpms;
        }
        
        private function parseNotes(data:String):Vector.<Measure> {
            var notes:Vector.<Measure> = new Vector.<Measure>();
            var result:String = "";
            for (var b:int = 0; b < data.length; b++) {
                var code:uint = data.charCodeAt(b);
                if (code == ControlCharacter.FLAG_FALSE ||
                    code == ControlCharacter.FLAG_TRUE ||
                    code == ControlCharacter.BREAK) {
                    result += data.charAt(b);
                }
            }
            
            var array:Array = result.split(",");
            for (var measureCounter:int = 0; measureCounter < array.length; measureCounter++) {
                var measure:Vector.<String> = new Vector.<String>();
                
                for (var i:int = 0; i < array[measureCounter].length; i += 8) {
                    measure.push(array[measureCounter].slice(i, i + 8));
                }
                
                notes.push(new Measure(measure));
            }
            
            return notes;
        }
        
        public function addPosition(lane:int, pos:Number):void {
            var target:Vector.<Number>;
            
            switch(lane) {
                case Lane.LANE_SCRATCH    : target = this.positionContainer[Lane.LANE_SCRATCH]; break;
                case Lane.LANE_1        : target = this.positionContainer[Lane.LANE_1]; break;
                case Lane.LANE_2        : target = this.positionContainer[Lane.LANE_2]; break;
                case Lane.LANE_3        : target = this.positionContainer[Lane.LANE_3]; break;
                case Lane.LANE_4        : target = this.positionContainer[Lane.LANE_4]; break;
                case Lane.LANE_5        : target = this.positionContainer[Lane.LANE_5]; break;
                case Lane.LANE_6        : target = this.positionContainer[Lane.LANE_6]; break;
                case Lane.LANE_7        : target = this.positionContainer[Lane.LANE_7]; break;
                case -1 : target = positionContainerLine; break;
                default : return; break;
            }
            
            target.push(pos);
        }
        
        private function shuffle(arg:Vector.<Vector.<Number>>):Vector.<Vector.<Number>> {
            var i:int = arg.length;
            while (i--) {
                var j:Number = Math.floor(Math.random() * (i + 1));
                var t:Vector.<Number> = arg[i];
                arg[i] = arg[j];
                arg[j] = t;
            }
            
            return arg;
        }
        
        private function hideJudge(e:TimerEvent):void {
            e.stopPropagation();
            e.stopImmediatePropagation();
            
            judgeTimer.stop();
            judgeTimer.removeEventListener(TimerEvent.TIMER, hideJudge);
            
            this.removeChild(judgeBridge);
        }
        
        private function onKeyDownHandler(e:KeyboardEvent = null):void {
            e.stopImmediatePropagation();
            e.stopPropagation();
            
            switch(e.keyCode) {
                case KeyConfig.START :
                    if ( ! keyDownStart) this.showHiSpeedWindow();
                break;
                case KeyConfig.SELECT :
                    if ( ! keyDownSelect) this.showHiSpeedWindow();
                break;
                case KeyConfig.KEY1 :
                    if (keyDownStart || keyDownSelect) this.hiSpeedDown();
                    if ( ! keyDown1) { keyDown1 = true; beam1.gotoAndPlay(2); if (containerLane1.length) { judge(containerLane1, notesPoolWhite) }};
                break;
                case KeyConfig.KEY2 :
                    if (keyDownStart || keyDownSelect) this.hiSpeedUp();
                    if ( ! keyDown2) { keyDown2 = true; beam2.gotoAndPlay(2); if (containerLane2.length) { judge(containerLane2, notesPoolBlue) }};
                break;
                case KeyConfig.KEY3:
                    if (keyDownStart || keyDownSelect) this.hiSpeedDown();
                    if ( ! keyDown3) { keyDown3 = true; beam3.gotoAndPlay(2); if (containerLane3.length) { judge(containerLane3, notesPoolWhite) }};
                break;
                case KeyConfig.KEY4 :
                    if (keyDownStart || keyDownSelect) this.hiSpeedUp();
                    if ( ! keyDown4) { keyDown4 = true; beam4.gotoAndPlay(2); if (containerLane4.length) { judge(containerLane4, notesPoolBlue) }};
                break;
                case KeyConfig.KEY5 :
                    if (keyDownStart || keyDownSelect) this.hiSpeedDown();
                    if ( ! keyDown5) { keyDown5 = true; beam5.gotoAndPlay(2); if (containerLane5.length) { judge(containerLane5, notesPoolWhite) }};
                break;
                case KeyConfig.KEY6 :
                    if (keyDownStart || keyDownSelect) { coverVy+=accelerator; this.coverUp(); }
                    if ( ! keyDown6) { keyDown6 = true; beam6.gotoAndPlay(2); if (containerLane6.length) { judge(containerLane6, notesPoolBlue) }};
                break;
                case KeyConfig.KEY7 :
                    if (keyDownStart || keyDownSelect) { coverVy+=accelerator; this.coverDown(); }
                    if ( ! keyDown7) { keyDown7 = true; beam7.gotoAndPlay(2); if (containerLane7.length) { judge(containerLane7, notesPoolWhite) } };
                break;
                case KeyConfig.SCRATCH_A :
                case KeyConfig.SCRATCH_B :
                    if ( ! keyDownScratch) { keyDownScratch = true; beamScratch.gotoAndPlay(2); if (containerLaneScratch.length) { judge(containerLaneScratch, notesPoolRed) } };
                break;
            }
        }
        
        private function onKeyUpHandler(e:KeyboardEvent):void {
            e.stopImmediatePropagation();
            e.stopPropagation();
            
            switch(e.keyCode) {
                case KeyConfig.START :
                case KeyConfig.SELECT :
                    this.hideHiSpeedWindow();
                    
                    if (isStopped) {
                        isStopped = false;
                        playMusicDataViewSecondTweenStart();
                    }
                break;
                case KeyConfig.KEY1 :
                    beam1.gotoAndPlay(5);
                    keyDown1 = false;
                break;
                case KeyConfig.KEY2 :
                    beam2.gotoAndPlay(5);
                    keyDown2 = false;
                break;
                case KeyConfig.KEY3:
                    beam3.gotoAndPlay(5);
                    keyDown3 = false;
                break;
                case KeyConfig.KEY4 :
                    beam4.gotoAndPlay(5);
                    keyDown4 = false;
                break;
                case KeyConfig.KEY5 :
                    beam5.gotoAndPlay(5);
                    keyDown5 = false;
                break;
                case KeyConfig.KEY6 :
                    coverVy = 0;
                    beam6.gotoAndPlay(5);
                    keyDown6 = false;
                break;
                case KeyConfig.KEY7 :
                    coverVy = 0;
                    beam7.gotoAndPlay(5);
                    keyDown7 = false;
                break;
                case KeyConfig.SCRATCH_A :
                case KeyConfig.SCRATCH_B :
                    beamScratch.gotoAndPlay(5);
                    keyDownScratch = false;
                break;
            }
            
        }
        
        private function upDataGauge():void {
            
            //TODO bit
            //TODO *HARDゲージ、段位ゲージは、現在の値が30%未満の場合、減少量が0.5倍される。
            if (gaugeValue < 2) gaugeValue = 2;
            if (gaugeValue > 100) gaugeValue = 100;
            
            var val:int = (((gaugeValue >> 0) % 2) ? (gaugeValue + 1) >> 0 : gaugeValue >> 0) / 2;
            
            //this.gauge.gotoAndStop(val);
            //this.percent.gotoAndStop(val);
            
            musicPlayMovieClip./*playFrameSkin.textFieldCombo2P.text = musicPlayMovieClip.playFrameSkin.*/textFieldComboShadow2P.text = gaugeValue.toString();
        }
        
        private function upDataScore():void {
            var val:Number = currentComboValue - 11;
            //comboScore += 2500 * (currentComboValue * currentComboValue - (currentComboValue - 10) * ((val < 0) ? -val : val) + 19 * currentComboValue - 110) / (2 * totalNotes - 11)
            score = (150000 * numPGreat + 100000 * numGreat + 20000 * numGood) / addedNotes;
            fieldScore.text = fieldScoreShadow.text = (score + comboScore >> 0).toString();
            
            exScore = (numPGreat * 2 + numGreat) / (totalNotes * 2);
            
            //graphCover.graphNow.height = exScore * GRAPH_HEIGHT;
        }
        
        private function currentCombo(isCurrentCombo:Boolean = false, val:int = 1):void{
            if (isCurrentCombo) currentComboValue += val;
            else currentComboValue = 0;
            
            if (maxCombo <= currentComboValue) maxCombo = currentComboValue;
            
            fieldMaxCombo.text = fieldMaxComboShadow.text = maxCombo.toString();
        }
        
        private function changeBPM(nextBPM:Number):void {
            
            bpm = nextBPM;
            oldPos = pos;
            
            beatTimer = new BeatTimer();
            beatTimer.start(bpm);
            
            var val:String = (bpm + 0.5 | 0).toString();
            
            musicPlayMovieClip./*playFrameSkin.*/textFieldBPM.text = val;
            //musicPlayMovieClip.playFrameSkin.textFieldBPMShadow.text = val;
            
            this.realignment();
        }
        
        private function showHiSpeedWindow():void {
            
            //if( ! isStarted) musicPlayMovieClip.playMusicDataView.alpha = 0.3;
            
            keyDownStart = true;
            laneCoverSUD.textFieldWhite.visible = laneCoverSUD.textFieldWhiteShadow.visible = laneCoverSUD.textFieldGreen.visible = laneCoverSUD.textFieldGreenShadow.visible = laneCoverHID.textFieldWhite.visible = laneCoverHID.textFieldWhiteShadow.visible = true;
            
            hiSpeedWindow.tween.stop();
            (hiSpeedWindow.tween = BetweenAS3.tween(hiSpeedWindow, { x : hiSpeedPoint.x }, null, 0.1)).play();
        }
        
        private function hideHiSpeedWindow():void {
            
            //if( ! isStarted) musicPlayMovieClip.playMusicDataView.alpha = 1;
            
            keyDownStart = false;
            laneCoverSUD.textFieldWhite.visible = laneCoverSUD.textFieldWhiteShadow.visible = laneCoverSUD.textFieldGreen.visible = laneCoverSUD.textFieldGreenShadow.visible = laneCoverHID.textFieldWhite.visible = laneCoverHID.textFieldWhiteShadow.visible = false;
            
            hiSpeedWindow.tween.stop();
            (hiSpeedWindow.tween = BetweenAS3.tween(hiSpeedWindow, { x : hiSpeedClosePoint.x }, null, 0.1)).play();
        }
        
        private function hiSpeedUp():void {
            hiSpeed = HiSpeed.SPEEDS[(hiSpeed.index >= HiSpeed.SPEEDS.length) ? hiSpeed.index - 1 : hiSpeed.index];
            //hiSpeedWindow.gotoAndStop(hiSpeed.index);
            //hiSpeedView.gotoAndStop(hiSpeed.index);
            this.realignment();
            this.updateCoverInformation();
        }
        
        private function hiSpeedDown():void {
            hiSpeed = HiSpeed.SPEEDS[(hiSpeed.index - 2 < 0) ? hiSpeed.index - 1 : hiSpeed.index - 2];
            //hiSpeedWindow.gotoAndStop(hiSpeed.index);
            //hiSpeedView.gotoAndStop(hiSpeed.index);
            this.realignment();
            this.updateCoverInformation();
        }
        
        private function judge(container:Vector.<Note>, pool:Vector.<Note>):void {
            
            var noRemove:Boolean = false;
            var isCurrentCombo:Boolean = false;
            var val:int = 1;
            
            var time:Number = container[0].tween.duration - container[0].tween.position;
            if (time < JUDGE_BAD_JUST_AFTER)     {
                showJudge(judgeBad);
                gaugeValue += gaugeBad;
            }
            else if (time < JUDGE_GREAT_JUST_AFTER) {
                showJudge(judgeGreat);
                gaugeValue += gaugeGreat;
                isCurrentCombo = true;
                numGreat += 1;
            }
            else if (time < JUDGE_JUST_GREAT) {
                showJudge(judgeJustGreat);
                gaugeValue += gaugePGreat;
                isCurrentCombo = true;
                numPGreat += 1;
            }
            else if (time < JUDGE_GREAT_JUST_BEFORE) {
                showJudge(judgeGreat);
                gaugeValue += gaugeGreat;
                isCurrentCombo = true;
                numGreat += 1;
            }
            else if (time < JUDGE_GOOD_JUST_BEFORE) {
                showJudge(judgeGood);
                gaugeValue += gaugeGood;
                isCurrentCombo = true;
                numGood += 1;
            }
            else if (time < JUDGE_BAD_JUST_BEFORE) {
                showJudge(judgeBad);
                gaugeValue += gaugeBad;
            }
            else if (time < JUDGE_NULL_POOR) {
                showJudge(judgePoor);
                gaugeValue += gaugeNullPoor;
                isCurrentCombo = true;
                noRemove = true;
                val = 0;
            }
            else { return; }
            
            
            
            this.upDataGauge();
            this.upDataScore();
            this.currentCombo(isCurrentCombo, val);
            if ( ! noRemove) this.removeNote(container[0], container, pool);
        }
        
        private function showJudge(_judge:MovieClip):void {
            if (judgeTimer.running) {
                this.removeChild(judgeBridge);
            }
            
            judgeBridge = _judge;
            judgeTimer.reset();
            judgeTimer.start();
            
            this.addChild(judgeBridge);
        }
        
        private function coverUp():void {
            if (playerConfig.range == Range.HID_SUD_PLUS) {
                if (laneCoverHID.y - coverVy >= laneCoverHIDOpenPoint.y) laneCoverHID.y -= coverVy;
                if (laneCoverSUD.y + coverVy <= laneCoverSUDOpenPoint.y) laneCoverSUD.y += coverVy;
            } else {
                if (laneCoverHID.y - coverVy >= laneCoverHIDOpenPoint.y) laneCoverHID.y -= coverVy;
                if (laneCoverSUD.y - coverVy >= laneCoverSUDClosePoint.y) laneCoverSUD.y -= coverVy;
            }
            this.updateCoverInformation();
        }
        
        private function coverDown():void {
            if (playerConfig.range == Range.HID_SUD_PLUS) {
                if (laneCoverHID.y + coverVy < laneCoverHIDClosePoint.y) laneCoverHID.y += coverVy;
                if (laneCoverSUD.y - coverVy > laneCoverSUDClosePoint.y) laneCoverSUD.y -= coverVy;
            }else {
                if (laneCoverHID.y + coverVy < laneCoverHIDClosePoint.y) laneCoverHID.y += coverVy;
                if (laneCoverSUD.y + coverVy < laneCoverSUDOpenPoint.y) laneCoverSUD.y += coverVy;
            }
            
            this.updateCoverInformation();
        }
        
        private function updateCoverInformation():void{
            laneCoverSUD.textFieldWhite.text = laneCoverSUD.textFieldWhiteShadow.text = String(1000 * (laneCoverSUD.y / 314) >> 0);
            laneCoverSUD.textFieldGreen.text = laneCoverSUD.textFieldGreenShadow.text = String(174000 / bpm / hiSpeed.speed - ((laneCoverSUD.y / 314) * (174000 / bpm / hiSpeed.speed) ) >> 0);
            
            laneCoverHID.textFieldWhite.text = laneCoverHID.textFieldWhiteShadow.text = String(1000 - 1000 * (laneCoverHID.y / 314) >> 0);
        }
        
        private function playMusicDataViewSecondTweenStart():void {
            isStarted = true;
            //musicPlayMovieClip.playMusicDataView.alpha = 1;
            //
            //playMusicDataViewSecondTween = BetweenAS3.delay(BetweenAS3.tween(musicPlayMovieClip.playMusicDataView, MUSIC_DATA_TWEEN_FROM_OBJECT, null, MUSIC_DATA_TWEEN_TIME), MUSIC_DATA_SECOND_TWEEN_DELAY, MUSIC_DATA_SECOND_TWEEN_POST_DELAY);
            //playMusicDataViewSecondTween.addEventListener(TweenEvent.COMPLETE, ready);
            //playMusicDataViewSecondTween.play();
            
            ready(null);
        }
        
        private function ready(e:TweenEvent):void {
            
            //playMusicDataViewSecondTween.stop();
            //playMusicDataViewSecondTween.removeEventListener(TweenEvent.COMPLETE, ready);
            playMusicDataViewSecondTween = null;
            
            debug.log("ready");
            //readyMovieClip.play();
            setTimeout(start, READY_DELAY_TIME_MSEC);
        }
        
        private function timeDelay(e:TimerEvent):void {
            e.stopImmediatePropagation();
            e.stopPropagation();
            
            sound.play();
            
            soundTimer.stop();
            soundTimer.removeEventListener(TimerEvent.TIMER, timeDelay);
            
            soundTimer = null;
        }
        
        private function start():void {
            
            /** addEventListener */
            stage.addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
            
            pos = 0;
            oldPos = 0;
            
            beatTimer.start(bpm);
            
            debug.log("start");
            soundTimer = new Timer(VELOCITY_CONSTANT_MSEC / bpm + offset * 1000);
            soundTimer.addEventListener(TimerEvent.TIMER, timeDelay);
            soundTimer.start();
        }
        
        private function onEnterFrameHandler(e:Event):void {
            e.stopImmediatePropagation();
            e.stopPropagation();
            beatTimer.update();
            
            pos = beatTimer.beatPosition + oldPos;
            if(positionContainer[0].length){
                if (positionContainer[0][0] < pos) {
                    positionContainer[0].shift();
                    addNote(Lane.LANE_SCRATCH);
                }
            }
            if(positionContainer[1].length){
                if (positionContainer[1][0] < pos) {
                    positionContainer[1].shift();
                    addNote(Lane.LANE_1);
                }
            }
            if(positionContainer[2].length){
                if (positionContainer[2][0] < pos) {
                    positionContainer[2].shift();
                    addNote(Lane.LANE_2);
                }
            }
            if(positionContainer[3].length){
                if (positionContainer[3][0] < pos) {
                    positionContainer[3].shift();
                    addNote(Lane.LANE_3);
                }
            }
            if(positionContainer[4].length){
                if (positionContainer[4][0] < pos) {
                    positionContainer[4].shift();
                    addNote(Lane.LANE_4);
                }
            }
            if(positionContainer[5].length){
                if (positionContainer[5][0] < pos) {
                    positionContainer[5].shift();
                    addNote(Lane.LANE_5);
                }
            }
            if(positionContainer[6].length){
                if (positionContainer[6][0] < pos) {
                    positionContainer[6].shift();
                    addNote(Lane.LANE_6);
                }
            }
            if(positionContainer[7].length){
                if (positionContainer[7][0] < pos) {
                    positionContainer[7].shift();
                    addNote(Lane.LANE_7);
                }
            }
            if (positionContainerBPM.length) {
                if (positionContainerBPM[0].pos+5 < pos) {
                    changeBPM(positionContainerBPM[0].bpm);
                    positionContainerBPM.shift();
                }
            }
            if (positionContainerLine.length) {
                if (positionContainerLine[0] < pos) {
                    positionContainerLine.shift();
                    addLine();
                }
            }
        }
        
        private function realignment():void {
            
            var container:Vector.<Note>;
            var pool:Vector.<Note>;
            var note:Note;
            var counter:int;
            
            if (containerLaneScratch.length) {
                
                
                container = containerLaneScratch;
                pool = notesPoolRed;
                
                for each(note in container) {
                    note.tween.stop();
                    note.tween.removeEventListener(TweenEvent.COMPLETE, timeOutPoor(note, container, pool));
                    
                    note.pos += (1 - note.pos) * (note.tween.position / (note.tween.duration- NOTE_POOR_DELAY));
                    
                    (note.tween = BetweenAS3.delay(BetweenAS3.tween(note,
                        { y : NOTE_DESTINATION_Y_COORD },
                        { y : 0 - (NOTE_DESTINATION_Y_COORD * (1 - note.pos)) * hiSpeed.speed + NOTE_DESTINATION_Y_COORD },
                        (1 - note.pos) * (VELOCITY_CONSTANT_SEC / bpm)),
                        0, NOTE_POOR_DELAY
                    )).play();
                    note.tween.addEventListener(TweenEvent.COMPLETE, timeOutPoor(note, container, pool));
                }
            }
            
            if (containerLane1.length) {
                
                
                container = containerLane1;
                pool = notesPoolWhite;
                
                for each(note in container) {
                    note.tween.stop();
                    note.tween.removeEventListener(TweenEvent.COMPLETE, timeOutPoor(note, container, pool));
                    
                    note.pos += (1 - note.pos) * (note.tween.position / (note.tween.duration- NOTE_POOR_DELAY));
                    
                    (note.tween = BetweenAS3.delay(BetweenAS3.tween(note,
                        { y : NOTE_DESTINATION_Y_COORD },
                        { y : 0 - (NOTE_DESTINATION_Y_COORD * (1 - note.pos)) * hiSpeed.speed + NOTE_DESTINATION_Y_COORD },
                        (1 - note.pos) * (VELOCITY_CONSTANT_SEC / bpm)),
                        0, NOTE_POOR_DELAY
                    )).play();
                    note.tween.addEventListener(TweenEvent.COMPLETE, timeOutPoor(note, container, pool));
                }
            }
            
            if (containerLane3.length) {
                
                container = containerLane3;
                pool = notesPoolWhite;
                
                for each(note in container) {
                    note.tween.stop();
                    note.tween.removeEventListener(TweenEvent.COMPLETE, timeOutPoor(note, container, pool));
                    
                    note.pos += (1 - note.pos) * (note.tween.position / (note.tween.duration- NOTE_POOR_DELAY));
                    
                    (note.tween = BetweenAS3.delay(BetweenAS3.tween(note,
                        { y : NOTE_DESTINATION_Y_COORD },
                        { y : 0 - (NOTE_DESTINATION_Y_COORD * (1 - note.pos)) * hiSpeed.speed + NOTE_DESTINATION_Y_COORD },
                        (1 - note.pos) * (VELOCITY_CONSTANT_SEC / bpm)),
                        0, NOTE_POOR_DELAY
                    )).play();
                    note.tween.addEventListener(TweenEvent.COMPLETE, timeOutPoor(note, container, pool));
                }
            }
            
            if (containerLane5.length) {
                
                
                container = containerLane5;
                pool = notesPoolWhite;
                
                for each(note in container) {
                    note.tween.stop();
                    note.tween.removeEventListener(TweenEvent.COMPLETE, timeOutPoor(note, container, pool));
                    
                    note.pos += (1 - note.pos) * (note.tween.position / (note.tween.duration- NOTE_POOR_DELAY));
                    
                    (note.tween = BetweenAS3.delay(BetweenAS3.tween(note,
                        { y : NOTE_DESTINATION_Y_COORD },
                        { y : 0 - (NOTE_DESTINATION_Y_COORD * (1 - note.pos)) * hiSpeed.speed + NOTE_DESTINATION_Y_COORD },
                        (1 - note.pos) * (VELOCITY_CONSTANT_SEC / bpm)),
                        0, NOTE_POOR_DELAY
                    )).play();
                    note.tween.addEventListener(TweenEvent.COMPLETE, timeOutPoor(note, container, pool));
                }
            }
            
            if (containerLane7.length) {
                
                
                container = containerLane7;
                pool = notesPoolWhite;
                
                for each(note in container) {
                    note.tween.stop();
                    note.tween.removeEventListener(TweenEvent.COMPLETE, timeOutPoor(note, container, pool));
                    
                    note.pos += (1 - note.pos) * (note.tween.position / (note.tween.duration- NOTE_POOR_DELAY));
                    
                    (note.tween = BetweenAS3.delay(BetweenAS3.tween(note,
                        { y : NOTE_DESTINATION_Y_COORD },
                        { y : 0 - (NOTE_DESTINATION_Y_COORD * (1 - note.pos)) * hiSpeed.speed + NOTE_DESTINATION_Y_COORD },
                        (1 - note.pos) * (VELOCITY_CONSTANT_SEC / bpm)),
                        0, NOTE_POOR_DELAY
                    )).play();
                    note.tween.addEventListener(TweenEvent.COMPLETE, timeOutPoor(note, container, pool));
                }
            }
            
            if (containerLane2.length) {
                
                
                container = containerLane2;
                pool = notesPoolBlue;
                
                for each(note in container) {
                    note.tween.stop();
                    note.tween.removeEventListener(TweenEvent.COMPLETE, timeOutPoor(note, container, pool));
                    
                    note.pos += (1 - note.pos) * (note.tween.position / (note.tween.duration- NOTE_POOR_DELAY));
                    
                    (note.tween = BetweenAS3.delay(BetweenAS3.tween(note,
                        { y : NOTE_DESTINATION_Y_COORD },
                        { y : 0 - (NOTE_DESTINATION_Y_COORD * (1 - note.pos)) * hiSpeed.speed + NOTE_DESTINATION_Y_COORD },
                        (1 - note.pos) * (VELOCITY_CONSTANT_SEC / bpm)),
                        0, NOTE_POOR_DELAY
                    )).play();
                    note.tween.addEventListener(TweenEvent.COMPLETE, timeOutPoor(note, container, pool));
                }
            }
            
            if (containerLane4.length) {
                
                
                container = containerLane4;
                pool = notesPoolBlue;
                
                for each(note in container) {
                    note.tween.stop();
                    note.tween.removeEventListener(TweenEvent.COMPLETE, timeOutPoor(note, container, pool));
                    
                    note.pos += (1 - note.pos) * (note.tween.position / (note.tween.duration- NOTE_POOR_DELAY));
                    
                    (note.tween = BetweenAS3.delay(BetweenAS3.tween(note,
                        { y : NOTE_DESTINATION_Y_COORD },
                        { y : 0 - (NOTE_DESTINATION_Y_COORD * (1 - note.pos)) * hiSpeed.speed + NOTE_DESTINATION_Y_COORD },
                        (1 - note.pos) * (VELOCITY_CONSTANT_SEC / bpm)),
                        0, NOTE_POOR_DELAY
                    )).play();
                    note.tween.addEventListener(TweenEvent.COMPLETE, timeOutPoor(note, container, pool));
                }
            }
            
            if (containerLane6.length) {
                
                
                container = containerLane6;
                pool = notesPoolBlue;
                
                for each(note in container) {
                    note.tween.stop();
                    note.tween.removeEventListener(TweenEvent.COMPLETE, timeOutPoor(note, container, pool));
                    
                    note.pos += (1 - note.pos) * (note.tween.position / (note.tween.duration- NOTE_POOR_DELAY));
                    
                    (note.tween = BetweenAS3.delay(BetweenAS3.tween(note,
                        { y : NOTE_DESTINATION_Y_COORD },
                        { y : 0 - (NOTE_DESTINATION_Y_COORD * (1 - note.pos)) * hiSpeed.speed + NOTE_DESTINATION_Y_COORD },
                        (1 - note.pos) * (VELOCITY_CONSTANT_SEC / bpm)),
                        0, NOTE_POOR_DELAY
                    )).play();
                    note.tween.addEventListener(TweenEvent.COMPLETE, timeOutPoor(note, container, pool));
                }
            }
            
            if (containerLines.length) {
                for each(var line:Line in containerLines) {
                    line.tween.stop();
                    line.pos += (1 - line.pos) * (line.tween.position / line.tween.duration);
                    line.tween.removeEventListener(TweenEvent.COMPLETE, lineTweenCompleted);
                    
                    (line.tween = BetweenAS3.tween(line,
                        { y : NOTE_DESTINATION_Y_COORD },
                        { y : 0 - (NOTE_DESTINATION_Y_COORD * (1 - line.pos)) * hiSpeed.speed + NOTE_DESTINATION_Y_COORD },
                        (1 - line.pos) * (VELOCITY_CONSTANT_SEC / bpm)
                    )).play();
                    line.tween.addEventListener(TweenEvent.COMPLETE, lineTweenCompleted);
                }
            }
        }
        
        private function timeOutPoor(note:Note, container:Vector.<Note>, pool:Vector.<Note>):Function {
            return function anonymous():void {
                
                gaugeValue += gaugePoor;
                upDataGauge();
                currentCombo(false);
                
                showJudge(judgePoor);
                removeNote(note, container, pool);
            }
        }
        
        private function addNote(laneNumber:int):void {
            
            var note:Note;
            var index:int;
            var container:Vector.<Note>;
            var pool:Vector.<Note>;
            
            switch(laneNumber) {
                /** scratch Lane */
                case Lane.LANE_SCRATCH :
                    container = containerLaneScratch;
                    pool = notesPoolRed;
                    
                    note = notes.addChild(container[container.push(pool.pop()) - 1]) as Note;
                    note.x = laneScratch - note.width * .5;
                break;
                case Lane.LANE_1 :
                    container = containerLane1;
                    pool = notesPoolWhite;
                    
                    note = notes.addChild(container[container.push(pool.pop()) - 1]) as Note;
                    note.x = lane1 - note.width * .5;
                break;
                case Lane.LANE_2 :
                    container = containerLane2;
                    pool = notesPoolBlue;
                    
                    note = notes.addChild(container[container.push(pool.pop()) - 1]) as Note;
                    note.x = lane2 - note.width * .5;
                break;
                case Lane.LANE_3 :
                    container = containerLane3;
                    pool = notesPoolWhite;
                    
                    note = notes.addChild(container[container.push(pool.pop()) - 1]) as Note;
                    note.x = lane3 - note.width * .5;
                break;
                case Lane.LANE_4 :
                    container = containerLane4;
                    pool = notesPoolBlue;
                    
                    note = notes.addChild(container[container.push(pool.pop()) - 1]) as Note;
                    note.x = lane4 - note.width * .5;
                break;
                case Lane.LANE_5 :
                    container = containerLane5;
                    pool = notesPoolWhite;
                    
                    note = notes.addChild(container[container.push(pool.pop()) - 1]) as Note;
                    note.x = lane5 - note.width * .5;
                break;
                case Lane.LANE_6 :
                    container = containerLane6;
                    pool = notesPoolBlue;
                    
                    note = notes.addChild(container[container.push(pool.pop()) - 1]) as Note;
                    note.x = lane6 - note.width * .5;
                break;
                case Lane.LANE_7 :
                    container = containerLane7;
                    pool = notesPoolWhite;
                    
                    note = notes.addChild(container[container.push(pool.pop()) - 1]) as Note;
                    note.x = lane7 - note.width * .5;
                break;
            }
            
            //note.tween = null;
            note.pos = 0;
            
            (note.tween = BetweenAS3.delay(BetweenAS3.tween(note,
                { y : NOTE_DESTINATION_Y_COORD },
                { y : 0 - (NOTE_DESTINATION_Y_COORD * (1 - 0)) * hiSpeed.speed + NOTE_DESTINATION_Y_COORD },
                (VELOCITY_CONSTANT_SEC / bpm)
                ), 0, NOTE_POOR_DELAY
            )).play();
            
            note.tween.addEventListener(TweenEvent.COMPLETE, timeOutPoor(note, container, pool));
        }
        
        private function removeNote(note:Note, container:Vector.<Note>, pool:Vector.<Note>):void {
            note.tween.stop();
            note.tween.removeEventListener(TweenEvent.COMPLETE, timeOutPoor(note, container, pool));
            
            if (notes.contains(note)) notes.removeChild(note);
            pool.push(container.shift());
        }
        
        private function addLine():void {
            
            var line:Line = notes.addChild(containerLines[containerLines.push(linesPool.pop()) - 1]) as Line;
            line.x = this.line;
            //line.tween = null;
            line.pos = 0;
            
            (line.tween = BetweenAS3.tween(line,
                { y : NOTE_DESTINATION_Y_COORD },
                { y : 0 - (NOTE_DESTINATION_Y_COORD * (1 - 0)) * hiSpeed.speed + NOTE_DESTINATION_Y_COORD },
                (VELOCITY_CONSTANT_SEC / bpm)
            )).play();
            line.tween.addEventListener(TweenEvent.COMPLETE, lineTweenCompleted);
        }
        
        private function removeLine(line:Line):void {
            if (notes.contains(line)) notes.removeChild(line);
            linesPool.push(containerLines.shift());
        }
        
        private function lineTweenCompleted(e:TweenEvent):void {
            e.stopImmediatePropagation();
            e.stopPropagation();
            
            containerLines[0].tween.stop();
            containerLines[0].tween.removeEventListener(TweenEvent.COMPLETE, lineTweenCompleted);
            
            removeLine(containerLines[0]);
        }
        
        
        
    }
}

class MusicPlayConfig {
    
    public function MusicPlayConfig (
        _player:String,
        _hiSpeed:HiSpeed,
        _assist:String,
        _gauge:String,
        _ghost:String,
        _range:String,
        _style:String,
        _timing:String,
        _difficulty:String
        ) {
        this.player = _player;
        this.hiSpeed = _hiSpeed;
        this.assist = _assist;
        this.gauge = _gauge;
        this.ghost = _ghost;
        this.range = _range;
        this.style = _style;
        this.timing = _timing;
        this.difficulty = _difficulty;
    }
    
    public var player:String;
    
    public var hiSpeed:HiSpeed;
    public var assist:String;
    public var gauge:String;
    public var ghost:String;
    public var range:String;
    public var style:String;
    public var timing:String;
    
    public var difficulty:String;
    
    public var title:String;
    public var artist:String;
    public var level:String;
}

class HiSpeed {
    
    /**
     * constructor
     * @param    _index
     * @param    _speed
     */
    public function HiSpeed(_index:int, _speed:Number) {
        this.index = _index;
        this.speed = _speed;
    }
    
    public static const SPEEDS:Vector.<HiSpeed> = Vector.<HiSpeed>([
        new HiSpeed(1, 1.0),
        new HiSpeed(2, 1.5),
        new HiSpeed(3, 2.0),
        new HiSpeed(4, 2.25),
        new HiSpeed(5, 2.5),
        new HiSpeed(6, 2.75),
        new HiSpeed(7, 3.0),
        new HiSpeed(8, 3.25),
        new HiSpeed(9, 3.5),
        new HiSpeed(10, 3.75),
        new HiSpeed(11, 4.0)
    ]);
    
    public var index:int;
    public var speed:Number;
}

class Player {
    public static const PLAYER_1:String = "Player1";
    public static const PLAYER_2:String = "Player2";
}

class Assist {
    
    /**/
    public static const OFF:String = "off";
    
    /** */
    public static const AUTO_SCRATCH:String = "autoScratch";
    
    /** */
    public static const FIVE_KEYS:String = "5Keys";
    
    /** */
    public static const A_SCR_FIVE_KEYS:String = "autoScratch5Keys";
}

class Gauge {
    
    /**/
    public static const OFF:String = "off";
    
    /** */
    public static const EASY:String = "easy";
    
    /** */
    public static const HARD:String = "hard";
    
    /** */
    public static const HAZARD:String = "hazard";
    
}

class Ghost {
    
    /**/
    public static const OFF:String = "off";
    
    /**/
    public static const TYPE_A:String = "typeA";
    
    /**/
    public static const TYPE_B:String = "typeB";
    
    /**/
    public static const TYPE_C:String = "typeC";
    
}

class Range {
    
    /**/
    public static const OFF:String = "off";
    
    /** HIDDEN */
    public static const HIDDEN:String = "hidden";
    
    /** SUDDEN */
    public static const SUDDEN:String = "sudden";
    
    /** HID SUD */
    public static const HID_SUD:String = "hidSud";
    
    /** HID+ */
    public static const HID_PLUS:String = "hidPlus";
    
    /** SUD+ */
    public static const SUD_PLUS:String = "sudPlus";
    
    /** HID+SUD+ */
    public static const HID_SUD_PLUS:String = "hidSudPlus";
}

class Style {
    
    /**/
    public static const OFF:String = "off";
    
    /** */
    public static const RANDOM:String = "random";
    
    /** */
    public static const S_RANDOM:String = "sRandom";
    
    /** */
    public static const MIRROR:String = "mirror";
    
    /** */
    public static const RANDOM_PLUS:String = "random+";
    
    /** */
    public static const MIRROR_PLUS:String = "mirror+";
    
    /** */
    public static const S_RANDOM_PLUS:String = "sRandom+";
    
}

class Timing {
    
    /**/
    public static const OFF:String = "off";
    
    /**/
    public static const TYPE_A:String = "typeA";
    
    /**/
    public static const TYPE_B:String = "typeB";
    
    /**/
    public static const TYPE_C:String = "typeC";
    
}

class Difficulty {
    public static const EASY:String = "easy";
    public static const NORMAL:String = "normal";
    public static const HYPER:String = "hyper";
    public static const ANOTHER:String = "another";
    public static const DARK_ANOTHER:String = "darkAnother";
}

class BPM {
    /**
     * constructor
     * @param    _pos
     * @param    _bpm
     */
    public function BPM(_pos:Number, _bpm:Number) {
        this.pos = _pos;
        this.bpm = _bpm;
    }
    
    public var pos:Number;
    public var bpm:Number;
}

class Measure {
    
    /**
     * constructor
     * @param    _beats
     */
    public function Measure(_beats:Vector.<String>) {
        this.beats = _beats;
        this.metrical = _beats.length;
    }
    
    public var metrical:Number;
    public var beats:Vector.<String>;
}

class ChartElement {
    /** タイトル */
    public static const TITLE:String = "TITLE";
    
    /** サブタイトル */
    public static const SUBTITLE:String = "SUBTITLE";
    
    /** アーティスト名 */
    public static const ARTIST:String = "ARTIST";
    
    /** */
    public static const TITLETRANSLIT:String = "TITLETRANSLIT";
    
    /** */
    public static const SUBTITLETRANSLIT:String = "SUBTITLETRANSLIT";
    
    /** */
    public static const ARTISTTRANSLIT:String = "ARTISTTRANSLIT";
    
    /** */
    public static const CREDIT:String = "CREDIT";
    
    /** */
    public static const BANNER:String = "BANNER";
    
    /** */
    public static const BACKGROUND:String = "BACKGROUND";
    
    /** */
    public static const LYRICSPATH:String = "LYRICSPATH";
    
    /** */
    public static const CDTITLE:String = "CDTITLE";
    
    /** 音楽ファイルのパス */
    public static const MUSIC:String = "MUSIC";
    
    /** 再生ヘッドのマージン */
    public static const OFFSET:String = "OFFSET";
    
    /** */
    public static const SAMPLESTART:String = "SAMPLESTART";
    
    /** */
    public static const SAMPLELENGTH:String = "SAMPLELENGTH";
    
    /** */
    public static const SELECTABLE:String = "SELECTABLE";
    
    /** BPM変化の列挙 */
    public static const BPMS:String = "BPMS";
    
    /** */
    public static const STOPS:String = "STOPS";
    
    /** */
    public static const BGCHANGES:String = "BGCHANGES";
    
    /** */
    public static const NOTES:String = "NOTES";
}

class ControlCharacter {
    
    /** 制御文字 */
    public static const CONTROL:uint = 0x1F;
    
    /** 1 */
    public static const FLAG_TRUE:uint = 0x31;
    
    /** 0 */
    public static const FLAG_FALSE:uint = 0x30;
    
    /** , */
    public static const BREAK:uint = 0x2C;
    
}

class Lane {
    public static const LANE_SCRATCH:int = 0;
    public static const LANE_1:int = 1;
    public static const LANE_2:int = 2;
    public static const LANE_3:int = 3;
    public static const LANE_4:int = 4;
    public static const LANE_5:int = 5;
    public static const LANE_6:int = 6;
    public static const LANE_7:int = 7;
}

import flash.display.Shape;
import flash.text.TextFieldAutoSize;
import org.libspark.betweenas3.tweens.ITween;
class Line extends Shape {
    
    /**
     * constructor
     */
    public function Line() {
        this.graphics.lineStyle(1, 0x555555);
        this.graphics.moveTo(0, 6);
        this.graphics.lineTo(206, 6);
        
        this.cacheAsBitmap = true;
        this.opaqueBackground = 0;
    }
    
    /** tween */
    public var tween:ITween;
    
    public var pos:Number = 0;
}

import flash.display.Bitmap;
import flash.display.BitmapData;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.tweens.ITween;
class Note extends Bitmap {
    
    /**
     * constructor
     * @param    bitmapData
     * @param    pixelSnapping
     * @param    smoothing
     */
    public function Note(bitmapData:BitmapData = null, pixelSnapping:String = "auto", smoothing:Boolean = false) {
        super(bitmapData, pixelSnapping, smoothing);
        this.tween = BetweenAS3.tween(this, { } );
        
        this.smoothing = false;
        this.cacheAsBitmap = true;
        this.opaqueBackground = 0;
    }
    
    /** tween */
    public var tween:ITween;
    
    public var pos:Number = 0;
}

class DifficultyView {
    public static const EASY:int = 1;
    public static const NORMAL:int = 2;
    public static const HYPER:int = 3;
    public static const ANOTHER:int = 4;
    public static const DARK_ANOTHER:int = 5;
}

class KeyConfig {
    
    public static var KEY1:int = 90;
    public static var KEY2:int = 83;
    public static var KEY3:int = 88;
    public static var KEY4:int = 68;
    public static var KEY5:int = 67;
    public static var KEY6:int = 70;
    public static var KEY7:int = 86;
    
    public static var START:int = 81;
    public static var SELECT:int = 87;
    public static var SCRATCH_A:int = 16;
    public static var SCRATCH_B:int = 65;
    
}

// *****************************************************************************
// *****************************************************************************
import flash.display.MovieClip;
import com.bit101.components.Label;
class MusicPlayMovieClip extends MovieClip {
    //public var hiSpeedWindow1P:MovieClip = new MovieClip();
    //public var hiSpeedWindow2P:MovieClip = new MovieClip();
    //public var playFrameSkin:MovieClip = new MovieClip();
    //public var playMusicDataView:MovieClip = new MovieClip();
    public var textFieldBPM:Label;
    public var textFieldComboShadow2P:Label;
    
    public function MusicPlayMovieClip() {
        //playFrameSkin.hiSpeedView2P = new MovieClip();
        //playFrameSkin.difficultyView2P = new MovieClip();
        this.graphics.lineStyle(2, 0xFF0000);
        this.graphics.moveTo(30, Main.NOTE_DESTINATION_Y_COORD);
        this.graphics.lineTo(235, Main.NOTE_DESTINATION_Y_COORD);
        
        new Label(this, 30, 350, "BPM");
        textFieldBPM = new Label(this, 60, 350);
        
        new Label(this, 30, 370, "Gauge");
        textFieldComboShadow2P = new Label(this, 60, 370);
    }
}

import flash.text.TextField;
class LaneCoverDefaultSUD extends MovieClip {
    public var textFieldGreen:TextField = new TextField();
    public var textFieldGreenShadow:TextField = new TextField();
    public var textFieldWhite:TextField = new TextField();
    public var textFieldWhiteShadow:TextField = new TextField();
}
class LaneCoverDefaultHID extends MovieClip {
    public var textFieldWhite:TextField = new TextField();
    public var textFieldWhiteShadow:TextField = new TextField();
    
    public function LaneCoverDefaultHID() {
    }
}

class AutoPlayPart5Keys extends MovieClip {
    
}

class AutoPlayPartScr extends MovieClip {
    
}
class Beam extends MovieClip {
    public function Beam(w:int) {
        super();
        
        this.graphics.beginFill(0xFFFFFF, 0.5);
        this.graphics.drawRect( -w / 2, 0, w, -100);
        this.graphics.endFill();
        
        this.visible = false;
    }
    
    public override function gotoAndPlay(frame:Object, scene:String = null):void {
        if (frame == 2) this.visible = true;
        if (frame == 5) this.visible = false;
    }
}

class BeamDefaultScr extends Beam {
    public function BeamDefaultScr() {
        super(35);
    }
}

class BeamDefaultWhite extends Beam {
    public function BeamDefaultWhite() {
        super(27);
    }
}

class BeamDefaultBlack extends Beam {
    public function BeamDefaultBlack() {
        super(27);
    }
}

class JudgeBuilder {
    public static function build(msg:String):TextField {
        var field:TextField = new TextField();
        with (field) {
            text = msg;
            selectable = false;
            textColor = 0xFFFFFF;
            autoSize = TextFieldAutoSize.LEFT;
        }
        
        return field;
    }
}

class JudgePoor extends MovieClip {
    public function JudgePoor() {
        addChild(JudgeBuilder.build("POOR"));
    }
}

class JudgeBad extends MovieClip {
    public function JudgeBad() {
        addChild(JudgeBuilder.build("BAD"));
    }
}

class JudgeGood extends MovieClip {
    public function JudgeGood() {
        addChild(JudgeBuilder.build("GOOD"));
    }
}

class JudgeGreat extends MovieClip {
    public function JudgeGreat() {
        addChild(JudgeBuilder.build("GREAT"));
    }
}

class JudgeJustGreat  extends MovieClip {
    public function JudgeJustGreat() {
        addChild(JudgeBuilder.build("JUST GREAT"));
    }
}

class NoteBlue extends BitmapData {
    public function NoteBlue() {
        super(27, 5, false, 0x0000FF);
    }
}

class NoteWhite extends BitmapData {
    public function NoteWhite() {
        super(27, 5, false, 0x7F7F7F);
    }
}

class NoteRed extends BitmapData {    
    public function NoteRed() {
        super(35, 5, false, 0xFF0000);
    }
}

class GaugeNormal extends MovieClip {
    
}

class GaugeHard extends MovieClip {
    
}

class GraphCover1P extends MovieClip {
    
}
class GraphCover2P extends MovieClip {
    
}

// *****************************************************************************
// *****************************************************************************

//package org.libspark.utils.media
import flash.utils.getTimer;
/**
 * @author yossy:beinteractive
 * @see http://www.libspark.org/wiki/BeatTimer/en
 */
class BeatTimer
{
    public function BeatTimer()
    {
    }
    
    private var _bpm:Number;
    private var _startTime:uint;
    private var _beatPosition:Number;
    private var _phase:Number;
    private var _isOnBeat:Boolean = false;
    
    public function get bpm():Number
    {
        return _bpm;
    }
    
    public function get beatPosition():Number
    {
        return _beatPosition;
    }
    
    public function get phase():Number
    {
        return _phase;
    }
    
    public function get isOnBeat():Boolean
    {
        return _isOnBeat;
    }
    
    public function start(bpm:Number):void
    {
        _bpm = bpm;
        _startTime = getTimer();
        update();
    }
    
    public function update():void
    {
        var currentTime:uint = getTimer();
        var beatInterval:Number = (60 * 1000) / _bpm;
        var oldPosition:Number = _beatPosition;
        
        _beatPosition = (currentTime - _startTime) / beatInterval;
        _phase = _beatPosition - int(_beatPosition);
        _isOnBeat = int(oldPosition) != int(_beatPosition);
    }
}


class F {
    
    public static const MS:String = (<![CDATA[
#OFFSET:0.000;
#BPMS:0.000=80.000;

#NOTES:
// measure 1
00000000
00000000
00000000
00000000
,  // measure 2
10000000
01000000
01000000
01000000
,  // measure 3
01000000
01000000
01000000
01000000
,  // measure 4
00100000
00100000
00000100
00000100
,  // measure 5
00100000
00100000
00010000
00010000
,  // measure 6
01000000
01000000
00000001
00000001
,  // measure 7
01001000
01000000
01000000
01001000
,  // measure 8
00000010
00010000
00000100
01000000
,  // measure 9
00100100
00100100
01001000
01001000
,  // measure 10
10000000
00010000
00000100
00100000
,  // measure 11
01000000
00010000
10000001
00000000
00001000
00001000
10000000
00001000
,  // measure 12
01000000
00010000
10000001
00000000
00100000
00001000
10000000
00001000
,  // measure 13
00000010
00010000
00000101
00000000
00000000
00000000
10010000
00101000
,  // measure 14
01000000
00010000
10000001
00000000
00000000
00000000
10000010
00101000
,  // measure 15
10000000
01000000
00001000
00000000
00000000
00000000
00100000
00100000
,  // measure 16
00000100
00000100
10000000
00000010
00000100
00010000
00010000
00010000
,  // measure 17
01000000
00010000
10000001
00000000
00000000
00000000
10000010
00101000
,  // measure 18
01000000
00010000
10000001
00000000
00000000
00000000
10000010
00101000
,  // measure 19
01000000
00010000
10000001
00000000
00000000
00000000
10000010
00101000
,  // measure 20
01000000
00010000
10000001
00000000
00100000
00001000
10000000
00001000
,  // measure 21
00000010
00010000
00000101
00000000
00000000
00000000
10010000
00101000
,  // measure 22
01000000
00010000
10000001
00000000
00000000
00000000
10000010
00101000
,  // measure 23
10000000
01000000
00001000
00000000
00000000
00000000
00100000
00100000
,  // measure 24
00000100
00000100
10000000
00000010
00000100
00010000
00010000
00010000
,  // measure 25
01000000
00010000
10000001
00000000
00000000
00000000
10000010
00101000
,  // measure 26
01000000
00010000
10000001
00000000
00000000
00000000
10000010
00101000
,  // measure 27
01000000
00010000
10000001
00000000
00000000
00000000
10000010
00101000
,  // measure 28
01000000
01000000
00001001
00000001
,  // measure 29
01001000
01000000
01010000
01001000
,  // measure 30
00000010
00010000
00100100
01000000
,  // measure 31
00100100
00100100
01001000
01001010
,  // measure 32
10000100
00010010
00000100
00100000
,  // measure 33
00100100
01001000
00010000
00000100
00100100
00010000
10000000
00000000
;]]> ).toString();
}

import com.bit101.components.Label;
class Debug {
    private var ta:Label;
    public function Debug($s:Main) {
        ta = new Label($s, 270, 10);
        ta.width = 100;
    }
    
    public function log(msg:*):void {
        ta.text = msg + "\n" + ta.text;
    }
}
";";