X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=helpers%2Fmixer.py;h=9242b61af9100e944b5060220bf40c0567741443;hb=205861936ca55357beea6a8af7c0c9ed5a61f484;hp=d08520a00cf7c3197ff63e37ec2c68d503addf58;hpb=75d6cdbac628b57e206cd37808c1d3c7fecbb9eb;p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git diff --git a/helpers/mixer.py b/helpers/mixer.py index d08520a..9242b61 100644 --- a/helpers/mixer.py +++ b/helpers/mixer.py @@ -5,6 +5,7 @@ import time from . import Config sample_width = Config.sample_width + def sample_width_to_dtype(sample_width): if sample_width == 1 or sample_width == 2 or sample_width == 4: return 'int' + str(8*sample_width) @@ -19,13 +20,13 @@ def _latency(latency): class Mixer: def __init__(self): - self.stream = sd.RawOutputStream(samplerate=Config.frame_rate, - channels=Config.channels, - dtype=sample_width_to_dtype(Config.sample_width), - latency=_latency(Config.latency), - blocksize=Config.blocksize, - callback=self.play_callback, - ) + self.stream = sd.RawOutputStream( + samplerate=Config.frame_rate, + channels=Config.channels, + dtype=sample_width_to_dtype(Config.sample_width), + latency=_latency(Config.latency), + blocksize=Config.blocksize, + callback=self.play_callback) self.open_files = [] def add_file(self, music_file): @@ -34,7 +35,8 @@ class Mixer: self.start() def remove_file(self, music_file): - self.open_files.remove(music_file) + if music_file in self.open_files: + self.open_files.remove(music_file) if len(self.open_files) == 0: self.stop()