From 6da344a75f27ffb5000f3aa9f7f2c6ac4b6871e4 Mon Sep 17 00:00:00 2001 From: Levent K Date: Sun, 6 Oct 2019 18:20:41 +0200 Subject: [PATCH] Fixing exception if index of selected microphone has changed Fixing exception if index in self.devices of selected microphone has changed. This will make it more stable, because it will search for the new array index in self.devices --- python/main.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/python/main.py b/python/main.py index dfa7a73..8e7e1df 100644 --- a/python/main.py +++ b/python/main.py @@ -855,9 +855,15 @@ def setDevice(self, device_id): # set device to stream from by the id of the device if not device_id in range(0,self.numdevices): raise ValueError("No device with id {}".format(device_id)) - self.device_id = self.devices[device_id]["index"] - self.device_name = self.devices[device_id]["name"] - self.device_rate = int(self.devices[device_id]["defaultSampleRate"]) + + device_pos = device_id + for device in self.devices: + if device["index"] == device_id: + device_pos = self.devices.index(device) + + self.device_id = self.devices[device_pos]["index"] + self.device_name = self.devices[device_pos]["name"] + self.device_rate = int(self.devices[device_pos]["defaultSampleRate"]) self.frames_per_buffer = self.device_rate // config.settings["configuration"]["FPS"] config.settings["mic_config"]["MIC_ID"] = self.device_id @@ -2050,4 +2056,4 @@ def microphone_update(audio_samples): save_config_dicts() colour_manager.saveColours() colour_manager.saveGradients() - py_audio.terminate() \ No newline at end of file + py_audio.terminate()