From: Ismaël Bouya Date: Wed, 27 Jul 2016 00:27:23 +0000 (+0200) Subject: Add music-path option to the command line X-Git-Tag: 1.0.0~12 X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git;a=commitdiff_plain;h=940bb6ad6cbd823ed245577093bd8959e189d43f Add music-path option to the command line --- diff --git a/helpers/__init__.py b/helpers/__init__.py index 534e168..f1a968b 100644 --- a/helpers/__init__.py +++ b/helpers/__init__.py @@ -33,6 +33,10 @@ def parse_args(): default="config.yml", required=False, help="Config file to load") + parser.add_argument("-p", "--music-path", + default=".", + required=False, + help="Folder in which to find the music files") parser.add_argument("-d", "--debug", nargs=0, action=DebugModeAction, @@ -98,6 +102,10 @@ def parse_args(): Config.channels = args.channels Config.sample_width = args.sample_width Config.builtin_mixing = args.builtin_mixing + if args.music_path.endswith("/"): + Config.music_path = args.music_path + else: + Config.music_path = args.music_path + "/" class DebugModeAction(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): diff --git a/helpers/music_file.py b/helpers/music_file.py index ba86142..916b955 100644 --- a/helpers/music_file.py +++ b/helpers/music_file.py @@ -104,7 +104,7 @@ class MusicFile: debug_print("Reloading « {} »".format(self.name)) initial_db_gain = gain(self.initial_volume_factor * 100) self.audio_segment = pydub.AudioSegment \ - .from_file(self.filename) \ + .from_file(Config.music_path + self.filename) \ .set_frame_rate(Config.frame_rate) \ .set_channels(Config.channels) \ .set_sample_width(Config.sample_width) \ @@ -125,7 +125,7 @@ class MusicFile: self.mixer = self.mapping.mixer or Mixer() initial_db_gain = gain(self.initial_volume_factor * 100) self.audio_segment = pydub.AudioSegment \ - .from_file(self.filename) \ + .from_file(Config.music_path + self.filename) \ .set_frame_rate(Config.frame_rate) \ .set_channels(Config.channels) \ .set_sample_width(Config.sample_width) \