aboutsummaryrefslogtreecommitdiff
path: root/music_sampler/helpers.py
diff options
context:
space:
mode:
Diffstat (limited to 'music_sampler/helpers.py')
-rw-r--r--music_sampler/helpers.py33
1 files changed, 25 insertions, 8 deletions
diff --git a/music_sampler/helpers.py b/music_sampler/helpers.py
index 68c1328..6acaba4 100644
--- a/music_sampler/helpers.py
+++ b/music_sampler/helpers.py
@@ -29,11 +29,11 @@ def register_fonts():
29 symbola = find_font("Symbola") 29 symbola = find_font("Symbola")
30 30
31 if ubuntu_regular is None: 31 if ubuntu_regular is None:
32 error_print("Font Ubuntu regular could not be found, please install it.") 32 error_print("Font Ubuntu regular could not be found, "
33 sys.exit() 33 "please install it.", exit=True)
34 if symbola is None: 34 if symbola is None:
35 error_print("Font Symbola could not be found, please install it.") 35 error_print("Font Symbola could not be found, please install it.",
36 sys.exit() 36 exit=True)
37 if ubuntu_bold is None: 37 if ubuntu_bold is None:
38 warn_print("Font Ubuntu Bold could not be found.") 38 warn_print("Font Ubuntu Bold could not be found.")
39 39
@@ -180,12 +180,29 @@ def gain(volume, old_volume=None):
180 20 * math.log10(max(volume, 0.1) / max(old_volume, 0.1)), 180 20 * math.log10(max(volume, 0.1) / max(old_volume, 0.1)),
181 max(volume, 0)] 181 max(volume, 0)]
182 182
183def debug_print(message, with_trace=False): 183def debug_print(message, with_trace=None):
184 if with_trace is None:
185 with_trace = (Logger.getEffectiveLevel() < logging.WARN)
186 with_trace &= (sys.exc_info()[0] is not None)
187
184 Logger.debug('MusicSampler: ' + message, exc_info=with_trace) 188 Logger.debug('MusicSampler: ' + message, exc_info=with_trace)
185 189
186def error_print(message, with_trace=False): 190def error_print(message, exit=False, with_trace=None):
187 Logger.error('MusicSampler: ' + message, exc_info=with_trace) 191 if with_trace is None:
192 with_trace = (Logger.getEffectiveLevel() < logging.WARN)
193 with_trace &= (sys.exc_info()[0] is not None)
194
195 # FIXME: handle it correctly when in a thread
196 if exit:
197 Logger.critical('MusicSampler: ' + message, exc_info=with_trace)
198 sys.exit(1)
199 else:
200 Logger.error('MusicSampler: ' + message, exc_info=with_trace)
201
202def warn_print(message, with_trace=None):
203 if with_trace is None:
204 with_trace = (Logger.getEffectiveLevel() < logging.WARN)
205 with_trace &= (sys.exc_info()[0] is not None)
188 206
189def warn_print(message, with_trace=False):
190 Logger.warn('MusicSampler: ' + message, exc_info=with_trace) 207 Logger.warn('MusicSampler: ' + message, exc_info=with_trace)
191 208