How to use the mpf.core.utility_functions.Util.string_to_secs function in mpf

To help you get started, we’ve selected a few mpf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github missionpinball / mpf-mc / mpfmc / core / audio / __init__.py View on Github external
raise AudioException("Could not create '{}' track - an illegal value for "
                                 "'type' was found".format(name))

        # Validate type-specific parameters and create the track
        track = None
        if config['type'] == 'standard':
            if 'simultaneous_sounds' not in config:
                config['simultaneous_sounds'] = DEFAULT_TRACK_MAX_SIMULTANEOUS_SOUNDS

            track = self.audio_interface.create_standard_track(self.mc,
                                                               name,
                                                               config['simultaneous_sounds'],
                                                               config['volume'])
        elif config['type'] == 'playlist':
            config.setdefault('crossfade_time', 0.0)
            config['crossfade_time'] = Util.string_to_secs(config['crossfade_time'])

            track = self.audio_interface.create_playlist_track(self.mc,
                                                               name,
                                                               config['crossfade_time'],
                                                               config['volume'])

        elif config['type'] == 'sound_loop':
            if 'max_layers' not in config:
                config['max_layers'] = 8

            track = self.audio_interface.create_sound_loop_track(self.mc,
                                                                 name,
                                                                 config['max_layers'],
                                                                 config['volume'])

        if track is None:
github missionpinball / mpf / mpf / core / config.py View on Github external
if item:
                return str(item)
            else:
                return None

        elif item_type in ('boolean', 'bool'):
            if type(item) is bool:
                return item
            else:
                return str(item).lower() in ('yes', 'true')

        elif item_type == 'ms':
            return Util.string_to_ms(item)

        elif item_type == 'secs':
            return Util.string_to_secs(item)

        elif item_type == 'list_of_lists':
            return Util.list_of_lists(item)
github missionpinball / mpf / mpf / core / config.py View on Github external
elif validator in ('bool', 'boolean'):
            if type(item) is str:
                if item.lower() in ['false', 'f', 'no', 'disable', 'off']:
                    item = False

            elif not item:
                item = False

            else:
                item = True

        elif validator == 'ms':
            item = Util.string_to_ms(item)

        elif validator == 'secs':
            item = Util.string_to_secs(item)

        elif validator == 'list':
            item = Util.string_to_list(item)

        elif validator == 'dict':
            return item

        elif validator == 'color':
            # we call color_from_string() here because MPF and the MPF_MC each
            # need different color formats internally, so this way they can
            # each implement their own methods.
            return self.color_from_string(item)

        else:
            self.log.error("Invalid Validator '%s' in config spec %s:%s",
                           validator,
github missionpinball / mpf-mc / mpfmc / assets / playlist.py View on Github external
self.log.error("'%s' is not a valid track name. "
                               "Could not create sound '%s' asset.", self.config['track'], name)
                raise AudioException("'{}' is not a valid track name. "
                                     "Could not create sound '{}' asset"
                                     .format(self.config['track'], name))

        self._track = track

        if 'type' in self.config and self.config['type'] is not None:
            self._type = self.config['type']

        if 'scope' in self.config and self.config['scope'] is not None:
            self._scope = self.config['scope']

        if 'crossfade_time' in self.config and self.config['crossfade_time'] is not None:
            self._crossfade_time = Util.string_to_secs(self.config['crossfade_time'])

        if 'events_when_played' in self.config and isinstance(
                self.config['events_when_played'], str):
            self._events_when_played = Util.string_to_list(self.config['events_when_played'])

        if 'events_when_stopped' in self.config and isinstance(
                self.config['events_when_stopped'], str):
            self._events_when_stopped = Util.string_to_list(self.config['events_when_stopped'])

        if 'events_when_sound_played' in self.config and isinstance(
                self.config['events_when_sound_played'], str):
            self._events_when_sound_played = Util.string_to_list(self.config['events_when_sound_played'])

        if 'events_when_sound_stopped' in self.config and isinstance(
                self.config['events_when_sound_stopped'], str):
            self._events_when_sound_stopped = Util.string_to_list(self.config['events_when_sound_stopped'])
github missionpinball / mpf / mpf / core / config_validator.py View on Github external
def _validate_type_secs(cls, item, validation_failure_info):
        del validation_failure_info
        if item is not None:
            return Util.string_to_secs(item)
        else:
            return None
github missionpinball / mpf / mpf / assets / show.py View on Github external
# Pylint complains about the change from dict to list. This is intended and fine.
        if isinstance(data, dict):
            data = list(data)
        elif not isinstance(data, list):    # pragma: no cover
            raise ValueError("Show {} does not appear to be a valid show "
                             "config".format(self.file))

        if not data:    # pragma: no cover
            self._show_validation_error("Cannot load empty show")

        total_step_time = 0

        # add empty first step if show does not start right away
        if 'time' in data[0] and data[0]['time'] != 0:
            self.show_steps.append({'duration': Util.string_to_secs(data[0]['time'])})
            total_step_time = Util.string_to_secs(data[0]['time'])

        # Loop over all steps in the show file
        for step_num, step in enumerate(data):
            actions = dict()

            # Note: all times are stored/calculated in seconds.

            # Step time can be specified as either an absolute time elapsed
            # (from the beginning of the show) or a relative time (time elapsed
            # since the previous step).  Time strings starting with a plus sign
            # (+) are treated as relative times.

            # Step times are all converted to relative times internally (time
            # since the previous step).
github missionpinball / mpf / mpf / assets / show.py View on Github external
if 'time' in data[step_num + 1]:
                next_step_time = data[step_num + 1]['time']
                if str(next_step_time)[0] == "+":
                    return Util.string_to_secs(next_step_time)

                if total_step_time < 0:     # pragma: no cover
                    self._show_validation_error("Absolute timing in step {} not possible because "
                                                "there was a duration of -1 before".format(step_num))
                return Util.string_to_secs(next_step_time) - total_step_time

            return 1

        if step_num < total_steps_num - 1 and 'time' in data[step_num + 1]:     # pragma: no cover
            self._show_validation_error("Found invalid 'time' entry in step after {} which contains a duration. "
                                        "Remove either of them!".format(step_num))
        return Util.string_to_secs(step['duration'])
github missionpinball / mpf / mpf / assets / show.py View on Github external
# Pylint complains about the change from dict to list. This is intended and fine.
        if isinstance(data, dict):
            data = list(data)
        elif not isinstance(data, list):    # pragma: no cover
            raise ValueError("Show {} does not appear to be a valid show "
                             "config".format(self.file))

        if not data:    # pragma: no cover
            self._show_validation_error("Cannot load empty show")

        total_step_time = 0

        # add empty first step if show does not start right away
        if 'time' in data[0] and data[0]['time'] != 0:
            self.show_steps.append({'duration': Util.string_to_secs(data[0]['time'])})
            total_step_time = Util.string_to_secs(data[0]['time'])

        # Loop over all steps in the show file
        for step_num, step in enumerate(data):
            actions = dict()

            # Note: all times are stored/calculated in seconds.

            # Step time can be specified as either an absolute time elapsed
            # (from the beginning of the show) or a relative time (time elapsed
            # since the previous step).  Time strings starting with a plus sign
            # (+) are treated as relative times.

            # Step times are all converted to relative times internally (time
            # since the previous step).

            # Make sure there is a time entry for each step in the show file.