mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
robustify Fmod, Miles support on Windows and OSX
This commit is contained in:
parent
e2c38edb6f
commit
285622c36f
@ -21,9 +21,15 @@
|
||||
#include "audioManager.h"
|
||||
#include "atomicAdjust.h"
|
||||
#include "nullAudioManager.h"
|
||||
|
||||
#include "windowsRegistry.h"
|
||||
#include "virtualFileSystem.h"
|
||||
#include "config_util.h"
|
||||
#include "load_dso.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h> // For GetSystemDirectory()
|
||||
#endif
|
||||
|
||||
|
||||
TypeHandle AudioManager::_type_handle;
|
||||
|
||||
@ -287,3 +293,47 @@ float AudioManager::audio_3d_get_drop_off_factor() const {
|
||||
// intentionally blank.
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: AudioManager::get_dls_pathname
|
||||
// Access: Public
|
||||
// Description: Returns the full pathname to the DLS file, as
|
||||
// specified by the Config.prc file, or the default for
|
||||
// the current OS if appropriate. Returns empty string
|
||||
// if the DLS file is unavailable.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
Filename AudioManager::
|
||||
get_dls_pathname() {
|
||||
Filename dls_filename = audio_dls_file;
|
||||
if (!dls_filename.empty()) {
|
||||
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
|
||||
vfs->resolve_filename(dls_filename, get_sound_path()) ||
|
||||
vfs->resolve_filename(dls_filename, get_model_path());
|
||||
|
||||
return dls_filename;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
Filename pathname;
|
||||
|
||||
// Get the registry key from DirectMusic
|
||||
string os_filename = WindowsRegistry::get_string_value("SOFTWARE\\Microsoft\\DirectMusic", "GMFilePath", "");
|
||||
|
||||
if (!os_filename.empty()) {
|
||||
pathname = Filename::from_os_specific(os_filename);
|
||||
} else {
|
||||
char sysdir[MAX_PATH+1];
|
||||
GetSystemDirectory(sysdir,MAX_PATH+1);
|
||||
pathname = Filename(Filename::from_os_specific(sysdir), Filename("drivers/gm.dls"));
|
||||
}
|
||||
pathname.make_true_case();
|
||||
return pathname;
|
||||
|
||||
#elif defined(IS_OSX)
|
||||
// This appears to be the standard place for this file on OSX 10.4.
|
||||
return Filename("/System/Library/Components/CoreAudio.component/Contents/Resources/gs_instruments.dls");
|
||||
|
||||
#else
|
||||
return Filename();
|
||||
#endif
|
||||
}
|
||||
|
@ -216,6 +216,8 @@ PUBLISHED:
|
||||
virtual void audio_3d_set_drop_off_factor(float factor);
|
||||
virtual float audio_3d_get_drop_off_factor() const;
|
||||
|
||||
Filename get_dls_pathname();
|
||||
|
||||
public:
|
||||
static void register_AudioManager_creator(Create_AudioManager_proc* proc);
|
||||
|
||||
|
@ -156,13 +156,9 @@ FmodAudioManager() {
|
||||
memset(&_midi_info, 0, sizeof(_midi_info));
|
||||
_midi_info.cbsize = sizeof(_midi_info);
|
||||
|
||||
Filename dls_filename = audio_dls_file;
|
||||
if (!dls_filename.empty()) {
|
||||
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
|
||||
vfs->resolve_filename(dls_filename, get_sound_path()) ||
|
||||
vfs->resolve_filename(dls_filename, get_model_path());
|
||||
|
||||
_dlsname = dls_filename.to_os_specific();
|
||||
Filename dls_pathname = get_dls_pathname();
|
||||
if (!dls_pathname.empty()) {
|
||||
_dlsname = dls_pathname.to_os_specific();
|
||||
_midi_info.dlsname = _dlsname.c_str();
|
||||
}
|
||||
}
|
||||
|
@ -109,13 +109,12 @@ MilesAudioManager() {
|
||||
if (dls == NULL) {
|
||||
audio_error(" Unable to open DLS. " << AIL_last_error());
|
||||
} else {
|
||||
string dls_file;
|
||||
get_gm_file_path(dls_file);
|
||||
audio_debug(" dls_file=\""<<dls_file<<"\"");
|
||||
Filename dls_pathname = get_dls_pathname();
|
||||
string os_pathname = dls_pathname.to_os_specific();
|
||||
// note: if AIL_DLS_load_file is not done, midi fails to play on some machines.
|
||||
nassertv(_dls_field == NULL);
|
||||
audio_debug(" AIL_DLS_load_file(dls, " << dls_file << ", 0)");
|
||||
_dls_field = AIL_DLS_load_file(dls, dls_file.c_str(), 0);
|
||||
audio_debug(" AIL_DLS_load_file(dls, " << os_pathname << ", 0)");
|
||||
_dls_field = AIL_DLS_load_file(dls, os_pathname.c_str(), 0);
|
||||
}
|
||||
|
||||
if (!_dls_field) {
|
||||
@ -680,85 +679,6 @@ stop_all_sounds() {
|
||||
}
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MilesAudioManager::get_registry_entry
|
||||
// Access: private
|
||||
// Description: Combine base\\subKeyname\\keyName to get
|
||||
// 'result' from the Windows registry.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool MilesAudioManager::
|
||||
get_registry_entry(HKEY base, const char* subKeyName,
|
||||
const char* keyName, string& result) {
|
||||
// Open the key to access the registry:
|
||||
HKEY key;
|
||||
long r=RegOpenKeyEx(base, subKeyName, 0, KEY_QUERY_VALUE, &key);
|
||||
if (r==ERROR_SUCCESS) {
|
||||
DWORD len=0;
|
||||
// Read the size of the value at keyName:
|
||||
r=RegQueryValueEx(key, keyName, 0, 0, 0, &len);
|
||||
if (r==ERROR_SUCCESS) {
|
||||
char* src = new char[len];
|
||||
DWORD type;
|
||||
// Read the value at keyName:
|
||||
r=RegQueryValueEx(key, keyName, 0, &type, (unsigned char*)src, &len);
|
||||
if (r==ERROR_SUCCESS) {
|
||||
if (type==REG_EXPAND_SZ) {
|
||||
// Find the size of the expanded string:
|
||||
DWORD destSize=ExpandEnvironmentStrings(src, 0, 0);
|
||||
// Get a destination buffer of that size:
|
||||
char* dest = new char[destSize];
|
||||
// Do the expansion:
|
||||
ExpandEnvironmentStrings(src, dest, destSize);
|
||||
// Propagate the result:
|
||||
result=dest;
|
||||
delete [] dest;
|
||||
} else if (type==REG_SZ) {
|
||||
result=src;
|
||||
} else {
|
||||
audio_error("MilesAudioManager::get_reg_entry(): Unknown key type.");
|
||||
}
|
||||
}
|
||||
delete [] src;
|
||||
}
|
||||
RegCloseKey(key);
|
||||
}
|
||||
|
||||
return (r==ERROR_SUCCESS);
|
||||
}
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MilesAudioManager::get_gm_file_path
|
||||
// Access: private
|
||||
// Description: Get path of downloadable sound midi instruments file.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void MilesAudioManager::
|
||||
get_gm_file_path(string& result) {
|
||||
Filename dls_filename = audio_dls_file;
|
||||
if (!dls_filename.empty()) {
|
||||
result = dls_filename.to_os_specific();
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
if(!get_registry_entry(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\DirectMusic", "GMFilePath", result)) {
|
||||
char sysdir[MAX_PATH+1];
|
||||
GetSystemDirectory(sysdir,MAX_PATH+1);
|
||||
result = sysdir;
|
||||
result.append("\\drivers\\gm.dls");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef IS_OSX
|
||||
result =
|
||||
//"gs_instruments.dls";
|
||||
"/System/Library/Components/CoreAudio.component/Contents/Resources/gs_instruments.dls";
|
||||
#endif
|
||||
|
||||
|
||||
audio_debug("MilesAudioManager::get_gm_file_path() result out=\""<<result<<"\"");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MilesAudioManager::force_midi_reset
|
||||
// Access: Private
|
||||
|
@ -122,13 +122,7 @@ private:
|
||||
|
||||
void starting_sound(MilesAudioSound* audio);
|
||||
void stopping_sound(MilesAudioSound* audio);
|
||||
#ifdef WIN32
|
||||
// utility function that should be moved to another class:
|
||||
bool get_registry_entry(HKEY base,
|
||||
const char* subKeyName,
|
||||
const char* keyName,
|
||||
string& result);
|
||||
#endif
|
||||
|
||||
// get the default dls file path:
|
||||
void get_gm_file_path(string& result);
|
||||
|
||||
|
@ -327,6 +327,18 @@ do_get(const string &key, const string &name, int &data_type, string &data) {
|
||||
<< ": " << format_message(error) << "\n";
|
||||
}
|
||||
|
||||
if (okflag) {
|
||||
if (data_type == REG_EXPAND_SZ) {
|
||||
// Expand the string.
|
||||
DWORD destSize=ExpandEnvironmentStrings(data.c_str(), 0, 0);
|
||||
char *dest = new char[destSize];
|
||||
ExpandEnvironmentStrings(data.c_str(), dest, destSize);
|
||||
data = dest;
|
||||
delete[] dest;
|
||||
data_type = REG_SZ;
|
||||
}
|
||||
}
|
||||
|
||||
return okflag;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user