Skip to content

Commit

Permalink
Merge pull request #45 from K0lb3/master
Browse files Browse the repository at this point in the history
Implement using a custom, user-specified fmod dll path
  • Loading branch information
tyrylu committed Oct 16, 2022
2 parents f520299 + 467a87f commit 71e3f31
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/usage/installation.rst
Expand Up @@ -3,6 +3,7 @@ Installation

To install, first make sure that you have the FMOD Engine library for you platform somewhere in your path, so Python will be able to find it.
On Linux, libraries are searched for in `LD_LIBRARY_PATH`.
Alternatively, you can set ``PYFMODEX_DLL_PATH`` as an environment variable to specify the library path. This can also be done inside Python setting ``os.environ["PYFMODEX_DLL_PATH"]`` before importing pyfmodex.

.. todo:: Add instructions for library paths on Mac OS X and Windows

Expand Down
41 changes: 22 additions & 19 deletions pyfmodex/fmodex.py
Expand Up @@ -12,26 +12,29 @@
import os
import platform
import sys
from ctypes import *

arch = platform.architecture()[0]
if platform.system() == "Windows":
try:
_dll = windll.fmod
except Exception as exc:
current_directory = os.path.dirname(os.path.realpath(sys.argv[0]))
try:
_dll = CDLL(os.path.join(current_directory, "fmod"))
except:
raise RuntimeError("Pyfmodex could not find the fmod library") from exc

elif platform.system() == "Linux":
_dll = CDLL("libfmod.so")
from ctypes import CDLL, windll

elif platform.system() == "Darwin":
if arch == "32bit":
raise RuntimeError("No 32-bit fmod library for Mac Os exists")
_dll = CDLL("libfmod.dylib")
if os.environ.get("PYFMODEX_DLL_PATH") is not None:
_dll = CDLL(os.environ.get("PYFMODEX_DLL_PATH"))
else:
arch = platform.architecture()[0]
if platform.system() == "Windows":
try:
_dll = windll.fmod
except Exception as exc:
current_directory = os.path.dirname(os.path.realpath(sys.argv[0]))
try:
_dll = CDLL(os.path.join(current_directory, "fmod"))
except:
raise RuntimeError("Pyfmodex could not find the fmod library") from exc

elif platform.system() == "Linux":
_dll = CDLL("libfmod.so")

elif platform.system() == "Darwin":
if arch == "32bit":
raise RuntimeError("No 32-bit fmod library for Mac Os exists")
_dll = CDLL("libfmod.dylib")
from . import globalvars

globalvars.DLL = _dll
Expand Down
1 change: 1 addition & 0 deletions readme.md
Expand Up @@ -6,6 +6,7 @@ Installation
------------
To install, first make sure that you have the FMOD Engine library for you platform somewhere in your path, so Python will be able to find it.
On Linux, libraries are searched for in `LD_LIBRARY_PATH`.
Alternatively, you can set ``PYFMODEX_DLL_PATH`` as an environment variable to specify the library path. This can also be done inside Python setting ``os.environ["PYFMODEX_DLL_PATH"]`` before importing pyfmodex.
To download the FMOD Engine library, visit http://www.fmod.org/download. The library is free to download, but requires a free account to be made first.

Then, install pyfmodex via `pip`, `easy_install` or the `setup.py` way. Note that the minimum supported Python version is Python 3.6.
Expand Down

0 comments on commit 71e3f31

Please sign in to comment.