symbola = find_font("Symbola")
if ubuntu_regular is None:
- error_print("Font Ubuntu regular could not be found, please install it.")
- sys.exit()
+ error_print("Font Ubuntu regular could not be found, "
+ "please install it.", exit=True)
if symbola is None:
- error_print("Font Symbola could not be found, please install it.")
- sys.exit()
+ error_print("Font Symbola could not be found, please install it.",
+ exit=True)
if ubuntu_bold is None:
warn_print("Font Ubuntu Bold could not be found.")
20 * math.log10(max(volume, 0.1) / max(old_volume, 0.1)),
max(volume, 0)]
-def debug_print(message, with_trace=False):
+def debug_print(message, with_trace=None):
+ if with_trace is None:
+ with_trace = (Logger.getEffectiveLevel() < logging.WARN)
+ with_trace &= (sys.exc_info()[0] is not None)
+
Logger.debug('MusicSampler: ' + message, exc_info=with_trace)
-def error_print(message, with_trace=False):
- Logger.error('MusicSampler: ' + message, exc_info=with_trace)
+def error_print(message, exit=False, with_trace=None):
+ if with_trace is None:
+ with_trace = (Logger.getEffectiveLevel() < logging.WARN)
+ with_trace &= (sys.exc_info()[0] is not None)
+
+ # FIXME: handle it correctly when in a thread
+ if exit:
+ Logger.critical('MusicSampler: ' + message, exc_info=with_trace)
+ sys.exit(1)
+ else:
+ Logger.error('MusicSampler: ' + message, exc_info=with_trace)
+
+def warn_print(message, with_trace=None):
+ if with_trace is None:
+ with_trace = (Logger.getEffectiveLevel() < logging.WARN)
+ with_trace &= (sys.exc_info()[0] is not None)
-def warn_print(message, with_trace=False):
Logger.warn('MusicSampler: ' + message, exc_info=with_trace)
self.key_config, self.open_files = self.parse_config()
except Exception as e:
error_print("Error while loading configuration: {}".format(e),
- with_trace=True)
- sys.exit()
+ with_trace=True, exit=True)
else:
self.success()
try:
config = yaml.safe_load(stream)
except Exception as e:
- error_print("Error while loading config file: {}".format(e))
- sys.exit()
+ error_print("Error while loading config file: {}".format(e),
+ exit=True)
stream.close()
if not isinstance(config, dict):
- raise Exception("Top level config is supposed to be a hash")
+ error_print("Top level config is supposed to be a hash",
+ exit=True)
if 'aliases' in config and isinstance(config['aliases'], dict):
aliases = config['aliases']
import audioop
import time
-from .helpers import Config
+from .helpers import Config, error_print
sample_width = Config.sample_width
-def sample_width_to_dtype(sample_width):
+def sample_width_to_dtype():
if sample_width == 1 or sample_width == 2 or sample_width == 4:
return 'int' + str(8*sample_width)
else:
- raise "Unknown sample width"
+ error_print("Unknown sample width, setting default value 2.")
+ Config.sample_width = 2
+ return 'int16'
def _latency(latency):
if latency == "high" or latency == "low":
self.stream = sd.RawOutputStream(
samplerate=Config.frame_rate,
channels=Config.channels,
- dtype=sample_width_to_dtype(Config.sample_width),
+ dtype=sample_width_to_dtype(),
latency=_latency(Config.latency),
blocksize=Config.blocksize,
callback=self.play_callback)
class GainEffect:
effect_types = [
+ 'noop',
'fade'
]
if effect in self.effect_types:
self.effect = effect
else:
- raise Exception("Unknown effect {}".format(effect))
+ self.effect = 'noop'
self.start = start
self.end = end
current_loop,
frame_count)
+ # Noop
+ def noop_init(self, **kwargs):
+ pass
+
+ def noop_get_last_gain(self, **kwargs):
+ return 0
+
+ def noop_get_next_gain(self, **kwargs):
+ return [0, True]
+
# Fading
def fade_init(self, gain=0, **kwargs):
self.audio_segment_frame_count = self.audio_segment.frame_count()