aboutsummaryrefslogtreecommitdiff
path: root/helpers/__init__.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-17 17:31:07 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-17 17:31:07 +0200
commita24c34bc1458c4b0962773d804fac4d325632ee8 (patch)
tree140fe654ca0efaa600eb5f2ea3b9c6dfa78ac1f7 /helpers/__init__.py
parentc80ff6dc4579ab28c4064576db5a4859e639c504 (diff)
downloadMusicSampler-a24c34bc1458c4b0962773d804fac4d325632ee8.tar.gz
MusicSampler-a24c34bc1458c4b0962773d804fac4d325632ee8.tar.zst
MusicSampler-a24c34bc1458c4b0962773d804fac4d325632ee8.zip
Add debugger
Diffstat (limited to 'helpers/__init__.py')
-rw-r--r--helpers/__init__.py22
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
4import os 4import os
5import math 5import math
6import sounddevice as sd 6import sounddevice as sd
7import logging
7 8
8class Config: 9class 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
98class 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
88class SelectDeviceAction(argparse.Action): 103class 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
134def debug_print(message):
135 from kivy.logger import Logger
136 Logger.debug('MusicSampler: ' + message)
137
138def error_print(message):
139 from kivy.logger import Logger
140 Logger.error('MusicSampler: ' + message)