Skip to content

Commit

Permalink
Fix gFix custom rolloff curve handling - respect that it must be kept…
Browse files Browse the repository at this point in the history
… alive by ourselves and bridge the methods correctly
  • Loading branch information
tyrylu committed Apr 1, 2021
1 parent 806e402 commit 52f8f2d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 14 deletions.
12 changes: 9 additions & 3 deletions pyfmodex/channel_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@


class ChannelControl(FmodObject):

def __init__(self, ptr):
super().__init__(ptr)
self._custom_rolloff_curve = None # To keep the custom rolloff curve alive

def _call_specific(self, specific_function_suffix, *args):
return self._call_fmod(
"FMOD_%s_%s" % (self.__class__.__name__, specific_function_suffix), *args
Expand Down Expand Up @@ -83,17 +88,18 @@ def custom_rolloff(self):
num = c_int()
self._call_specific("Get3DCustomRolloff", None, byref(num))
curve = (VECTOR * num.value)()
curve = POINTER(VECTOR)()
self._call_specific("Get3DCustomRolloff", byref(curve), None)
return [p.to_list() for p in curve]
return [curve[i].to_list() for i in range(num.value)]

@custom_rolloff.setter
def custom_rolloff(self, curve):
"""Sets the custom rolloff curve.
:param curve: The curve to set.
:type curve: A list of something that can be treated as a list of [x, y, z] values e.g. implements indexing in some way.
"""
native_curve = (VECTOR * len(curve))(*[VECTOR.from_list(lst) for lst in curve])
self._call_specific("Set3DCustomRolloff", native_curve, len(native_curve))
self._custom_rolloff_curve = (VECTOR * len(curve))(*[VECTOR.from_list(lst) for lst in curve])
self._call_specific("Set3DCustomRolloff", self._custom_rolloff_curve, len(self._custom_rolloff_curve))

@property
def threed_distance_filter(self):
Expand Down
12 changes: 6 additions & 6 deletions pyfmodex/sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class ConeSettings(object):
def __init__(self, sptr):
self._sptr = sptr
self._native_curve = None # To keep the custom rolloff curve alive
self._in = c_float()
self._out = c_float()
self._outvol = c_float()
Expand Down Expand Up @@ -79,20 +80,19 @@ def custom_rolloff(self):
"""
num = c_int()
self._call_fmod("FMOD_Sound_Get3DCustomRolloff", None, byref(num))
print(num.value)
curve = (VECTOR * num.value)()
self._call_fmod("FMOD_Sound_Get3DCustomRolloff", byref(curve), None)
return [p.to_list() for p in curve]
curve_ptr = POINTER(VECTOR)()
self._call_fmod("FMOD_Sound_Get3DCustomRolloff", byref(curve_ptr), None)
return [curve_ptr[i].to_list() for i in range(num.value)]

@custom_rolloff.setter
def custom_rolloff(self, curve):
"""Sets the custom rolloff curve.
:param curve: The curve to set.
:type curve: A list of something that can be treated as a list of [x, y, z] values e.g. implements indexing in some way.
"""
native_curve = (VECTOR * len(curve))(*[VECTOR.from_list(lst) for lst in curve])
self._native_curve = (VECTOR * len(curve))(*[VECTOR.from_list(lst) for lst in curve])
self._call_fmod(
"FMOD_Sound_Set3DCustomRolloff", native_curve, len(native_curve)
"FMOD_Sound_Set3DCustomRolloff", self._native_curve, len(self._native_curve)
)

@property
Expand Down
4 changes: 3 additions & 1 deletion pyfmodex/studio/studio_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
class StudioObject:
"""A base FMOD studio object."""

function_prefix = '' # to be overridden in subclasses

def __init__(self, ptr):
"""Constructor.
:param ptr: The pointer representing this object.
"""
self._ptr = ptr
self._lib = get_library()
self.function_prefix = '' # to be overridden in subclasses

def _call(self, specific_function_suffix, *args):
func_name = "%s_%s" % (self.function_prefix, specific_function_suffix)
print(func_name)
result = getattr(self._lib, func_name)(self._ptr, *args)
ckresult(result)

Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
from pyfmodex.enums import DSP_TYPE, DSPCONNECTION_TYPE
from pyfmodex.studio.enums import LOADING_STATE
from pyfmodex.flags import MODE

@pytest.fixture(scope="session")
def instance(system_with_banks, event):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_custom_rolloff(channel):
new_curve = [[1.0,0.5,0.0], [4.0,0.0,0.0]]
assert channel.custom_rolloff == []
channel.custom_rolloff = new_curve
assert channel.custom_rolloff == channel.custom_rolloff # Should test equality with the new curve, but the setting or retrieval results in some garbage values
assert channel.custom_rolloff == new_curve

def test_threed_distance_filter(channel):
settings = channel.threed_distance_filter
Expand Down
3 changes: 1 addition & 2 deletions tests/test_channel_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ def test_cone_settings(channel_group):
assert settings.outside_angle == 360.0

def test_custom_rolloff(channel_group):
channel_group.mode = MODE.THREED
new_curve = [[1.0,0.5,0.0], [4.0,0.0,0.0]]
assert channel_group.custom_rolloff == []
channel_group.custom_rolloff = new_curve
assert channel_group.custom_rolloff == channel_group.custom_rolloff # Should test equality with the new curve, but the setting or retrieval results in some garbage values
assert channel_group.custom_rolloff == new_curve

def test_threed_distance_filter(channel_group):
channel_group.mode = MODE.THREED
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_custom_rolloff(sound):
assert sound.custom_rolloff == []
curve = [[0,1,0],[3,0.5,0]]
sound.custom_rolloff = curve
assert sound.custom_rolloff == sound.custom_rolloff
assert sound.custom_rolloff == curve
sound.custom_rolloff = []

def test_min_distance(sound):
Expand Down

0 comments on commit 52f8f2d

Please sign in to comment.