]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/commitdiff
Add music-path option to the command line
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Wed, 27 Jul 2016 00:27:23 +0000 (02:27 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Wed, 27 Jul 2016 00:27:23 +0000 (02:27 +0200)
helpers/__init__.py
helpers/music_file.py

index 534e168a6898790d66cf1bdba1b88674ba12d3b3..f1a968b298065dddfebe5c52649507fffd891111 100644 (file)
@@ -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):
index ba8614204e030423c2aa71baca8b3f084143e759..916b95526fcff251d09717577e2d23a77273e9c3 100644 (file)
@@ -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) \