Просмотр исходного кода

added search for software midi downloadable sounds files

Dave Schuyler 24 лет назад
Родитель
Сommit
244a915603

+ 56 - 0
panda/src/audiotraits/milesAudioManager.cxx

@@ -67,6 +67,10 @@ MilesAudioManager() {
         AIL_quick_handles(0, 0, &dls);
         nassertv(audio_dls_file);
         nassertv(!_dls_field);
+        if (audio_dls_file->empty()) {
+          audio_debug("  using default audio_dls_file");
+          get_gm_file_path(*audio_dls_file);
+        }
         audio_debug("  audio_dls_file=\""<<*audio_dls_file<<"\"");
         _dls_field=AIL_DLS_load_file(dls, audio_dls_file->c_str(), 0);
         if (!_dls_field) {
@@ -281,4 +285,56 @@ get_active() {
   return _active;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: MilesAudioManager::get_registry_entry
+//       Access: private
+//  Description: Combine base\\subKeyname\\keyName to get
+//               'result' from the Windows registry.
+////////////////////////////////////////////////////////////////////
+void MilesAudioManager::
+get_registry_entry(HKEY base, const char* subKeyName, const char* keyName, 
+  string& result) {
+  // Create a key to access the registry:
+  HKEY key;
+  long r=RegCreateKeyEx(base, subKeyName, 0, "", 
+      REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL);
+  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 && 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;
+      }
+      delete [] src;
+    }
+    RegCloseKey(key);
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     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) {
+  get_registry_entry(HKEY_LOCAL_MACHINE, 
+      "SOFTWARE\\Microsoft\\DirectMusic", "GMFilePath", result);
+  audio_debug("MilesAudioManager::get_gm_file_path() result out=\""<<result<<"\"");
+}
+
+
 #endif //]

+ 8 - 0
panda/src/audiotraits/milesAudioManager.h

@@ -63,6 +63,14 @@ private:
   // Tell the manager that the sound dtor was called.
   void release_sound(MilesAudioSound* audioSound);
   
+  // utility function that should be moved to another class:
+  void get_registry_entry(HKEY base, 
+                          const char* subKeyName, 
+                          const char* keyName, 
+                          string& result);
+  // get the default dls file path:
+  void get_gm_file_path(string& result);
+  
   friend MilesAudioSound;
 };