utils
DataKey
- class DataKey(*values)[source]
-
Enumeration of simulation data keys used for system-wide communication.
This class defines the standardized keys used by the
SoundModelto identify simulation variables received from the CARLA client. By inheriting fromstr, these members act as validated constants that ensure consistency between the network layer, the EventBus, and the various sound adapters.
EventBus
- class EventBus[source]
Bases:
objectCentralized Publish-Subscribe (Pub/Sub) system for decoupled communication.
The EventBus facilitates the flow of simulation data from the SoundModel to various audio adapters. By using this pattern, the data source remains agnostic of the specific sound logic, allowing for a highly modular and extensible architecture.
- subscribe(key: DataKey, callback: Callable[[Any], None]) None[source]
Registers a listener for a specific simulation data key.
- Parameters:
key (DataKey) – The specific data channel to subscribe to.
callback (Callable) – The function to be executed when data is published.
- unsubscribe(key: DataKey, callback: Callable[[Any], None]) None[source]
Removes a previously registered listener from a data key.
- Parameters:
key (DataKey) – The data channel to detach from.
callback (Callable) – The specific function to remove from the registry.
- publish(key: DataKey, data: Any) None[source]
Broadcasts simulation data to all listeners of a specific key.
This method iterates through the subscriber list for the provided key and executes each callback, passing the new simulation data as an argument.
- Parameters:
key (DataKey) – The data channel to broadcast on.
data (Any) – The simulation value (speed, torque, etc.) to distribute.
RangeLevel
- class RangeLevel(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
EnumGeneric base class for level definitions with range bounds and output mapping.
This utility allows for the categorization of continuous numeric simulation data into discrete states. It is primarily used to map percentages (like rain or wind intensity) into specific integer values required by FMOD Studio parameters.
- contains(value)[source]
Checks whether the given value falls within this level’s range.
The logic implements a specific boundary rule: the lower bound is inclusive only if it is 0.0, otherwise it is treated as exclusive to prevent overlap between adjacent levels.
- classmethod from_value(value)[source]
Factory method to find the matching level for a given numeric input.
Iterates through all members of the Enum and returns the level where
contains()evaluates to True.- Parameters:
value (float) – The simulation value to be categorized.
- Returns:
The matching Enum member, or None if no match is found.
- Return type: