diff options
Diffstat (limited to 'helpers/__init__.py')
-rw-r--r-- | helpers/__init__.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/helpers/__init__.py b/helpers/__init__.py index ce8f04b..da447d8 100644 --- a/helpers/__init__.py +++ b/helpers/__init__.py | |||
@@ -4,6 +4,7 @@ import sys | |||
4 | import os | 4 | import os |
5 | import math | 5 | import math |
6 | import sounddevice as sd | 6 | import sounddevice as sd |
7 | import logging | ||
7 | 8 | ||
8 | class Config: | 9 | class Config: |
9 | pass | 10 | pass |
@@ -32,6 +33,10 @@ def parse_args(): | |||
32 | default="config.yml", | 33 | default="config.yml", |
33 | required=False, | 34 | required=False, |
34 | help="Config file to load") | 35 | help="Config file to load") |
36 | parser.add_argument("-d", "--debug", | ||
37 | nargs=0, | ||
38 | action=DebugModeAction, | ||
39 | help="Print messages in console") | ||
35 | parser.add_argument("-m", "--builtin-mixing", | 40 | parser.add_argument("-m", "--builtin-mixing", |
36 | action="store_true", | 41 | action="store_true", |
37 | help="Make the mixing of sounds manually (do it if the system cannot handle it correctly)") | 42 | help="Make the mixing of sounds manually (do it if the system cannot handle it correctly)") |
@@ -75,9 +80,14 @@ def parse_args(): | |||
75 | parser.add_argument('--', | 80 | parser.add_argument('--', |
76 | dest="args", | 81 | dest="args", |
77 | help="Kivy arguments. All arguments after this are interpreted by Kivy. Pass \"-- --help\" to get Kivy's usage.") | 82 | help="Kivy arguments. All arguments after this are interpreted by Kivy. Pass \"-- --help\" to get Kivy's usage.") |
83 | |||
84 | from kivy.logger import Logger | ||
85 | Logger.setLevel(logging.ERROR) | ||
86 | |||
78 | args = parser.parse_args(argv) | 87 | args = parser.parse_args(argv) |
79 | 88 | ||
80 | Config.yml_file = args.config | 89 | Config.yml_file = args.config |
90 | |||
81 | Config.latency = args.latency | 91 | Config.latency = args.latency |
82 | Config.blocksize = args.blocksize | 92 | Config.blocksize = args.blocksize |
83 | Config.frame_rate = args.frame_rate | 93 | Config.frame_rate = args.frame_rate |
@@ -85,6 +95,11 @@ def parse_args(): | |||
85 | Config.sample_width = args.sample_width | 95 | Config.sample_width = args.sample_width |
86 | Config.builtin_mixing = args.builtin_mixing | 96 | Config.builtin_mixing = args.builtin_mixing |
87 | 97 | ||
98 | class DebugModeAction(argparse.Action): | ||
99 | def __call__(self, parser, namespace, values, option_string=None): | ||
100 | from kivy.logger import Logger | ||
101 | Logger.setLevel(logging.DEBUG) | ||
102 | |||
88 | class SelectDeviceAction(argparse.Action): | 103 | class SelectDeviceAction(argparse.Action): |
89 | def __call__(self, parser, namespace, values, option_string=None): | 104 | def __call__(self, parser, namespace, values, option_string=None): |
90 | sd.default.device = values | 105 | sd.default.device = values |
@@ -116,3 +131,10 @@ def gain(volume, old_volume = None): | |||
116 | else: | 131 | else: |
117 | return [20 * math.log10(max(volume, 0.1) / max(old_volume, 0.1)), max(volume, 0)] | 132 | return [20 * math.log10(max(volume, 0.1) / max(old_volume, 0.1)), max(volume, 0)] |
118 | 133 | ||
134 | def debug_print(message): | ||
135 | from kivy.logger import Logger | ||
136 | Logger.debug('MusicSampler: ' + message) | ||
137 | |||
138 | def error_print(message): | ||
139 | from kivy.logger import Logger | ||
140 | Logger.error('MusicSampler: ' + message) | ||