<ActorFrame><children>

    <Layer
        Type= "Quad"
        InitCommand= "hidden,1;sleep,9999"
    />

    <Layer
        Type= "Quad"
        OnCommand="%function(self)

            ------------------------
            -- Const
            ------------------------

            UPDATE = 'Update';
            BASE_BPM = 219;

            ------------------------
            -- Function
            ------------------------
            --[[
                Rateオプションの値を取得
            ]]
            function getRateMod()
                local so = SCREENMAN:GetTopScreen():GetChild('SongOptions')
                local s = '';
                if not so then
                    return 1.0;
                else
                    s = so:GetText();
                end

                if not s then
                    return 1.0;
                end;

                local fbegin = string.find(s,'.',1,true);
                local fend = string.find(s,'xMusic');
                if fbegin and fend then
                    return tonumber(string.sub(s,fbegin-1,fend-1));
                else
                    return 1.0;
                end
            end

            --[[
                プレイヤーの使用しているHiSpeedオプションを取得
                @args プレイヤー1Pまたは2P (0,1)
            ]]
            function getPlayerHiSpeed(player)
                local hispeed = 1.0;
                for i = 1, 160 do
                    if (GAMESTATE:PlayerIsUsingModifier(player, tostring(i*0.05)..'x')) then
                        hispeed = i*0.05;
                    end
                end
                return hispeed;
            end

            --[[
                ノートの位置拍数を求める
                @args (小節,小節内の拍数,端数 1以下の値)
            ]]
            function calcBeat(measure, beat, fraction)
                return (measure-1) * 4.0 + beat + fraction;
            end

            --[[
                指定した拍数にかかる時間を求める
                @args (拍数, BPM)
            ]]
            function calcTime(beatLength, bpm)
                return beatLength * (60.0/bpm);
            end

            function getSpeedTime(beatLength)
                return 1.0/calcTime(beatLength, BASE_BPM);
            end

            function getTimeString(beatLength, bpm)
                return '*' .. tostring(1.0/calcTime(beatLength, bpm));
            end

            function getTimeString(beatLength)
                return '*' .. tostring(1.0/calcTime(beatLength, BASE_BPM));
            end

            --[[
                スピード変更Mod
                @args (変更速度, 値)
            ]]
            function ApplyXMod(velocity, value)
                GAMESTATE:ApplyGameCommand('mod, *'..tostring(velocity*hfvP1)..' '..tostring(hispeedP1*value)..'x', 1);
                GAMESTATE:ApplyGameCommand('mod, *'..tostring(velocity*hfvP2)..' '..tostring(hispeedP2*value)..'x', 2);
            end

            --[[
                フレーム待機
            ]]
            function WaitFrame()
				self:sleep(0.02);
            end

            --[[
                Modsを更新
                @args (Beat位置)
            ]]
            function UpdateMods(beat)

                -- Modループ
                for m, mod in ipairs(mods) do
                    if (beat >= mod[1] and lastBeat < mod[1]) then
                        GAMESTATE:ApplyGameCommand('mod, '..mod[2]);
                    elseif (beat < mod[1]) then
                        break
                    end
                end

                -- SpeedModループ
                for e, event in ipairs(speedMods) do
                    if (beat >= event[1] and lastBeat < event[1]) then
                        -- if (event[2] == 'A0') then
                        --     ApplyXMod(10000, 0.01);
                        -- end
                        -- if (event[2] == 'A1') then
                        --     ApplyXMod(10000, 1);
                        -- end
                    elseif (beat < event[1]) then
                        break
                    end
                end

                lastBeat = beat;

            end

            -----------------------
            -- Mod Event
            -----------------------
            -- Gimmik Mod
            mods = {
                {calcBeat(19, 1, 0), '*100000 50.0% stealth'},
                {calcBeat(21, 0, 0), '*1 No stealth'},
                {calcBeat(89, 3, 0), '*10000 50% Stealth, *2 100% Dark'},
                {calcBeat(90, 2, 0), '*10000 50% Stealth'},
                {calcBeat(90, 2, 1/12), '*10000 100% Stealth'},
                {calcBeat(90, 3, 0), '*10000 50% Stealth'},
                {calcBeat(90, 3, 1/12), '*10000 100% Stealth'},
                {calcBeat(91, 0, 0), '*10000 50% Stealth'},
                {calcBeat(91, 0, 1/12), '*10000 100% Stealth'},
                {calcBeat(91, 1, 0), '*10000 50% Stealth'},
                {calcBeat(91, 1, 1/12), '*10000 100% Stealth'},
                {calcBeat(91, 2, 0), '*10000 50% Stealth'},
                {calcBeat(91, 2, 1/12), '*10000 100% Stealth'},
                {calcBeat(91, 3, 0), '*10000 50% Stealth'},
                {calcBeat(91, 3, 1/12), '*10000 100% Stealth'},
                {calcBeat(92, 0, 0), '*10000 50% Stealth'},
                {calcBeat(92, 0, 1/12), '*10000 100% Stealth'},
                {calcBeat(92, 1, 0), '*1 No Stealth, *10000 No Dark'},
                {calcBeat(113, 0, 1/2), '*5 2500% Confusion'},
                {calcBeat(113, 0, 1/2), '*0.1700 50% Flip'},
                {calcBeat(113, 0, 3/4), '*100000 -7% Flip, *100000 -25% Mini, *65535 No Confusion'},
                {calcBeat(113, 0, 7/8), '*100000 No Flip, *100000 No Mini'}
            }

            -- SpeedMod
            speedMods = {
            }

            -----------------------
            -- Cache
            -----------------------
            lastBeat = -16.0;
            hispeedP1 = getPlayerHiSpeed(0);
            hispeedP2 = getPlayerHiSpeed(1);

            hfvP1 = hispeedP1 / getRateMod();
            hfvP2 = hispeedP2 / getRateMod();
            -----------------------

            self:sleep(1);
            self:queuecommand( UPDATE );
        end"

        UpdateCommand="%function(self)
            beat = GAMESTATE:GetSongBeat();
            UpdateMods(beat);
            WaitFrame();
            self:queuecommand( UPDATE );
        end"
    />

</children></ActorFrame>