2020-10-02 00:35:59 -07:00
|
|
|
/* Copyright (C) 2020 Wildfire Games.
|
2013-06-06 04:13:57 -07:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
|
|
#include "JSInterface_Sound.h"
|
|
|
|
|
|
|
|
|
|
#include "lib/config2.h"
|
|
|
|
|
#include "lib/utf8.h"
|
|
|
|
|
#include "maths/Vector3D.h"
|
|
|
|
|
#include "ps/Filesystem.h"
|
2021-03-02 12:01:14 -08:00
|
|
|
#include "scriptinterface/FunctionWrapper.h"
|
2018-04-27 09:48:44 -07:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2013-06-06 04:13:57 -07:00
|
|
|
#include "soundmanager/SoundManager.h"
|
|
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
namespace JSI_Sound
|
|
|
|
|
{
|
2018-04-24 04:44:26 -07:00
|
|
|
#if CONFIG2_AUDIO
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
void StartMusic()
|
2018-04-24 04:44:26 -07:00
|
|
|
{
|
|
|
|
|
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
|
|
|
|
|
sndManager->SetMusicEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
void StopMusic()
|
2018-04-24 04:44:26 -07:00
|
|
|
{
|
|
|
|
|
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
|
|
|
|
|
sndManager->SetMusicEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
void ClearPlaylist()
|
2018-04-24 04:44:26 -07:00
|
|
|
{
|
|
|
|
|
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
|
|
|
|
|
sndManager->ClearPlayListItems();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
void AddPlaylistItem(const std::wstring& filename)
|
2018-04-24 04:44:26 -07:00
|
|
|
{
|
|
|
|
|
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
|
|
|
|
|
sndManager->AddPlayListItem(VfsPath(filename));
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
void StartPlaylist(bool looping)
|
2018-04-24 04:44:26 -07:00
|
|
|
{
|
|
|
|
|
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
|
|
|
|
|
sndManager->StartPlayList(looping );
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
void PlayMusic(const std::wstring& filename, bool looping)
|
2018-04-24 04:44:26 -07:00
|
|
|
{
|
|
|
|
|
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
|
|
|
|
|
sndManager->PlayAsMusic(filename, looping);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
void PlayUISound(const std::wstring& filename, bool looping)
|
2018-04-24 04:44:26 -07:00
|
|
|
{
|
|
|
|
|
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
|
|
|
|
|
sndManager->PlayAsUI(filename, looping);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
void PlayAmbientSound(const std::wstring& filename, bool looping)
|
2018-04-24 04:44:26 -07:00
|
|
|
{
|
|
|
|
|
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
|
|
|
|
|
sndManager->PlayAsAmbient(filename, looping);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
bool MusicPlaying()
|
2018-04-24 04:44:26 -07:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
void SetMasterGain(float gain)
|
2018-04-24 04:44:26 -07:00
|
|
|
{
|
|
|
|
|
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
|
|
|
|
|
sndManager->SetMasterGain(gain);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
void SetMusicGain(float gain)
|
2018-04-24 04:44:26 -07:00
|
|
|
{
|
|
|
|
|
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
|
|
|
|
|
sndManager->SetMusicGain(gain);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
void SetAmbientGain(float gain)
|
2018-04-24 04:44:26 -07:00
|
|
|
{
|
|
|
|
|
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
|
|
|
|
|
sndManager->SetAmbientGain(gain);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
void SetActionGain(float gain)
|
2018-04-24 04:44:26 -07:00
|
|
|
{
|
|
|
|
|
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
|
|
|
|
|
sndManager->SetActionGain(gain);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
void SetUIGain(float gain)
|
2018-04-24 04:44:26 -07:00
|
|
|
{
|
|
|
|
|
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
|
|
|
|
|
sndManager->SetUIGain(gain);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
bool MusicPlaying( ){ return false; }
|
|
|
|
|
void PlayAmbientSound(const std::wstring& UNUSED(filename), bool UNUSED(looping) ){}
|
|
|
|
|
void PlayUISound(const std::wstring& UNUSED(filename), bool UNUSED(looping) ) {}
|
|
|
|
|
void PlayMusic(const std::wstring& UNUSED(filename), bool UNUSED(looping) ) {}
|
|
|
|
|
void StartPlaylist(bool UNUSED(looping) ){}
|
|
|
|
|
void AddPlaylistItem(const std::wstring& UNUSED(filename) ){}
|
|
|
|
|
void ClearPlaylist( ){}
|
|
|
|
|
void StopMusic( ){}
|
|
|
|
|
void StartMusic( ){}
|
|
|
|
|
void SetMasterGain(float UNUSED(gain)){}
|
|
|
|
|
void SetMusicGain(float UNUSED(gain)){}
|
|
|
|
|
void SetAmbientGain(float UNUSED(gain)){}
|
|
|
|
|
void SetActionGain(float UNUSED(gain)){}
|
|
|
|
|
void SetUIGain(float UNUSED(gain)){}
|
2013-06-10 06:58:43 -07:00
|
|
|
|
2018-04-24 04:44:26 -07:00
|
|
|
#endif
|
|
|
|
|
|
2021-03-02 12:01:14 -08:00
|
|
|
void RegisterScriptFunctions(const ScriptRequest& rq)
|
2018-04-24 04:44:26 -07:00
|
|
|
{
|
2021-03-02 12:01:14 -08:00
|
|
|
ScriptFunction::Register<&StartMusic>(rq, "StartMusic");
|
|
|
|
|
ScriptFunction::Register<&StopMusic>(rq, "StopMusic");
|
|
|
|
|
ScriptFunction::Register<&ClearPlaylist>(rq, "ClearPlaylist");
|
|
|
|
|
ScriptFunction::Register<&AddPlaylistItem>(rq, "AddPlaylistItem");
|
|
|
|
|
ScriptFunction::Register<&StartPlaylist>(rq, "StartPlaylist");
|
|
|
|
|
ScriptFunction::Register<&PlayMusic>(rq, "PlayMusic");
|
|
|
|
|
ScriptFunction::Register<&PlayUISound>(rq, "PlayUISound");
|
|
|
|
|
ScriptFunction::Register<&PlayAmbientSound>(rq, "PlayAmbientSound");
|
|
|
|
|
ScriptFunction::Register<&MusicPlaying>(rq, "MusicPlaying");
|
|
|
|
|
ScriptFunction::Register<&SetMasterGain>(rq, "SetMasterGain");
|
|
|
|
|
ScriptFunction::Register<&SetMusicGain>(rq, "SetMusicGain");
|
|
|
|
|
ScriptFunction::Register<&SetAmbientGain>(rq, "SetAmbientGain");
|
|
|
|
|
ScriptFunction::Register<&SetActionGain>(rq, "SetActionGain");
|
|
|
|
|
ScriptFunction::Register<&SetUIGain>(rq, "SetUIGain");
|
2018-04-24 04:44:26 -07:00
|
|
|
}
|
2013-06-10 06:58:43 -07:00
|
|
|
}
|