|
|
@ -16,6 +16,7 @@ |
|
|
|
import bpy |
|
|
|
import bpy |
|
|
|
from bpy.props import * |
|
|
|
from bpy.props import * |
|
|
|
from bpy.app.handlers import persistent |
|
|
|
from bpy.app.handlers import persistent |
|
|
|
|
|
|
|
from contextlib import contextmanager |
|
|
|
import math |
|
|
|
import math |
|
|
|
from PyHSPlasma import * |
|
|
|
from PyHSPlasma import * |
|
|
|
|
|
|
|
|
|
|
@ -39,22 +40,34 @@ class PlasmaSfxFade(bpy.types.PropertyGroup): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PlasmaSound(idprops.IDPropMixin, bpy.types.PropertyGroup): |
|
|
|
class PlasmaSound(idprops.IDPropMixin, bpy.types.PropertyGroup): |
|
|
|
def _update_sound(self, value): |
|
|
|
@contextmanager |
|
|
|
if not value: |
|
|
|
def _lock_sound(self): |
|
|
|
self.name = "[Empty]" |
|
|
|
exclusive = not self.updating_sound |
|
|
|
return |
|
|
|
self.updating_sound = True |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
|
header, size = self._get_sound_info() |
|
|
|
yield exclusive |
|
|
|
except Exception as e: |
|
|
|
finally: |
|
|
|
self.is_valid = False |
|
|
|
if exclusive: |
|
|
|
# this might be perfectly acceptable... who knows? |
|
|
|
self.updating_sound = False |
|
|
|
# user consumable error report to be handled by the UI code |
|
|
|
|
|
|
|
print("---Invalid SFX selection---\n{}\n------".format(str(e))) |
|
|
|
def _update_sound(self, value): |
|
|
|
else: |
|
|
|
with self._lock_sound() as exclusive: |
|
|
|
self.is_valid = True |
|
|
|
if exclusive: |
|
|
|
self.is_stereo = header.numChannels == 2 |
|
|
|
if not value: |
|
|
|
self._update_name() |
|
|
|
self.name = "[Empty]" |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
header, size = self._get_sound_info() |
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
|
|
|
|
self.is_valid = False |
|
|
|
|
|
|
|
# this might be perfectly acceptable... who knows? |
|
|
|
|
|
|
|
# user consumable error report to be handled by the UI code |
|
|
|
|
|
|
|
print("---Invalid SFX selection---\n{}\n------".format(str(e))) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
self.is_valid = True |
|
|
|
|
|
|
|
self.is_stereo = header.numChannels == 2 |
|
|
|
|
|
|
|
self._update_name() |
|
|
|
|
|
|
|
|
|
|
|
def _update_name(self, context=None): |
|
|
|
def _update_name(self, context=None): |
|
|
|
if self.is_stereo and self.channel != {"L", "R"}: |
|
|
|
if self.is_stereo and self.channel != {"L", "R"}: |
|
|
@ -67,6 +80,8 @@ class PlasmaSound(idprops.IDPropMixin, bpy.types.PropertyGroup): |
|
|
|
description="Sound Datablock", |
|
|
|
description="Sound Datablock", |
|
|
|
type=bpy.types.Sound, |
|
|
|
type=bpy.types.Sound, |
|
|
|
update=_update_sound) |
|
|
|
update=_update_sound) |
|
|
|
|
|
|
|
updating_sound = BoolProperty(default=False, |
|
|
|
|
|
|
|
options={"HIDDEN", "SKIP_SAVE"}) |
|
|
|
|
|
|
|
|
|
|
|
is_stereo = BoolProperty(default=True, options={"HIDDEN"}) |
|
|
|
is_stereo = BoolProperty(default=True, options={"HIDDEN"}) |
|
|
|
is_valid = BoolProperty(default=False, options={"HIDDEN"}) |
|
|
|
is_valid = BoolProperty(default=False, options={"HIDDEN"}) |
|
|
|