Skip to content

Commit

Permalink
继续调整fmod遇到异常情况的反应
Browse files Browse the repository at this point in the history
  • Loading branch information
MrZ626 committed Jun 28, 2024
1 parent d881293 commit 7e2d16a
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions assets/fmod20221/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ M.music={}
function M.music.setVolume(v,instant)
M.musicVolume=v
if not studio then return end
local res=studio:setParameterByName('MusicVolume',M.mainVolume*M.musicVolume,instant==true)
assert(res==M.FMOD_OK,M.errorString[res])
studio:setParameterByName('MusicVolume',M.mainVolume*M.musicVolume,instant==true)
end

---@type {desc:FMOD.Studio.EventDescription?, event:FMOD.Studio.EventInstance?}?
Expand All @@ -171,9 +170,7 @@ end
function M.music.getParamDesc(name,param)
local desc=musicLib[name]
if not desc then return end
local paraDesc,res=musicLib[name]:getParameterDescriptionByName(param)
assert(res==M.FMOD_OK,M.errorString[res])
return paraDesc
return (musicLib[name]:getParameterDescriptionByName(param))
end

---@param name string
Expand Down Expand Up @@ -250,8 +247,7 @@ end
---@return number?,number?
function M.music.getParam(param)
if not studio or not playing then return end
local v,fv,res=playing.event:getParameterByName(param)
assert(res==M.FMOD_OK,M.errorString[res])
local v,fv=playing.event:getParameterByName(param)
return v,fv
end

Expand All @@ -260,15 +256,13 @@ end
---@param instant? boolean only `true` take effect
function M.music.setParam(param,value,instant)
if not studio or not playing then return end
local res=playing.event:setParameterByName(param,value,instant==true)
assert(res==M.FMOD_OK,M.errorString[res])
return playing.event:setParameterByName(param,value,instant==true)
end

---@param time number seconds
function M.music.seek(time)
if not studio or not playing then return end
local res=playing.event:setTimelinePosition(time*1000)
assert(res==M.FMOD_OK,M.errorString[res])
return playing.event:setTimelinePosition(time*1000)
end

---@return number
Expand Down Expand Up @@ -302,8 +296,7 @@ M.effect={}
function M.effect.setVolume(v,instant)
M.effectVolume=v
if not studio then return end
local res=studio:setParameterByName('EffectVolume',M.mainVolume*M.effectVolume,instant==true)
assert(res==M.FMOD_OK,M.errorString[res])
return studio:setParameterByName('EffectVolume',M.mainVolume*M.effectVolume,instant==true)
end

---Get event description by name, to check if a music exists
Expand All @@ -329,7 +322,10 @@ function M.effect.play(name,args)
return
end
local event,res=desc:createInstance()
assert(res==M.FMOD_OK,M.errorString[res])
if res~=M.FMOD_OK then
MSG.new('warn',"Play SE '"..name.."' failed: "..M.errorString[res])
return
end

if args then
assert(type(args)=='table',"args must be table")
Expand Down Expand Up @@ -417,8 +413,7 @@ M.vocal={}
function M.vocal.setVolume(v,instant)
M.vocalVolume=v
if not studio then return end
local res=studio:setParameterByName('VocalVolume',M.mainVolume*M.vocalVolume,instant==true)
assert(res==M.FMOD_OK,M.errorString[res])
return studio:setParameterByName('VocalVolume',M.mainVolume*M.vocalVolume,instant==true)
end

--------------------------------------------------------------
Expand Down

0 comments on commit 7e2d16a

Please sign in to comment.