<commit_before>/*
 *  SoundSet.js
 *  2014/11/28
 *  @auther minimo  
 *  This Program is MIT license.
 *
 */

//fBA^Cv
MEDIA_ASSET = 0;    //tmlibAZbg
MEDIA_URL = 1;      //PhoneGapMedia

//fBAǗ
tm.define("shotgun.SoundSet", {
    elements: null,

    bgm: null,
    bgmIsPlay: false,

    volumeBGM: 3,
    volumeSE: 3,

    init: function() {
        this.elements = [];
    },

    add: function(name, url) {
        if (name === undefined) return null;
        url = url || null;
        var type = 0;
        if (url) type = MEDIA_URL; else type = MEDIA_ASSET;
        var e = shotgun.SoundElement(type, name, url);
        this.elements.push(e);
        return this;
    },

    find: function(name) {
        for (var i = 0; i < this.elements.length; i++) {
            if (this.elements[i].name == name) return this.elements[i];
        }
        return null;
    },

    playBGM: function(name) {
        if (this.bgm) {
            this.bgm.stop();
            this.bgmIsPlay = false;
        }
        var media = this.find(name);
        if (media) {
            media.play(true);
            media.setVolume(this.volumeBGM);
            this.bgm = media;
            this.bgmIsPlay = true;
        }
        return this;
    },

    stopBGM: function() {
        if (this.bgm) {
            if (this.bgmIsPlay) {
                this.bgm.stop();
                this.bgmIsPlay = false;
            }
            this.bgm = null;
        }
        return this;
    },

    pauseBGM: function() {
        if (this.bgm) {
            if (this.bgmIsPlay) {
                this.bgm.pause();
                this.bgmIsPlay = false;
            }
        }
        return this;
    },

    resumeBGM: function() {
        if (this.bgm) {
            if (!this.bgmIsPlay) {
                this.bgm.volume = this.volumeBGM*0.34;
                this.bgm.resume();
                this.bgmIsPlay = true;
            }
        }
        return this;
    },

    setVolumeBGM: function(v) {
        this.volumeSE = Math.Clamp(v, 0, 1);
        return this;
    },

    playSE: function(name) {
        var media = this.find(name);
        if (media) {
            media.setVolume(this.volumeSE);
            media.playClone();
        }
        return this;
    },

    setVolumeSE: function(v) {
        this.volumeSE = Math.Clamp(v, 0, 1);
        return this;
    },
});

tm.define("shotgun.SoundElement", {
    type: 0,
    name: null,
    url: null,
    media: null,
    volume: 1.0,
    status: null,
    init: function(type, name, url) {
        this.type = type;
        this.name = name;
        this.url = url || null;

        if (type == MEDIA_ASSET) {
            this.media = tm.asset.AssetManager.get(name);
        } else if (type == MEDIA_URL) {
            var that = this;
            this.media = new Media(url, function(){
                that.status="OK";
//                AdvanceAlert("OK:"+url);
            }, function(err){
                that.status="NG";
//                AdvanceAlert("NG:"+err+":"+url);
            });
        }
    },

    play: function(loop) {
        if (!this.media) return this;
        if (this.type == MEDIA_URL) {
            if (loop) {
                this.media.play({numberOfLoops:9999, playAudioWhenScreenIsLocked : false});
            } else {
                this.media.play({playAudioWhenScreenIsLocked : false});
            }
        } else {
            this.media.loop = loop;
            this.media.play();
        }
        return this;
    },

    playClone: function() {
        if (!this.media) return this;
        if (this.type == MEDIA_URL) {
            var tmp = new Media(this.url);
            tmp.play();
            tmp = null;
        } else {
            this.media.loop = false;
            this.media.clone().play();
        }
        return this;
    },

    stop: function() {
        if (!this.media) return this;
        this.media.stop();
        return this;
    },

    setVolume: function(vol) {
        if (!this.media) return this;
        vol = vol || 1.0;
        this.volume = Math.clamp(vol, 0.0, 1.0);
        this.media.volume = this.volume;
        return this;
    },
});<commit_msg>ハイブリッド化<commit_after>/*
 *  SoundSet.js
 *  2014/11/28
 *  @auther minimo  
 *  This Program is MIT license.
 *
 */

//fBA^Cv
MEDIA_ASSET = 0;    //tmlibAZbg
MEDIA_CORDOVA = 1;  //CordovaMediaPlugin
MEDIA_LLA = 2;      //LawLaytensyAudioPlugin

//fBAǗ
tm.define("shotgun.SoundSet", {
    defaultType = MEDIA_ASSET,
    elements: null,

    bgm: null,
    bgmIsPlay: false,

    volumeBGM: 3,
    volumeSE: 3,

    init: function() {
        this.elements = [];
    },

    add: function(name, url) {
        if (name === undefined) return null;
        url = url || null;
        var type = 0;
        if (url) type = MEDIA_URL; else type = MEDIA_ASSET;
        var e
        switch(this.defaultType) {
            case MEDIA_ASSET:
                e = shotgun.SoundElement_WebAudio(name);
                break;
            case MEDIA_CORDOVA:
                e = shotgun.SoundElement_Cordova(name, url);
                break;
            case MEDIA_LLA:
                e = shotgun.SoundElement_LLA(name, url);
                break;
        }
        this.elements.push(e);
        return this;
    },

    find: function(name) {
        for (var i = 0; i < this.elements.length; i++) {
            if (this.elements[i].name == name) return this.elements[i];
        }
        return null;
    },

    playBGM: function(name) {
        if (this.bgm) {
            this.bgm.stop();
            this.bgmIsPlay = false;
        }
        var media = this.find(name);
        if (media) {
            media.play(true);
            media.setVolume(this.volumeBGM);
            this.bgm = media;
            this.bgmIsPlay = true;
        }
        return this;
    },

    stopBGM: function() {
        if (this.bgm) {
            if (this.bgmIsPlay) {
                this.bgm.stop();
                this.bgmIsPlay = false;
            }
            this.bgm = null;
        }
        return this;
    },

    pauseBGM: function() {
        if (this.bgm) {
            if (this.bgmIsPlay) {
                this.bgm.pause();
                this.bgmIsPlay = false;
            }
        }
        return this;
    },

    resumeBGM: function() {
        if (this.bgm) {
            if (!this.bgmIsPlay) {
                this.bgm.volume = this.volumeBGM*0.34;
                this.bgm.resume();
                this.bgmIsPlay = true;
            }
        }
        return this;
    },

    setVolumeBGM: function(v) {
        this.volumeSE = Math.Clamp(v, 0, 1);
        return this;
    },

    playSE: function(name) {
        var media = this.find(name);
        if (media) {
            media.setVolume(this.volumeSE);
            media.playClone();
        }
        return this;
    },

    setVolumeSE: function(v) {
        this.volumeSE = Math.Clamp(v, 0, 1);
        return this;
    },
});

//TEhvf{
tm.define("shotgun.SoundElement", {

    type: 0,
    name: null,
    url: null,
    media: null,
    volume: 1.0,
    status: null,

    init: function(type, name, url) {
        this.type = type;
        this.name = name;
        this.url = url || null;
    },

    play: function(loop) {
        return this;
    },

    playClone: function() {
        return this;
    },

    pause: function () {
        if (!this.media) return this;
        this.media.pause();
    },

    stop: function() {
        if (!this.media) return this;
        this.media.stop();
        return this;
    },

    setVolume: function(vol) {
        if (!this.media) return this;
        vol = vol || 1.0;
        this.volume = Math.clamp(vol, 0.0, 1.0);
        this.media.volume = this.volume;
        return this;
    },
});

//TEhvf(WebAudio/tmlibAsset)
tm.define("shotgun.SoundElement_WebAudio", {
    superClass: shotgun.SoundElement,

    init: function(name) {
        this.superInit(MEDIA_ASSET, name);
        this.media = tm.asset.AssetManager.get(name);
    },

    play: function(loop) {
        if (!this.media) return this;
        this.media.loop = loop;
        this.media.play();
        return this;
    },

    playClone: function() {
        this.media.loop = false;
        this.media.clone().play();
        return this;
    },
});

//TEhvf(CordovaMediaPlugin)
tm.define("shotgun.SoundElement_CordovaMedia", {
    superClass: shotgun.SoundElement,

    init: function(name, url) {
        this.superInit(MEDIA_CORDOVA, name, url);

        var that = this;
        this.media = new Media(url, function(){
            that.status="OK";
//            AdvanceAlert("OK:"+url);
        }, function(err){
            that.status="NG";
//            AdvanceAlert("NG:"+err+":"+url);
        });
    },

    play: function(loop) {
        if (!this.media) return this;
        if (loop) {
            this.media.play({numberOfLoops:9999, playAudioWhenScreenIsLocked : false});
        } else {
            this.media.play({playAudioWhenScreenIsLocked : false});
        }
        return this;
    },

    playClone: function() {
        if (!this.media) return this;
        var tmp = new Media(this.url);
        tmp.play();
        tmp = null;
        return this;
    },
});

//TEhvf(LowLaytensyAudioPlugin)
tm.define("shotgun.SoundElement_LLA", {
    init: function(name, url) {
        this.superInit(MEDIA_LLA, name, url);

        window.plugins.LowLatencyAudio.preloadFX(this.name, url, function(msg){}, function(msg){alert( 'Error: ' + msg)});
    },

    play: function(loop) {
        if (!this.media) return this;
        if (loop) {
            window.plugins.LowLatencyAudio.loop(this.name);
        } else {
            window.plugins.LowLatencyAudio.play(this.name);
        }
        return this;
    },

    playClone: function() {
        if (!this.media) return this;
        window.plugins.LowLatencyAudio.play(this.name);
        return this;
    },

    stop: function() {
        if (!this.media) return this;
        window.plugins.LowLatencyAudio.stop(this.name);
        return this;
    },

    pause: function () {
        if (!this.media) return this;
        window.plugins.LowLatencyAudio.stop(this.name);
    },

    setVolume: function(vol) {
        if (!this.media) return this;
        vol = vol || 1.0;
        this.volume = vol;
        window.plugins.LowLatencyAudio.unload(this.name);
        window.plugins.LowLatencyAudio.preloadAudio(this.name, url, vol, 1, function(msg){}, function(msg){alert( 'Error: ' + msg)});
        return this;
    },
});
{'fraction_non_alphanumeric': 0.13664244597527603, 'fraction_numerical': 0.006794375766726432, 'mean_word_length': 1.5611406476558725, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3573795', 'n_tokens_mistral': 3514, 'n_tokens_neox': 3382, 'n_words': 679}