Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSInterface_Sound.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2013 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #include "precompiled.h"
19 
20 #include "JSInterface_Sound.h"
21 
22 #include "lib/config2.h"
23 #include "lib/utf8.h"
24 #include "maths/Vector3D.h"
25 #include "ps/Filesystem.h"
27 
28 #include <sstream>
29 
30 namespace JSI_Sound
31 {
32  #if CONFIG2_AUDIO
33 
34  void StartMusic(void* UNUSED(cbdata))
35  {
36  if ( CSoundManager* sndManager = (CSoundManager*)g_SoundManager )
37  sndManager->SetMusicEnabled(true);
38  }
39 
40  void StopMusic(void* UNUSED(cbdata))
41  {
42  if ( CSoundManager* sndManager = (CSoundManager*)g_SoundManager )
43  sndManager->SetMusicEnabled(false);
44  }
45 
46  void ClearPlaylist(void* UNUSED(cbdata))
47  {
48  if ( CSoundManager* sndManager = (CSoundManager*)g_SoundManager )
49  sndManager->ClearPlayListItems();
50  }
51 
52  void AddPlaylistItem(void* UNUSED(cbdata), std::wstring filename)
53  {
54  if ( CSoundManager* sndManager = (CSoundManager*)g_SoundManager )
55  sndManager->AddPlayListItem(VfsPath(filename));
56  }
57 
58  void StartPlaylist(void* UNUSED(cbdata), bool looping)
59  {
60  if ( CSoundManager* sndManager = (CSoundManager*)g_SoundManager )
61  sndManager->StartPlayList( looping );
62  }
63 
64  void PlayMusic(void* UNUSED(cbdata), std::wstring filename, bool looping)
65  {
66  if ( CSoundManager* sndManager = (CSoundManager*)g_SoundManager )
67  sndManager->PlayAsMusic( filename, looping);
68  }
69 
70  void PlayUISound(void* UNUSED(cbdata), std::wstring filename, bool looping)
71  {
72  if ( CSoundManager* sndManager = (CSoundManager*)g_SoundManager )
73  sndManager->PlayAsUI( filename, looping);
74  }
75 
76  void PlayAmbientSound(void* UNUSED(cbdata), std::wstring filename, bool looping)
77  {
78  if ( CSoundManager* sndManager = (CSoundManager*)g_SoundManager )
79  sndManager->PlayAsAmbient( filename, looping);
80  }
81 
82  bool MusicPlaying(void* UNUSED(cbdata))
83  {
84  return true;
85  }
86 
87 
88 
89  #else
90  bool MusicPlaying(void* UNUSED(cbdata) ){ return false; }
91  void PlayAmbientSound(void* UNUSED(cbdata), std::wstring UNUSED(filename), bool UNUSED(looping) ){}
92  void PlayUISound(void* UNUSED(cbdata), std::wstring UNUSED(filename), bool UNUSED(looping) ) {}
93  void PlayMusic(void* UNUSED(cbdata), std::wstring UNUSED(filename), bool UNUSED(looping) ) {}
94  void StartPlaylist(void* UNUSED(cbdata), bool UNUSED(looping) ){}
95  void AddPlaylistItem(void* UNUSED(cbdata), std::wstring UNUSED(filename) ){}
96  void ClearPlaylist(void* UNUSED(cbdata) ){}
97  void StopMusic(void* UNUSED(cbdata) ){}
98  void StartMusic(void* UNUSED(cbdata) ){}
99 
100  #endif
101 
102 
104  {
105  scriptInterface.RegisterFunction<void, &StartMusic>("StartMusic");
106  scriptInterface.RegisterFunction<void, &StopMusic>("StopMusic");
107  scriptInterface.RegisterFunction<void, &ClearPlaylist>("ClearPlaylist");
108  scriptInterface.RegisterFunction<void, std::wstring, &AddPlaylistItem>("AddPlaylistItem");
109  scriptInterface.RegisterFunction<void, bool, &StartPlaylist>("StartPlaylist");
110  scriptInterface.RegisterFunction<void, std::wstring, bool, &PlayMusic>("PlayMusic");
111  scriptInterface.RegisterFunction<void, std::wstring, bool, &PlayUISound>("PlayUISound");
112  scriptInterface.RegisterFunction<void, std::wstring, bool, &PlayAmbientSound>("PlayAmbientSound");
113  scriptInterface.RegisterFunction<bool, &MusicPlaying>("MusicPlaying");
114  }
115 }
116 
117 
void PlayMusic(void *cbdata, std::wstring filename, bool looping)
void ClearPlaylist(void *cbdata)
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
Path VfsPath
VFS path of the form &quot;(dir/)*file?&quot;.
Definition: vfs_path.h:40
ISoundManager * g_SoundManager
void PlayUISound(void *cbdata, std::wstring filename, bool looping)
void StartPlaylist(void *cbdata, bool looping)
void StopMusic(void *cbdata)
void StartMusic(void *cbdata)
void PlayAmbientSound(void *cbdata, std::wstring filename, bool looping)
void AddPlaylistItem(void *cbdata, std::wstring filename)
void RegisterScriptFunctions(ScriptInterface &scriptInterface)
Abstraction around a SpiderMonkey JSContext.
bool MusicPlaying(void *cbdata)