From 05619b530d0122dd8903f3a8eb009f40a8b26421 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Sat, 9 Jul 2016 20:30:19 +0300 Subject: [PATCH 1/4] Added StreamSound support --- .../source-python/engines/sound/__init__.py | 77 +++++++++++++++ .../engines/{sound.py => sound/base.py} | 97 +++++-------------- .../source-python/engines/sound/sound.py | 39 ++++++++ .../source-python/engines/sound/stream.py | 45 +++++++++ 4 files changed, 183 insertions(+), 75 deletions(-) create mode 100644 addons/source-python/packages/source-python/engines/sound/__init__.py rename addons/source-python/packages/source-python/engines/{sound.py => sound/base.py} (57%) create mode 100644 addons/source-python/packages/source-python/engines/sound/sound.py create mode 100644 addons/source-python/packages/source-python/engines/sound/stream.py diff --git a/addons/source-python/packages/source-python/engines/sound/__init__.py b/addons/source-python/packages/source-python/engines/sound/__init__.py new file mode 100644 index 000000000..73234ddaa --- /dev/null +++ b/addons/source-python/packages/source-python/engines/sound/__init__.py @@ -0,0 +1,77 @@ +# ../engines/sound/__init__.py + +"""Provides access to the Sound and StreamSound interfaces.""" + +# ============================================================================= +# >> IMPORTS +# ============================================================================= +# Python Imports +# Enum +from enum import Enum + +# Source.Python Imports +# Engines +from engines import engines_logger + + +# ============================================================================= +# >> FORWARD IMPORTS +# ============================================================================= +# Source.Python Imports +# Engines +from _engines._sound import Channel +from _engines._sound import VOL_NORM +from _engines._sound import ATTN_NONE +from _engines._sound import ATTN_NORM +from _engines._sound import ATTN_IDLE +from _engines._sound import ATTN_STATIC +from _engines._sound import ATTN_RICOCHET +from _engines._sound import ATTN_GUNFIRE +from _engines._sound import MAX_ATTENUATION +from _engines._sound import SoundFlags +from _engines._sound import Pitch +from _engines._sound import SOUND_FROM_LOCAL_PLAYER +from _engines._sound import SOUND_FROM_WORLD +from _engines._sound import engine_sound + + +# ============================================================================= +# >> ALL DECLARATION +# ============================================================================= +__all__ = ('Attenuation', + 'Channel', + 'Pitch', + 'SOUND_FROM_LOCAL_PLAYER', + 'SOUND_FROM_WORLD', + 'Sound', + 'SoundFlags', + 'StreamSound', + 'VOL_NORM', + 'engine_sound', + ) + + +# ============================================================================= +# >> GLOBAL VARIABLES +# ============================================================================= +# Get the sp.engines.sound logger +engines_sound_logger = engines_logger.sound + + +# ============================================================================= +# >> ENUMERATORS +# ============================================================================= +class Attenuation(float, Enum): + """Attenuation values wrapper enumerator.""" + + NONE = ATTN_NONE + NORMAL = ATTN_NORM + IDLE = ATTN_IDLE + STATIC = ATTN_STATIC + RICOCHET = ATTN_RICOCHET + GUNFIRE = ATTN_GUNFIRE + MAXIMUM = MAX_ATTENUATION + + +from engines.sound.sound import Sound +from engines.sound.stream import StreamSound diff --git a/addons/source-python/packages/source-python/engines/sound.py b/addons/source-python/packages/source-python/engines/sound/base.py similarity index 57% rename from addons/source-python/packages/source-python/engines/sound.py rename to addons/source-python/packages/source-python/engines/sound/base.py index f6a74d8dd..d959795ac 100644 --- a/addons/source-python/packages/source-python/engines/sound.py +++ b/addons/source-python/packages/source-python/engines/sound/base.py @@ -1,19 +1,21 @@ -# ../engines/sound.py +# ../engines/sound/base.py -"""Provides access to the Sound interface.""" +"""Provides access to the _BaseSound interface.""" # ============================================================================= # >> IMPORTS # ============================================================================= -# Python Imports -# Enum -from enum import Enum - # Source.Python Imports # Core from core import AutoUnload # Engines -from engines import engines_logger +from engines.sound import Attenuation +from engines.sound import Channel +from engines.sound import engine_sound +from engines.sound import Pitch +from engines.sound import SOUND_FROM_WORLD +from engines.sound import SoundFlags +from engines.sound import VOL_NORM # Entities from entities.constants import INVALID_ENTITY_INDEX # Filters @@ -21,72 +23,13 @@ # Mathlib from mathlib import NULL_VECTOR # Stringtables -from stringtables import string_tables from stringtables.downloads import Downloadables -# ============================================================================= -# >> FORWARD IMPORTS -# ============================================================================= -# Source.Python Imports -# Engines -from _engines._sound import Channel -from _engines._sound import VOL_NORM -from _engines._sound import ATTN_NONE -from _engines._sound import ATTN_NORM -from _engines._sound import ATTN_IDLE -from _engines._sound import ATTN_STATIC -from _engines._sound import ATTN_RICOCHET -from _engines._sound import ATTN_GUNFIRE -from _engines._sound import MAX_ATTENUATION -from _engines._sound import SoundFlags -from _engines._sound import Pitch -from _engines._sound import SOUND_FROM_LOCAL_PLAYER -from _engines._sound import SOUND_FROM_WORLD -from _engines._sound import engine_sound - - -# ============================================================================= -# >> ALL DECLARATION -# ============================================================================= -__all__ = ('Attenuation', - 'Channel', - 'Pitch', - 'SOUND_FROM_LOCAL_PLAYER', - 'SOUND_FROM_WORLD', - 'Sound', - 'SoundFlags', - 'VOL_NORM', - 'engine_sound', - ) - - -# ============================================================================= -# >> GLOBAL VARIABLES -# ============================================================================= -# Get the sp.engines.sound logger -engines_sound_logger = engines_logger.sound - - -# ============================================================================= -# >> ENUMERATORS -# ============================================================================= -class Attenuation(float, Enum): - """Attenuation values wrapper enumerator.""" - - NONE = ATTN_NONE - NORMAL = ATTN_NORM - IDLE = ATTN_IDLE - STATIC = ATTN_STATIC - RICOCHET = ATTN_RICOCHET - GUNFIRE = ATTN_GUNFIRE - MAXIMUM = MAX_ATTENUATION - - # ============================================================================= # >> CLASSES # ============================================================================= -class Sound(AutoUnload): +class _BaseSound(AutoUnload): """Class used to interact with a specific sound file.""" # Set the base _downloads attribute to know whether @@ -138,11 +81,7 @@ def play(self, *recipients): self.precache() # Play the sound - engine_sound.emit_sound( - recipients, self.index, self.channel, self.sample, - self.volume, self.attenuation, self.flags, self.pitch, - self.origin, self.direction, self.origins, - self.update_positions, self.sound_time, self.speaker_entity) + self._play(recipients) def stop(self, index=None, channel=None): """Stop a sound from being played.""" @@ -159,16 +98,24 @@ def stop(self, index=None, channel=None): channel = self.channel # Stop the sound - engine_sound.stop_sound(index, channel, self.sample) + self._stop(index, channel) + + def _play(self, recipients): + """Play the sound (internal).""" + raise NotImplementedError + + def _stop(self, index, channel): + """Stop a sound from being played (internal).""" + raise NotImplementedError def precache(self): """Precache the sample.""" - engine_sound.precache_sound(self.sample) + raise NotImplementedError @property def is_precached(self): """Return whether or not the sample is precached.""" - return self.sample in string_tables.soundprecache + raise NotImplementedError @property def sample(self): diff --git a/addons/source-python/packages/source-python/engines/sound/sound.py b/addons/source-python/packages/source-python/engines/sound/sound.py new file mode 100644 index 000000000..1704ea96a --- /dev/null +++ b/addons/source-python/packages/source-python/engines/sound/sound.py @@ -0,0 +1,39 @@ +# ../engines/sound/sound.py + +"""Provides access to the Sound interface.""" + +# ============================================================================= +# >> IMPORTS +# ============================================================================= +# Source.Python Imports +# Engines +from engines.sound import engine_sound +from engines.sound.base import _BaseSound +# Stringtables +from stringtables import string_tables + + +# ============================================================================= +# >> CLASSES +# ============================================================================= +class Sound(_BaseSound): + def _play(self, recipients): + """Play the sound (internal).""" + engine_sound.emit_sound( + recipients, self.index, self.channel, self.sample, + self.volume, self.attenuation, self.flags, self.pitch, + self.origin, self.direction, self.origins, + self.update_positions, self.sound_time, self.speaker_entity) + + def _stop(self, index, channel): + """Stop a sound from being played (internal).""" + engine_sound.stop_sound(index, channel, self.sample) + + def precache(self): + """Precache the sample.""" + engine_sound.precache_sound(self.sample) + + @property + def is_precached(self): + """Return whether or not the sample is precached.""" + return self.sample in string_tables.soundprecache diff --git a/addons/source-python/packages/source-python/engines/sound/stream.py b/addons/source-python/packages/source-python/engines/sound/stream.py new file mode 100644 index 000000000..66a4930c0 --- /dev/null +++ b/addons/source-python/packages/source-python/engines/sound/stream.py @@ -0,0 +1,45 @@ +# ../engines/sound/stream.py + +"""Provides access to the StreamSound interface.""" + +# ============================================================================= +# >> IMPORTS +# ============================================================================= +# Source.Python Imports +# Engines +from engines.sound import engine_sound +from engines.sound.base import _BaseSound +# Stringtables +from stringtables import string_tables + + +# ============================================================================= +# >> CLASSES +# ============================================================================= +class StreamSound(_BaseSound): + @property + def _stream_sample(self): + """Return the streamed sample path of the Sound instance.""" + return "*/{}".format(self.sample) + + def _play(self, recipients): + """Play the sound (internal).""" + engine_sound.emit_sound( + recipients, self.index, self.channel, self._stream_sample, + self.volume, self.attenuation, self.flags, self.pitch, + self.origin, self.direction, self.origins, + self.update_positions, self.sound_time, self.speaker_entity) + + def _stop(self, index, channel): + """Stop a sound from being played (internal).""" + engine_sound.stop_sound(index, channel, self._stream_sample) + + def precache(self): + """Precache the sample.""" + string_tables.soundprecache.add_string( + self._stream_sample, self._stream_sample) + + @property + def is_precached(self): + """Return whether or not the sample is precached.""" + return self._stream_sample in string_tables.soundprecache From e4d052ba0767543790593863cf1c2527356fc7cd Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Sun, 10 Jul 2016 09:27:21 +0300 Subject: [PATCH 2/4] Combined `sound` package back into `sound.py` --- .../packages/source-python/engines/sound.py | 243 ++++++++++++++++++ .../source-python/engines/sound/__init__.py | 77 ------ .../source-python/engines/sound/base.py | 133 ---------- .../source-python/engines/sound/sound.py | 39 --- .../source-python/engines/sound/stream.py | 45 ---- 5 files changed, 243 insertions(+), 294 deletions(-) create mode 100644 addons/source-python/packages/source-python/engines/sound.py delete mode 100644 addons/source-python/packages/source-python/engines/sound/__init__.py delete mode 100644 addons/source-python/packages/source-python/engines/sound/base.py delete mode 100644 addons/source-python/packages/source-python/engines/sound/sound.py delete mode 100644 addons/source-python/packages/source-python/engines/sound/stream.py diff --git a/addons/source-python/packages/source-python/engines/sound.py b/addons/source-python/packages/source-python/engines/sound.py new file mode 100644 index 000000000..c3b8ed209 --- /dev/null +++ b/addons/source-python/packages/source-python/engines/sound.py @@ -0,0 +1,243 @@ +# ../engines/sound/__init__.py + +"""Provides access to the Sound and StreamSound interfaces.""" + +# ============================================================================= +# >> IMPORTS +# ============================================================================= +# Python Imports +# Enum +from enum import Enum + +# Source.Python Imports +# Core +from core import AutoUnload +# Engines +from engines import engines_logger +# Entities +from entities.constants import INVALID_ENTITY_INDEX +# Filters +from filters.recipients import RecipientFilter +# Mathlib +from mathlib import NULL_VECTOR +# Stringtables +from stringtables import string_tables +from stringtables.downloads import Downloadables + + +# ============================================================================= +# >> FORWARD IMPORTS +# ============================================================================= +# Source.Python Imports +# Engines +from _engines._sound import Channel +from _engines._sound import VOL_NORM +from _engines._sound import ATTN_NONE +from _engines._sound import ATTN_NORM +from _engines._sound import ATTN_IDLE +from _engines._sound import ATTN_STATIC +from _engines._sound import ATTN_RICOCHET +from _engines._sound import ATTN_GUNFIRE +from _engines._sound import MAX_ATTENUATION +from _engines._sound import SoundFlags +from _engines._sound import Pitch +from _engines._sound import SOUND_FROM_LOCAL_PLAYER +from _engines._sound import SOUND_FROM_WORLD +from _engines._sound import engine_sound + + +# ============================================================================= +# >> ALL DECLARATION +# ============================================================================= +__all__ = ('Attenuation', + 'Channel', + 'Pitch', + 'SOUND_FROM_LOCAL_PLAYER', + 'SOUND_FROM_WORLD', + 'Sound', + 'SoundFlags', + 'StreamSound', + 'VOL_NORM', + 'engine_sound', + ) + + +# ============================================================================= +# >> GLOBAL VARIABLES +# ============================================================================= +# Get the sp.engines.sound logger +engines_sound_logger = engines_logger.sound + + +# ============================================================================= +# >> ENUMERATORS +# ============================================================================= +class Attenuation(float, Enum): + """Attenuation values wrapper enumerator.""" + + NONE = ATTN_NONE + NORMAL = ATTN_NORM + IDLE = ATTN_IDLE + STATIC = ATTN_STATIC + RICOCHET = ATTN_RICOCHET + GUNFIRE = ATTN_GUNFIRE + MAXIMUM = MAX_ATTENUATION + + +# ============================================================================= +# >> CLASSES +# ============================================================================= +class _BaseSound(AutoUnload): + """Class used to interact with a specific sound file.""" + + # Set the base _downloads attribute to know whether + # or not the sample was added to the downloadables + _downloads = None + + def __init__( + self, sample, index=SOUND_FROM_WORLD, volume=VOL_NORM, + attenuation=Attenuation.NONE, channel=Channel.AUTO, + flags=SoundFlags.NO_FLAGS, pitch=Pitch.NORMAL, + origin=NULL_VECTOR, direction=NULL_VECTOR, origins=(), + update_positions=True, sound_time=0.0, + speaker_entity=INVALID_ENTITY_INDEX, download=False): + """Store all the given attributes and set the module for unloading.""" + # Set sample as a private attribute, since it should never change + # Added replacing \ with / in paths for comformity + self._sample = sample.replace('\\', '/') + + # Set all the base attributes + self.index = index + self.volume = volume + self.attenuation = attenuation + self.channel = channel + self.flags = flags + self.pitch = pitch + self.origin = origin + self.direction = direction + self.origins = origins + self.update_positions = update_positions + self.sound_time = sound_time + self.speaker_entity = speaker_entity + + # Should the sample be downloaded by clients? + if download: + + # Add the sample to Downloadables + self._downloads = Downloadables() + self._downloads.add('sound/{0}'.format(self.sample)) + + def play(self, *recipients): + """Play the sound.""" + # Get the recipients to play the sound to + recipients = RecipientFilter(*recipients) + + # Is the sound precached? + if not self.is_precached: + + # Precache the sound + self.precache() + + # Play the sound + self._play(recipients) + + def stop(self, index=None, channel=None): + """Stop a sound from being played.""" + # Was an index passed in? + if index is None: + + # Use the instance's index + index = self.index + + # Was a channel passed in? + if channel is None: + + # Use the instance's index + channel = self.channel + + # Stop the sound + self._stop(index, channel) + + def _play(self, recipients): + """Play the sound (internal).""" + raise NotImplementedError + + def _stop(self, index, channel): + """Stop a sound from being played (internal).""" + raise NotImplementedError + + def precache(self): + """Precache the sample.""" + raise NotImplementedError + + @property + def is_precached(self): + """Return whether or not the sample is precached.""" + raise NotImplementedError + + @property + def sample(self): + """Return the filename of the Sound instance.""" + return self._sample + + @property + def duration(self): + """Return the duration of the sample.""" + return engine_sound.get_sound_duration(self.sample) + + def _unload_instance(self): + """Remove the sample from the downloads list.""" + if self._downloads is not None: + self._downloads._unload_instance() + + +class Sound(_BaseSound): + def _play(self, recipients): + """Play the sound (internal).""" + engine_sound.emit_sound( + recipients, self.index, self.channel, self.sample, + self.volume, self.attenuation, self.flags, self.pitch, + self.origin, self.direction, self.origins, + self.update_positions, self.sound_time, self.speaker_entity) + + def _stop(self, index, channel): + """Stop a sound from being played (internal).""" + engine_sound.stop_sound(index, channel, self.sample) + + def precache(self): + """Precache the sample.""" + engine_sound.precache_sound(self.sample) + + @property + def is_precached(self): + """Return whether or not the sample is precached.""" + return self.sample in string_tables.soundprecache + + +class StreamSound(_BaseSound): + @property + def _stream_sample(self): + """Return the streamed sample path of the Sound instance.""" + return "*/{}".format(self.sample) + + def _play(self, recipients): + """Play the sound (internal).""" + engine_sound.emit_sound( + recipients, self.index, self.channel, self._stream_sample, + self.volume, self.attenuation, self.flags, self.pitch, + self.origin, self.direction, self.origins, + self.update_positions, self.sound_time, self.speaker_entity) + + def _stop(self, index, channel): + """Stop a sound from being played (internal).""" + engine_sound.stop_sound(index, channel, self._stream_sample) + + def precache(self): + """Precache the sample.""" + string_tables.soundprecache.add_string( + self._stream_sample, self._stream_sample) + + @property + def is_precached(self): + """Return whether or not the sample is precached.""" + return self._stream_sample in string_tables.soundprecache diff --git a/addons/source-python/packages/source-python/engines/sound/__init__.py b/addons/source-python/packages/source-python/engines/sound/__init__.py deleted file mode 100644 index 73234ddaa..000000000 --- a/addons/source-python/packages/source-python/engines/sound/__init__.py +++ /dev/null @@ -1,77 +0,0 @@ -# ../engines/sound/__init__.py - -"""Provides access to the Sound and StreamSound interfaces.""" - -# ============================================================================= -# >> IMPORTS -# ============================================================================= -# Python Imports -# Enum -from enum import Enum - -# Source.Python Imports -# Engines -from engines import engines_logger - - -# ============================================================================= -# >> FORWARD IMPORTS -# ============================================================================= -# Source.Python Imports -# Engines -from _engines._sound import Channel -from _engines._sound import VOL_NORM -from _engines._sound import ATTN_NONE -from _engines._sound import ATTN_NORM -from _engines._sound import ATTN_IDLE -from _engines._sound import ATTN_STATIC -from _engines._sound import ATTN_RICOCHET -from _engines._sound import ATTN_GUNFIRE -from _engines._sound import MAX_ATTENUATION -from _engines._sound import SoundFlags -from _engines._sound import Pitch -from _engines._sound import SOUND_FROM_LOCAL_PLAYER -from _engines._sound import SOUND_FROM_WORLD -from _engines._sound import engine_sound - - -# ============================================================================= -# >> ALL DECLARATION -# ============================================================================= -__all__ = ('Attenuation', - 'Channel', - 'Pitch', - 'SOUND_FROM_LOCAL_PLAYER', - 'SOUND_FROM_WORLD', - 'Sound', - 'SoundFlags', - 'StreamSound', - 'VOL_NORM', - 'engine_sound', - ) - - -# ============================================================================= -# >> GLOBAL VARIABLES -# ============================================================================= -# Get the sp.engines.sound logger -engines_sound_logger = engines_logger.sound - - -# ============================================================================= -# >> ENUMERATORS -# ============================================================================= -class Attenuation(float, Enum): - """Attenuation values wrapper enumerator.""" - - NONE = ATTN_NONE - NORMAL = ATTN_NORM - IDLE = ATTN_IDLE - STATIC = ATTN_STATIC - RICOCHET = ATTN_RICOCHET - GUNFIRE = ATTN_GUNFIRE - MAXIMUM = MAX_ATTENUATION - - -from engines.sound.sound import Sound -from engines.sound.stream import StreamSound diff --git a/addons/source-python/packages/source-python/engines/sound/base.py b/addons/source-python/packages/source-python/engines/sound/base.py deleted file mode 100644 index d959795ac..000000000 --- a/addons/source-python/packages/source-python/engines/sound/base.py +++ /dev/null @@ -1,133 +0,0 @@ -# ../engines/sound/base.py - -"""Provides access to the _BaseSound interface.""" - -# ============================================================================= -# >> IMPORTS -# ============================================================================= -# Source.Python Imports -# Core -from core import AutoUnload -# Engines -from engines.sound import Attenuation -from engines.sound import Channel -from engines.sound import engine_sound -from engines.sound import Pitch -from engines.sound import SOUND_FROM_WORLD -from engines.sound import SoundFlags -from engines.sound import VOL_NORM -# Entities -from entities.constants import INVALID_ENTITY_INDEX -# Filters -from filters.recipients import RecipientFilter -# Mathlib -from mathlib import NULL_VECTOR -# Stringtables -from stringtables.downloads import Downloadables - - -# ============================================================================= -# >> CLASSES -# ============================================================================= -class _BaseSound(AutoUnload): - """Class used to interact with a specific sound file.""" - - # Set the base _downloads attribute to know whether - # or not the sample was added to the downloadables - _downloads = None - - def __init__( - self, sample, index=SOUND_FROM_WORLD, volume=VOL_NORM, - attenuation=Attenuation.NONE, channel=Channel.AUTO, - flags=SoundFlags.NO_FLAGS, pitch=Pitch.NORMAL, - origin=NULL_VECTOR, direction=NULL_VECTOR, origins=(), - update_positions=True, sound_time=0.0, - speaker_entity=INVALID_ENTITY_INDEX, download=False): - """Store all the given attributes and set the module for unloading.""" - # Set sample as a private attribute, since it should never change - # Added replacing \ with / in paths for comformity - self._sample = sample.replace('\\', '/') - - # Set all the base attributes - self.index = index - self.volume = volume - self.attenuation = attenuation - self.channel = channel - self.flags = flags - self.pitch = pitch - self.origin = origin - self.direction = direction - self.origins = origins - self.update_positions = update_positions - self.sound_time = sound_time - self.speaker_entity = speaker_entity - - # Should the sample be downloaded by clients? - if download: - - # Add the sample to Downloadables - self._downloads = Downloadables() - self._downloads.add('sound/{0}'.format(self.sample)) - - def play(self, *recipients): - """Play the sound.""" - # Get the recipients to play the sound to - recipients = RecipientFilter(*recipients) - - # Is the sound precached? - if not self.is_precached: - - # Precache the sound - self.precache() - - # Play the sound - self._play(recipients) - - def stop(self, index=None, channel=None): - """Stop a sound from being played.""" - # Was an index passed in? - if index is None: - - # Use the instance's index - index = self.index - - # Was a channel passed in? - if channel is None: - - # Use the instance's index - channel = self.channel - - # Stop the sound - self._stop(index, channel) - - def _play(self, recipients): - """Play the sound (internal).""" - raise NotImplementedError - - def _stop(self, index, channel): - """Stop a sound from being played (internal).""" - raise NotImplementedError - - def precache(self): - """Precache the sample.""" - raise NotImplementedError - - @property - def is_precached(self): - """Return whether or not the sample is precached.""" - raise NotImplementedError - - @property - def sample(self): - """Return the filename of the Sound instance.""" - return self._sample - - @property - def duration(self): - """Return the duration of the sample.""" - return engine_sound.get_sound_duration(self.sample) - - def _unload_instance(self): - """Remove the sample from the downloads list.""" - if self._downloads is not None: - self._downloads._unload_instance() diff --git a/addons/source-python/packages/source-python/engines/sound/sound.py b/addons/source-python/packages/source-python/engines/sound/sound.py deleted file mode 100644 index 1704ea96a..000000000 --- a/addons/source-python/packages/source-python/engines/sound/sound.py +++ /dev/null @@ -1,39 +0,0 @@ -# ../engines/sound/sound.py - -"""Provides access to the Sound interface.""" - -# ============================================================================= -# >> IMPORTS -# ============================================================================= -# Source.Python Imports -# Engines -from engines.sound import engine_sound -from engines.sound.base import _BaseSound -# Stringtables -from stringtables import string_tables - - -# ============================================================================= -# >> CLASSES -# ============================================================================= -class Sound(_BaseSound): - def _play(self, recipients): - """Play the sound (internal).""" - engine_sound.emit_sound( - recipients, self.index, self.channel, self.sample, - self.volume, self.attenuation, self.flags, self.pitch, - self.origin, self.direction, self.origins, - self.update_positions, self.sound_time, self.speaker_entity) - - def _stop(self, index, channel): - """Stop a sound from being played (internal).""" - engine_sound.stop_sound(index, channel, self.sample) - - def precache(self): - """Precache the sample.""" - engine_sound.precache_sound(self.sample) - - @property - def is_precached(self): - """Return whether or not the sample is precached.""" - return self.sample in string_tables.soundprecache diff --git a/addons/source-python/packages/source-python/engines/sound/stream.py b/addons/source-python/packages/source-python/engines/sound/stream.py deleted file mode 100644 index 66a4930c0..000000000 --- a/addons/source-python/packages/source-python/engines/sound/stream.py +++ /dev/null @@ -1,45 +0,0 @@ -# ../engines/sound/stream.py - -"""Provides access to the StreamSound interface.""" - -# ============================================================================= -# >> IMPORTS -# ============================================================================= -# Source.Python Imports -# Engines -from engines.sound import engine_sound -from engines.sound.base import _BaseSound -# Stringtables -from stringtables import string_tables - - -# ============================================================================= -# >> CLASSES -# ============================================================================= -class StreamSound(_BaseSound): - @property - def _stream_sample(self): - """Return the streamed sample path of the Sound instance.""" - return "*/{}".format(self.sample) - - def _play(self, recipients): - """Play the sound (internal).""" - engine_sound.emit_sound( - recipients, self.index, self.channel, self._stream_sample, - self.volume, self.attenuation, self.flags, self.pitch, - self.origin, self.direction, self.origins, - self.update_positions, self.sound_time, self.speaker_entity) - - def _stop(self, index, channel): - """Stop a sound from being played (internal).""" - engine_sound.stop_sound(index, channel, self._stream_sample) - - def precache(self): - """Precache the sample.""" - string_tables.soundprecache.add_string( - self._stream_sample, self._stream_sample) - - @property - def is_precached(self): - """Return whether or not the sample is precached.""" - return self._stream_sample in string_tables.soundprecache From 3f73fc393993cbb6873b827ca6eebafc580457d4 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Sun, 10 Jul 2016 09:28:40 +0300 Subject: [PATCH 3/4] Oops, forgot this one --- addons/source-python/packages/source-python/engines/sound.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/source-python/packages/source-python/engines/sound.py b/addons/source-python/packages/source-python/engines/sound.py index c3b8ed209..4b4c5bd5b 100644 --- a/addons/source-python/packages/source-python/engines/sound.py +++ b/addons/source-python/packages/source-python/engines/sound.py @@ -1,4 +1,4 @@ -# ../engines/sound/__init__.py +# ../engines/sound.py """Provides access to the Sound and StreamSound interfaces.""" From f7e9a9a35100d1ecb1a182f23405681eea1a4e15 Mon Sep 17 00:00:00 2001 From: Kirill Mysnik Date: Sun, 10 Jul 2016 17:46:26 +0300 Subject: [PATCH 4/4] Updated docstrings --- .../packages/source-python/engines/sound.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/addons/source-python/packages/source-python/engines/sound.py b/addons/source-python/packages/source-python/engines/sound.py index 4b4c5bd5b..c146e98d4 100644 --- a/addons/source-python/packages/source-python/engines/sound.py +++ b/addons/source-python/packages/source-python/engines/sound.py @@ -88,7 +88,7 @@ class Attenuation(float, Enum): # >> CLASSES # ============================================================================= class _BaseSound(AutoUnload): - """Class used to interact with a specific sound file.""" + """Base class for sound classes.""" # Set the base _downloads attribute to know whether # or not the sample was added to the downloadables @@ -192,6 +192,15 @@ def _unload_instance(self): class Sound(_BaseSound): + """Class used to interact with precached sounds. + + .. note:: + + On some engines (e.g. CS:GO) server is unable to precache the sound, + thus the sound won't be played. StreamSound is recommended in that case. + However, sounds located in sound/music/ directory are always streamed + on those engines, and this class will be able to play them. + """ def _play(self, recipients): """Play the sound (internal).""" engine_sound.emit_sound( @@ -215,6 +224,19 @@ def is_precached(self): class StreamSound(_BaseSound): + """Class used to interact with streamed sounds. + + .. note:: + + This class is a recommended choice on some engines (e.g. CS:GO), + however, it's unable to play *.wav-files. + + .. note:: + + On some engines (e.g. CS:GO) files that are located in sound/music/ + directory are already streamed, so simple Sound class can be used + instead. + """ @property def _stream_sample(self): """Return the streamed sample path of the Sound instance."""