X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=helpers%2Fmapping.py;h=c2a94e67baa52f3bfe4b06eccb78d88741805789;hb=205861936ca55357beea6a8af7c0c9ed5a61f484;hp=3622f9d8d42086369d59702cf45e6e3cd03fa9d5;hpb=a8340c5d43bcfc3d78c2e00ab26c0596d7ffe85e;p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git diff --git a/helpers/mapping.py b/helpers/mapping.py index 3622f9d..c2a94e6 100644 --- a/helpers/mapping.py +++ b/helpers/mapping.py @@ -10,7 +10,7 @@ import sys from .music_file import * from .mixer import Mixer from . import Config, gain, error_print -from .music_effect import GainEffect +from .action import Action class Mapping(RelativeLayout): expected_keys = NumericProperty(0) @@ -22,11 +22,18 @@ class Mapping(RelativeLayout): self.mixer = Mixer() else: self.mixer = None - self.key_config, self.open_files = self.parse_config() + + try: + self.key_config, self.open_files = self.parse_config() + except Exception as e: + error_print("Error while loading configuration: {}".format(e)) + sys.exit() + super(Mapping, self).__init__(**kwargs) self._keyboard = Window.request_keyboard(self._keyboard_closed, self) self._keyboard.bind(on_key_down=self._on_keyboard_down) self.running = [] + self.wait_ids = {} Clock.schedule_interval(self.not_all_keys_ready, 1) @property @@ -39,16 +46,19 @@ class Mapping(RelativeLayout): self.master_volume) for music in self.open_files.values(): - if fade > 0: - music.gain_effects.append(GainEffect( - "fade", - music.current_audio_segment, - music.current_loop, - music.sound_position, - music.sound_position + fade, - gain=db_gain)) + music.set_gain_with_effect(db_gain, fade=fade) + + def add_wait_id(self, wait_id, action_or_wait): + self.wait_ids[wait_id] = action_or_wait + + def interrupt_wait(self, wait_id): + if wait_id in self.wait_ids: + action_or_wait = self.wait_ids[wait_id] + del(self.wait_ids[wait_id]) + if isinstance(action_or_wait, Action): + action_or_wait.interrupt() else: - music.set_gain(db_gain) + action_or_wait.set() def _keyboard_closed(self): self._keyboard.unbind(on_key_down=self._on_keyboard_down)