aboutsummaryrefslogtreecommitdiffstats
path: root/solo-tool-project/src/solo_tool/metronome.py
diff options
context:
space:
mode:
authorEddy Pedroni <epedroni@pm.me>2026-10-13 20:36:02 +0200
committerEddy Pedroni <epedroni@pm.me>2026-10-13 20:36:02 +0200
commit05a3406de3e26d21865db87960f80c5f40f9cd83 (patch)
tree372597a6c1210cb1203238b7193ce6dcd565a5fa /solo-tool-project/src/solo_tool/metronome.py
parentedc8d820df84c147ddb6e723b9639bddd6d15344 (diff)
Add option to specify audio device (only applicable for metronome and recorder)
Diffstat (limited to 'solo-tool-project/src/solo_tool/metronome.py')
-rw-r--r--solo-tool-project/src/solo_tool/metronome.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/solo-tool-project/src/solo_tool/metronome.py b/solo-tool-project/src/solo_tool/metronome.py
index 9c65357..3ffc6bc 100644
--- a/solo-tool-project/src/solo_tool/metronome.py
+++ b/solo-tool-project/src/solo_tool/metronome.py
@@ -1,6 +1,8 @@
import pyaudio as pa
from array import array
+from solo_tool.utils import getAudioDeviceIndex
+
def _createClickSample(clickFrequency: int, samplingRate: int) -> array:
clickDuration = 0.03 # seconds
@@ -22,9 +24,10 @@ def _createOutputBuffer(bpm: int, clickFrequency: int, samplingRate: int) -> arr
return clickSample + array('h', [0] * (samplesPerBeat - len(clickSample)))
class Metronome:
- def __init__(self, bufferSize: int, samplingRate: int):
+ def __init__(self, bufferSize: int, samplingRate: int, deviceName: str):
self._bufferSize = bufferSize
self._samplingRate = samplingRate
+ self._deviceName = deviceName
self._sampleFormat = pa.paInt16
self._channels = 1
self._pa = pa.PyAudio()
@@ -58,6 +61,7 @@ class Metronome:
rate=self._samplingRate,
frames_per_buffer=self._bufferSize,
output=True,
+ output_device_index=getAudioDeviceIndex(self._deviceName, self._pa),
stream_callback=self._callback)
def stop(self) -> None: