Work on sound positioning for objects. Enable in sounds in preferences.
This commit is contained in:
@@ -16,6 +16,7 @@ speech_stub.speak = mock.Mock()
|
||||
sys.modules.setdefault("cthulhu.speech", speech_stub)
|
||||
|
||||
from cthulhu import settings
|
||||
from cthulhu.sound_generator import SoundGenerator
|
||||
from cthulhu.sound_theme_manager import SoundThemeManager
|
||||
from cthulhu.speech_generator import SpeechGenerator
|
||||
from cthulhu.script_utilities import Utilities
|
||||
@@ -146,6 +147,74 @@ class LinkIndicatorPresentationRegressionTests(unittest.TestCase):
|
||||
self.assertEqual(spoken, "Docs link")
|
||||
self.assertEqual(icons, [icon])
|
||||
|
||||
def test_sound_pan_uses_object_position_inside_active_frame(self):
|
||||
utility = object.__new__(Utilities)
|
||||
obj = mock.Mock()
|
||||
frame = mock.Mock()
|
||||
icon = SimpleNamespace(path="/tmp/link.wav")
|
||||
|
||||
fakeApp = mock.Mock()
|
||||
fakeApp.settingsManager.getSetting.return_value = True
|
||||
|
||||
def get_rect(target):
|
||||
if target is frame:
|
||||
return SimpleNamespace(x=0, y=0, width=1000, height=800)
|
||||
if target is obj:
|
||||
return SimpleNamespace(x=495, y=0, width=10, height=20)
|
||||
return SimpleNamespace(x=0, y=0, width=0, height=0)
|
||||
|
||||
utility.frameAndDialog = mock.Mock(return_value=[frame, None])
|
||||
|
||||
with (
|
||||
mock.patch("cthulhu.script_utilities.cthulhu.cthulhuApp", fakeApp),
|
||||
mock.patch("cthulhu.script_utilities.AXComponent.get_rect", side_effect=get_rect),
|
||||
):
|
||||
utility.spatializeSoundIcon(icon, obj)
|
||||
|
||||
self.assertEqual(icon.pan, 0.0)
|
||||
|
||||
def test_sound_pan_hard_pans_only_at_extreme_edges(self):
|
||||
utility = object.__new__(Utilities)
|
||||
obj = mock.Mock()
|
||||
frame = mock.Mock()
|
||||
fakeApp = mock.Mock()
|
||||
fakeApp.settingsManager.getSetting.return_value = True
|
||||
|
||||
utility.frameAndDialog = mock.Mock(return_value=[frame, None])
|
||||
|
||||
with (
|
||||
mock.patch("cthulhu.script_utilities.cthulhu.cthulhuApp", fakeApp),
|
||||
mock.patch(
|
||||
"cthulhu.script_utilities.AXComponent.get_rect",
|
||||
side_effect=[
|
||||
SimpleNamespace(x=0, y=0, width=10, height=20),
|
||||
SimpleNamespace(x=0, y=0, width=1000, height=800),
|
||||
],
|
||||
),
|
||||
):
|
||||
self.assertEqual(utility.getSoundPanForObject(obj), -1.0)
|
||||
|
||||
|
||||
class SoundGeneratorSpatializationRegressionTests(unittest.TestCase):
|
||||
def test_generated_icons_and_tones_are_spatialized(self):
|
||||
generator = object.__new__(SoundGenerator)
|
||||
icon = SimpleNamespace(path="/tmp/link.wav")
|
||||
tone = SimpleNamespace(duration=0.1, frequency=440, volume=0.5, wave=0)
|
||||
generator._script = mock.Mock()
|
||||
generator._script.utilities.spatializeSoundIcon.side_effect = lambda sound, obj: sound
|
||||
|
||||
fakeApp = mock.Mock()
|
||||
fakeApp.settingsManager.getSetting.return_value = True
|
||||
obj = mock.Mock()
|
||||
|
||||
with mock.patch("cthulhu.sound_generator.cthulhu.cthulhuApp", fakeApp):
|
||||
result = generator._spatializeSounds([icon, [tone]], obj)
|
||||
|
||||
self.assertEqual(result, [icon, [tone]])
|
||||
generator._script.utilities.spatializeSoundIcon.assert_has_calls(
|
||||
[mock.call(icon, obj), mock.call(tone, obj)]
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user