diff --git a/apps/openmw/mwlua/soundbindings.cpp b/apps/openmw/mwlua/soundbindings.cpp index dc45a672b4..c3c810e591 100644 --- a/apps/openmw/mwlua/soundbindings.cpp +++ b/apps/openmw/mwlua/soundbindings.cpp @@ -23,6 +23,11 @@ namespace float mTimeOffset = 0.f; }; + struct StreamMusicArgs + { + float mFade = 1.f; + }; + PlaySoundArgs getPlaySoundArgs(const sol::optional& options) { PlaySoundArgs args; @@ -55,6 +60,17 @@ namespace return MWSound::PlayMode::NoEnvNoScaling; return MWSound::PlayMode::NoEnv; } + + StreamMusicArgs getStreamMusicArgs(const sol::optional& options) + { + StreamMusicArgs args; + + if (options.has_value()) + { + args.mFade = options->get_or("fadeOut", 1.f); + } + return args; + } } namespace MWLua @@ -95,9 +111,10 @@ namespace MWLua return MWBase::Environment::get().getSoundManager()->getSoundPlaying(MWWorld::Ptr(), fileName); }; - api["streamMusic"] = [](std::string_view fileName) { + api["streamMusic"] = [](std::string_view fileName, const sol::optional& options) { + auto args = getStreamMusicArgs(options); MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); - sndMgr->streamMusic(std::string(fileName), MWSound::MusicType::Scripted); + sndMgr->streamMusic(std::string(fileName), MWSound::MusicType::Scripted, args.mFade); }; api["isMusicPlaying"] = []() { return MWBase::Environment::get().getSoundManager()->isMusicPlaying(); }; diff --git a/files/lua_api/openmw/ambient.lua b/files/lua_api/openmw/ambient.lua index 917ec86c85..7153a6fb44 100644 --- a/files/lua_api/openmw/ambient.lua +++ b/files/lua_api/openmw/ambient.lua @@ -12,7 +12,7 @@ -- @param #string soundId ID of Sound record to play -- @param #table options An optional table with additional optional arguments. Can contain: -- --- * `timeOffset` - a floating point number >= 0, to some time (in second) from beginning of sound file (default: 0); +-- * `timeOffset` - a floating point number >= 0, to skip some time (in seconds) from beginning of sound file (default: 0); -- * `volume` - a floating point number >= 0, to set a sound volume (default: 1); -- * `pitch` - a floating point number >= 0, to set a sound pitch (default: 1); -- * `scale` - a boolean, to set if sound pitch should be scaled by simulation time scaling (default: true); @@ -32,7 +32,7 @@ -- @param #string fileName Path to sound file in VFS -- @param #table options An optional table with additional optional arguments. Can contain: -- --- * `timeOffset` - a floating point number >= 0, to some time (in second) from beginning of sound file (default: 0); +-- * `timeOffset` - a floating point number >= 0, to skip some time (in seconds) from beginning of sound file (default: 0); -- * `volume` - a floating point number >= 0, to set a sound volume (default: 1); -- * `pitch` - a floating point number >= 0, to set a sound pitch (default: 1); -- * `scale` - a boolean, to set if sound pitch should be scaled by simulation time scaling (default: true); @@ -76,7 +76,13 @@ -- Play a sound file as a music track -- @function [parent=#ambient] streamMusic -- @param #string fileName Path to file in VFS --- @usage ambient.streamMusic("Music\\Test\\Test.mp3"); +-- @param #table options An optional table with additional optional arguments. Can contain: +-- +-- * `fadeOut` - a floating point number >= 0, time (in seconds) to fade out current track before playing this one (default 1.0); +-- @usage local params = { +-- fadeOut=2.0 +-- }; +-- ambient.streamMusic("Music\\Test\\Test.mp3", params) --- -- Stop to play current music