Skip to content

Commit

Permalink
Fix and improve sound logging, priority bug
Browse files Browse the repository at this point in the history
Sound library logging improvements.  Fixed a sound priority playback bug
(priority was being ignored).
  • Loading branch information
qcapen committed Jun 13, 2016
1 parent b0bb55d commit adde9aa
Show file tree
Hide file tree
Showing 6 changed files with 5,838 additions and 5,814 deletions.
5 changes: 4 additions & 1 deletion mpfmc/assets/sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from mpf.core.utility_functions import Util
from mpfmc.core.audio.audio_interface import AudioInterface, AudioException

Logger = logging.getLogger('AudioInterface')
Logger = logging.getLogger('SoundAsset')


# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -234,14 +234,17 @@ def play(self, settings=None):
Args:
settings: Optional dictionary of settings to override the default values.
"""
Logger.debug("SoundAsset: Play sound %s %s", self.name, self.track)
self._track.play_sound(self, **settings)

def stop(self):
"""Stops all instances of the sound playing on the sound's default track."""
Logger.debug("SoundAsset: Stop sound %s %s", self.name, self.track)
self._track.stop_sound(self)

def stop_looping(self):
"""Stops looping on all instances of the sound playing (and awaiting playback)."""
Logger.debug("SoundAsset: Stop looping sound %s %s", self.name, self.track)
self._track.stop_sound_looping(self)


Expand Down
1 change: 0 additions & 1 deletion mpfmc/config_players/sound_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# WARNING: Do not import kivy's logger here since that will trigger Kivy to
# load in the mpf process when MPF processes the MpfSoundPlayer
# from kivy.logger import Logger
from mpf.config_players.plugin_player import PluginPlayer
from mpf.core.config_validator import ConfigValidator
from mpfmc.core.mc_config_player import McConfigPlayer
Expand Down
29 changes: 15 additions & 14 deletions mpfmc/core/audio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Audio module provides all the audio features (playing of sounds) for the media controller.
"""

from kivy.logger import Logger
from kivy.clock import Clock
from mpfmc.core.audio.audio_interface import AudioInterface, AudioException, Track
import logging

__all__ = ('SoundSystem',
'AudioInterface',
Expand Down Expand Up @@ -33,17 +33,18 @@ class SoundSystem(object):

def __init__(self, mc):
self.mc = mc
self.log = logging.getLogger('SoundSystem')
self._initialized = False
self.audio_interface = None
self.config = {}
self.tracks = {}
self.sound_events = {}

Logger.debug("Loading the Sound System")
self.log.debug("Loading the Sound System")

# Load configuration for sound system
if 'sound_system' not in self.mc.machine_config:
Logger.info("SoundSystem: Using default 'sound_system' settings")
self.log.info("SoundSystem: Using default 'sound_system' settings")
self.config = {}
else:
self.config = self.mc.machine_config['sound_system']
Expand All @@ -54,16 +55,16 @@ def __init__(self, mc):

# If the sound system has been disabled, abort initialization
if not self.config['enabled']:
Logger.debug("SoundSystem: The sound system has been disabled in "
"the configuration file (enabled: False). No audio "
"features will be available.")
self.log.debug("SoundSystem: The sound system has been disabled in "
"the configuration file (enabled: False). No audio "
"features will be available.")
return

if 'buffer' not in self.config or self.config['buffer'] == 'auto':
self.config['buffer'] = DEFAULT_AUDIO_BUFFER_SAMPLE_SIZE
elif not AudioInterface.power_of_two(self.config['buffer']):
Logger.warning("SoundSystem: The buffer setting is not a power of "
"two. Default buffer size will be used.")
self.log.warning("SoundSystem: The buffer setting is not a power of "
"two. Default buffer size will be used.")
self.config['buffer'] = DEFAULT_AUDIO_BUFFER_SAMPLE_SIZE

if 'frequency' not in self.config or self.config['frequency'] == 'auto':
Expand All @@ -83,8 +84,8 @@ def __init__(self, mc):
channels=self.config['channels'],
buffer_samples=self.config['buffer'])
except AudioException:
Logger.error("SoundController: Could not initialize the audio interface. "
"Audio features will not be available.")
self.log.error("SoundController: Could not initialize the audio interface. "
"Audio features will not be available.")
self.audio_interface = None
return

Expand Down Expand Up @@ -148,14 +149,14 @@ def _create_track(self, name, config=None):
True if the track was successfully created, False otherwise
"""
if self.audio_interface is None:
Logger.error("SoundSystem: Could not create '{}' track - the audio interface has not been initialized"
.format(name))
self.log.error("SoundSystem: Could not create '{}' track - the audio interface has "
"not been initialized".format(name))
return False

# Validate track config parameters
if name in self.tracks:
Logger.error("SoundSystem: Could not create '{}' track - a track with that name already exists"
.format(name))
self.log.error("SoundSystem: Could not create '{}' track - a track with that name "
"already exists".format(name))
return False

if config is None:
Expand Down

0 comments on commit adde9aa

Please sign in to comment.