<commit_before>--
-- Provides ability to turn on/off and fade music in/out.
--
-- @copyright (c) 2015 Upstart Illustration LLC. All rights reserved.
--

require("Logger")

Music = Class()

local engine = cc.SimpleAudioEngine:getInstance()

function Music.new(self)
    local tweenId
    local _bgPath
    local isOn = true

    function self.preload(path)
        engine:preloadMusic(path)
    end

    function self.play(path, loop)
        engine:playMusic(path, loop)
    end

    function self.stop(release)
        engine:stopMusic(release)
    end

    function self.setVolume(to)
        engine:setMusicVolume(to)
    end
    
    function self.pause()
        engine:pauseMusic()
    end

    function self.resume()
        engine:resumeMusic()
    end

    function self.turnOn(vol)
        Log.i("Music.on(%d)", vol)
        isOn = true
        self.fadeTo(vol, 0.5, nil, _bgPath)
    end

    function self.turnOff()
        Log.i("Music.off()")
        self.fadeTo(0, 0.5, function()
            self.stop(true)
        end)
        isOn = false
    end

    function self.fadeTo(to, length, bgPath)
        local p = Promise()
        -- Always set the bg path so that when the sound is turned back on
        -- it can be loaded.
        if bgPath then
            _bgPath = bgPath
        end
        if not isOn then
            Log.d("fadeTo Off")
            p.resolve()
            return p
        end
        Log.d("Starting music...")
        if tweenId then
            Log.w("Attempting to fade music in before the previous transition is over!")
            cu.unscheduleFunc(tweenId)
            tweenId = nil
        end
        local from<commit_msg>Music turn on/off methods now work<commit_after>--
-- Provides ability to turn on/off and fade music in/out.
--
-- @copyright (c) 2015 Upstart Illustration LLC. All rights reserved.
--

require("Logger")

Music = Class()

local engine = cc.SimpleAudioEngine:getInstance()

function Music.new(self)
    local tweenId
    local _bgPath
    local isOn = true

    function self.preload(path)
        engine:preloadMusic(path)
    end

    function self.play(path, loop)
        engine:playMusic(path, loop)
    end

    function self.stop(release)
        engine:stopMusic(release)
    end

    function self.setVolume(to)
        engine:setMusicVolume(to)
    end
    
    function self.pause()
        engine:pauseMusic()
    end

    function self.resume()
        engine:resumeMusic()
    end

    function self.turnOn(vol)
        Log.i("Music.on(%f)", vol)
        isOn = true
        self.fadeTo(vol, 0.5, _bgPath)
    end

    function self.turnOff()
        Log.i("Music.off()")
        local promise = self.fadeTo(0, 0.5)
        promise.done(function()
            self.stop(true)
        end)
        isOn = false
    end

    function self.fadeTo(to, length, bgPath)
        local p = Promise()
        -- Always set the bg path so that when the sound is turned back on
        -- it can be loaded.
        if bgPath then
            _bgPath = bgPath
        end
        if not isOn then
            Log.d("fadeTo Off")
            p.resolve()
            return p
        end
        Log.d("Starting music...")
        if tweenId then
            Log.w("Attempting to fade music in before the previous transition is over!")
            cu.unscheduleFunc(tweenId)
            tweenId = nil
        end
        local from
{'fraction_non_alphanumeric': 0.09421778690930438, 'fraction_numerical': 0.005283240387437629, 'mean_word_length': 1.84, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5952915', 'n_tokens_mistral': 1043, 'n_tokens_neox': 1005, 'n_words': 295}