diff options
Diffstat (limited to 'helpers/__init__.py')
-rw-r--r-- | helpers/__init__.py | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/helpers/__init__.py b/helpers/__init__.py index 4b9529d..807aa44 100644 --- a/helpers/__init__.py +++ b/helpers/__init__.py | |||
@@ -6,11 +6,7 @@ import math | |||
6 | import sounddevice as sd | 6 | import sounddevice as sd |
7 | 7 | ||
8 | class Config: | 8 | class Config: |
9 | def __init__(self, **kwargs): | 9 | pass |
10 | for arg in kwargs: | ||
11 | setattr(self, arg, kwargs[arg]) | ||
12 | |||
13 | config = Config(yml_file="config.yml") | ||
14 | 10 | ||
15 | def path(): | 11 | def path(): |
16 | if getattr(sys, 'frozen', False): | 12 | if getattr(sys, 'frozen', False): |
@@ -29,11 +25,37 @@ def parse_args(): | |||
29 | 25 | ||
30 | sys.argv.extend(kivy_args) | 26 | sys.argv.extend(kivy_args) |
31 | 27 | ||
32 | parser = argparse.ArgumentParser(description="A Music Sampler application.") | 28 | parser = argparse.ArgumentParser( |
29 | description="A Music Sampler application.", | ||
30 | formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
33 | parser.add_argument("-c", "--config", | 31 | parser.add_argument("-c", "--config", |
34 | default="config.yml", | 32 | default="config.yml", |
35 | required=False, | 33 | required=False, |
36 | help="Config file to load") | 34 | help="Config file to load") |
35 | parser.add_argument("-l", "--latency", | ||
36 | default="high", | ||
37 | required=False, | ||
38 | help="Latency: low, high or number of seconds") | ||
39 | parser.add_argument("-b", "--blocksize", | ||
40 | default=0, | ||
41 | type=int, | ||
42 | required=False, | ||
43 | help="Blocksize: If not 0, the numbe of frames to take at each step for the mixer") | ||
44 | parser.add_argument("-f", "--frame-rate", | ||
45 | default=44100, | ||
46 | type=int, | ||
47 | required=False, | ||
48 | help="Frame rate to play the musics") | ||
49 | parser.add_argument("-x", "--channels", | ||
50 | default=2, | ||
51 | type=int, | ||
52 | required=False, | ||
53 | help="Number of channels to use") | ||
54 | parser.add_argument("-s", "--sample-width", | ||
55 | default=2, | ||
56 | type=int, | ||
57 | required=False, | ||
58 | help="Sample width (number of bytes for each frame)") | ||
37 | parser.add_argument("-V", "--version", | 59 | parser.add_argument("-V", "--version", |
38 | action="version", | 60 | action="version", |
39 | help="Displays the current version and exits. Only use in bundled package", | 61 | help="Displays the current version and exits. Only use in bundled package", |
@@ -52,7 +74,12 @@ def parse_args(): | |||
52 | help="Kivy arguments. All arguments after this are interpreted by Kivy. Pass \"-- --help\" to get Kivy's usage.") | 74 | help="Kivy arguments. All arguments after this are interpreted by Kivy. Pass \"-- --help\" to get Kivy's usage.") |
53 | args = parser.parse_args(argv) | 75 | args = parser.parse_args(argv) |
54 | 76 | ||
55 | config.yml_file = args.config | 77 | Config.yml_file = args.config |
78 | Config.latency = args.latency | ||
79 | Config.blocksize = args.blocksize | ||
80 | Config.frame_rate = args.frame_rate | ||
81 | Config.channels = args.channels | ||
82 | Config.sample_width = args.sample_width | ||
56 | 83 | ||
57 | class SelectDeviceAction(argparse.Action): | 84 | class SelectDeviceAction(argparse.Action): |
58 | def __call__(self, parser, namespace, values, option_string=None): | 85 | def __call__(self, parser, namespace, values, option_string=None): |
@@ -71,9 +98,6 @@ def show_version(): | |||
71 | else: | 98 | else: |
72 | return "option '-v' can only be used in bundled package" | 99 | return "option '-v' can only be used in bundled package" |
73 | 100 | ||
74 | def yml_file(): | ||
75 | return config.yml_file | ||
76 | |||
77 | def duration_to_min_sec(duration): | 101 | def duration_to_min_sec(duration): |
78 | minutes = int(duration / 60) | 102 | minutes = int(duration / 60) |
79 | seconds = int(duration) % 60 | 103 | seconds = int(duration) % 60 |