From: Ismaƫl Bouya Date: Sun, 17 Jul 2016 12:48:59 +0000 (+0200) Subject: Add the possibility to use the system mixer X-Git-Tag: 1.0.0~50 X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git;a=commitdiff_plain;h=af27d78259265bdada147757cd64488f44dd524d;hp=75d6cdbac628b57e206cd37808c1d3c7fecbb9eb Add the possibility to use the system mixer --- diff --git a/helpers/__init__.py b/helpers/__init__.py index 807aa44..863a23b 100644 --- a/helpers/__init__.py +++ b/helpers/__init__.py @@ -32,6 +32,9 @@ def parse_args(): default="config.yml", required=False, help="Config file to load") + parser.add_argument("-m", "--no-mixing", + action="store_true", + help="Don't make the mixing of sounds manually and let the sound system do it") parser.add_argument("-l", "--latency", default="high", required=False, @@ -80,6 +83,7 @@ def parse_args(): Config.frame_rate = args.frame_rate Config.channels = args.channels Config.sample_width = args.sample_width + Config.no_mixing = args.no_mixing class SelectDeviceAction(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): diff --git a/helpers/mapping.py b/helpers/mapping.py index 8e0265c..cfc2c3f 100644 --- a/helpers/mapping.py +++ b/helpers/mapping.py @@ -17,7 +17,10 @@ class Mapping(RelativeLayout): ready_color = ListProperty([1, 165/255, 0, 1]) def __init__(self, **kwargs): - self.mixer = Mixer() + if Config.no_mixing: + self.mixer = None + else: + self.mixer = Mixer() self.key_config, self.open_files = self.parse_config() super(Mapping, self).__init__(**kwargs) self._keyboard = Window.request_keyboard(self._keyboard_closed, self) diff --git a/helpers/music_file.py b/helpers/music_file.py index f1aa341..f391ff4 100644 --- a/helpers/music_file.py +++ b/helpers/music_file.py @@ -7,6 +7,7 @@ import os.path from .lock import Lock from . import Config, gain +from .mixer import Mixer file_lock = Lock("file") @@ -31,6 +32,7 @@ class MusicFile(Machine): Machine.__init__(self, states=states, transitions=transitions, initial='initial') + self.mixer = mapping.mixer or Mixer() self.volume = 100 self.mapping = mapping self.filename = filename @@ -95,7 +97,7 @@ class MusicFile(Machine): self.start_playing() def on_enter_loaded_playing(self): - self.mapping.mixer.add_file(self) + self.mixer.add_file(self) def finished_callback(self): if self.is_loaded_playing(): @@ -104,7 +106,7 @@ class MusicFile(Machine): self.stopped() def trigger_stopped_events(self): - self.mapping.mixer.remove_file(self) + self.mixer.remove_file(self) self.wait_event.set() def play_callback(self, out_data_length, frame_count):