Skip to content

Commit 45b566e

Browse files
authored
Merge pull request #22 from HEnquist/support_38
Support python 3.8
2 parents fdd5d67 + 7ede497 commit 45b566e

File tree

2 files changed

+44
-43
lines changed

2 files changed

+44
-43
lines changed

camilladsp/camilladsp.py

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import json
1616
import math
17-
from typing import Optional
17+
from typing import Dict, Tuple, List, Optional
1818
from threading import Lock
1919
import yaml
2020
from websocket import create_connection, WebSocket # type: ignore
@@ -47,7 +47,7 @@ def __init__(self, host: str, port: int):
4747
self._host = host
4848
self._port = int(port)
4949
self._ws: Optional[WebSocket] = None
50-
self.cdsp_version: Optional[tuple[str, str, str]] = None
50+
self.cdsp_version: Optional[Tuple[str, str, str]] = None
5151
self._lock = Lock()
5252

5353
def query(self, command: str, arg=None):
@@ -217,39 +217,39 @@ def range_decibel(self) -> float:
217217
range_decibel = -1000
218218
return range_decibel
219219

220-
def capture_rms(self) -> list[float]:
220+
def capture_rms(self) -> List[float]:
221221
"""
222222
Get capture signal level rms in dB for the last processed chunk.
223223
Full scale is 0 dB. Returns a list with one element per channel.
224224
"""
225225
sigrms = self.client.query("GetCaptureSignalRms")
226226
return sigrms
227227

228-
def playback_rms(self) -> list[float]:
228+
def playback_rms(self) -> List[float]:
229229
"""
230230
Get playback signal level rms in dB for the last processed chunk.
231231
Full scale is 0 dB. Returns a list with one element per channel.
232232
"""
233233
sigrms = self.client.query("GetPlaybackSignalRms")
234234
return sigrms
235235

236-
def capture_peak(self) -> list[float]:
236+
def capture_peak(self) -> List[float]:
237237
"""
238238
Get capture signal level peak in dB for the last processed chunk.
239239
Full scale is 0 dB. Returns a list with one element per channel.
240240
"""
241241
sigpeak = self.client.query("GetCaptureSignalPeak")
242242
return sigpeak
243243

244-
def playback_peak(self) -> list[float]:
244+
def playback_peak(self) -> List[float]:
245245
"""
246246
Get playback signal level peak in dB for the last processed chunk.
247247
Full scale is 0 dB. Returns a list with one element per channel.
248248
"""
249249
sigpeak = self.client.query("GetPlaybackSignalPeak")
250250
return sigpeak
251251

252-
def playback_peak_since(self, interval: float) -> list[float]:
252+
def playback_peak_since(self, interval: float) -> List[float]:
253253
"""
254254
Get playback signal level peak in dB for the last `interval` seconds.
255255
Full scale is 0 dB. Returns a list with one element per channel.
@@ -260,7 +260,7 @@ def playback_peak_since(self, interval: float) -> list[float]:
260260
sigpeak = self.client.query("GetPlaybackSignalPeakSince", arg=float(interval))
261261
return sigpeak
262262

263-
def playback_rms_since(self, interval: float) -> list[float]:
263+
def playback_rms_since(self, interval: float) -> List[float]:
264264
"""
265265
Get playback signal level rms in dB for the last `interval` seconds.
266266
Full scale is 0 dB. Returns a list with one element per channel.
@@ -271,7 +271,7 @@ def playback_rms_since(self, interval: float) -> list[float]:
271271
sigrms = self.client.query("GetPlaybackSignalRmsSince", arg=float(interval))
272272
return sigrms
273273

274-
def capture_peak_since(self, interval: float) -> list[float]:
274+
def capture_peak_since(self, interval: float) -> List[float]:
275275
"""
276276
Get capture signal level peak in dB for the last `interval` seconds.
277277
Full scale is 0 dB. Returns a list with one element per channel.
@@ -282,7 +282,7 @@ def capture_peak_since(self, interval: float) -> list[float]:
282282
sigpeak = self.client.query("GetCaptureSignalPeakSince", arg=float(interval))
283283
return sigpeak
284284

285-
def capture_rms_since(self, interval: float) -> list[float]:
285+
def capture_rms_since(self, interval: float) -> List[float]:
286286
"""
287287
Get capture signal level rms in dB for the last `interval` seconds.
288288
Full scale is 0 dB. Returns a list with one element per channel.
@@ -293,39 +293,39 @@ def capture_rms_since(self, interval: float) -> list[float]:
293293
sigrms = self.client.query("GetCaptureSignalRmsSince", arg=float(interval))
294294
return sigrms
295295

296-
def playback_peak_since_last(self) -> list[float]:
296+
def playback_peak_since_last(self) -> List[float]:
297297
"""
298298
Get playback signal level peak in dB since the last read by the same client.
299299
Full scale is 0 dB. Returns a list with one element per channel.
300300
"""
301301
sigpeak = self.client.query("GetPlaybackSignalPeakSinceLast")
302302
return sigpeak
303303

304-
def playback_rms_since_last(self) -> list[float]:
304+
def playback_rms_since_last(self) -> List[float]:
305305
"""
306306
Get playback signal level rms in dB since the last read by the same client.
307307
Full scale is 0 dB. Returns a list with one element per channel.
308308
"""
309309
sigrms = self.client.query("GetPlaybackSignalRmsSinceLast")
310310
return sigrms
311311

312-
def capture_peak_since_last(self) -> list[float]:
312+
def capture_peak_since_last(self) -> List[float]:
313313
"""
314314
Get capture signal level peak in dB since the last read by the same client.
315315
Full scale is 0 dB. Returns a list with one element per channel.
316316
"""
317317
sigpeak = self.client.query("GetCaptureSignalPeakSinceLast")
318318
return sigpeak
319319

320-
def capture_rms_since_last(self) -> list[float]:
320+
def capture_rms_since_last(self) -> List[float]:
321321
"""
322322
Get capture signal level rms in dB since the last read by the same client.
323323
Full scale is 0 dB. Returns a list with one element per channel.
324324
"""
325325
sigrms = self.client.query("GetCaptureSignalRmsSinceLast")
326326
return sigrms
327327

328-
def levels(self) -> dict[str, list[float]]:
328+
def levels(self) -> Dict[str, List[float]]:
329329
"""
330330
Get all signal levels in dB for the last processed chunk.
331331
Full scale is 0 dB.
@@ -336,7 +336,7 @@ def levels(self) -> dict[str, list[float]]:
336336
siglevels = self.client.query("GetSignalLevels")
337337
return siglevels
338338

339-
def levels_since(self, interval: float) -> dict[str, list[float]]:
339+
def levels_since(self, interval: float) -> Dict[str, List[float]]:
340340
"""
341341
Get all signal levels in dB for the last `interval` seconds.
342342
Full scale is 0 dB.
@@ -350,7 +350,7 @@ def levels_since(self, interval: float) -> dict[str, list[float]]:
350350
siglevels = self.client.query("GetSignalLevelsSince", arg=float(interval))
351351
return siglevels
352352

353-
def levels_since_last(self) -> dict[str, list[float]]:
353+
def levels_since_last(self) -> Dict[str, List[float]]:
354354
"""
355355
Get all signal levels in dB since the last read by the same client.
356356
Full scale is 0 dB.
@@ -361,7 +361,7 @@ def levels_since_last(self) -> dict[str, list[float]]:
361361
siglevels = self.client.query("GetSignalLevelsSinceLast")
362362
return siglevels
363363

364-
def peaks_since_start(self) -> dict[str, list[float]]:
364+
def peaks_since_start(self) -> Dict[str, List[float]]:
365365
"""
366366
Get the playback and capture peak level since processing started.
367367
The values are returned as a json object with keys `playback` and `capture`.
@@ -420,31 +420,31 @@ def set_active_raw(self, config_string: str):
420420
"""
421421
self.client.query("SetConfig", arg=config_string)
422422

423-
def active(self) -> Optional[dict]:
423+
def active(self) -> Optional[Dict]:
424424
"""
425425
Get the active configuration as a Python object.
426426
427427
Returns:
428-
dict | None: Current config as a Python dict, or None.
428+
Dict | None: Current config as a Python dict, or None.
429429
"""
430430
config_string = self.active_raw()
431431
if config_string is None:
432432
return None
433433
config_object = yaml.safe_load(config_string)
434434
return config_object
435435

436-
def previous(self) -> Optional[dict]:
436+
def previous(self) -> Optional[Dict]:
437437
"""
438438
Get the previously active configuration as a Python object.
439439
440440
Returns:
441-
dict | None: Previous config as a Python dict, or None.
441+
Dict | None: Previous config as a Python dict, or None.
442442
"""
443443
config_string = self.client.query("GetPreviousConfig")
444444
config_object = yaml.safe_load(config_string)
445445
return config_object
446446

447-
def parse_yaml(self, config_string: str) -> dict:
447+
def parse_yaml(self, config_string: str) -> Dict:
448448
"""
449449
Parse a config from yaml string and return the contents
450450
as a Python object, with defaults filled out with their default values.
@@ -453,47 +453,47 @@ def parse_yaml(self, config_string: str) -> dict:
453453
config_string (str): A config as raw yaml string.
454454
455455
Returns:
456-
dict | None: Parsed config as a Python dict.
456+
Dict | None: Parsed config as a Python dict.
457457
"""
458458
config_raw = self.client.query("ReadConfig", arg=config_string)
459459
config_object = yaml.safe_load(config_raw)
460460
return config_object
461461

462-
def read_and_parse_file(self, filename: str) -> dict:
462+
def read_and_parse_file(self, filename: str) -> Dict:
463463
"""
464464
Read and parse a config file from disk and return the contents as a Python object.
465465
466466
Args:
467467
filename (str): Path to a config file.
468468
469469
Returns:
470-
dict | None: Parsed config as a Python dict.
470+
Dict | None: Parsed config as a Python dict.
471471
"""
472472
config_raw = self.client.query("ReadConfigFile", arg=filename)
473473
config = yaml.safe_load(config_raw)
474474
return config
475475

476-
def set_active(self, config_object: dict):
476+
def set_active(self, config_object: Dict):
477477
"""
478478
Upload and apply a new configuration from a Python object.
479479
480480
Args:
481-
config_object (dict): A configuration as a Python dict.
481+
config_object (Dict): A configuration as a Python dict.
482482
"""
483483
config_raw = yaml.dump(config_object)
484484
self.set_active_raw(config_raw)
485485

486-
def validate(self, config_object: dict) -> dict:
486+
def validate(self, config_object: Dict) -> Dict:
487487
"""
488488
Validate a configuration object.
489489
Returns the validated config with all optional fields filled with defaults.
490490
Raises a CamillaError on errors.
491491
492492
Args:
493-
config_object (dict): A configuration as a Python dict.
493+
config_object (Dict): A configuration as a Python dict.
494494
495495
Returns:
496-
dict | None: Validated config as a Python dict.
496+
Dict | None: Validated config as a Python dict.
497497
"""
498498
config_string = yaml.dump(config_object)
499499
validated_string = self.client.query("ValidateConfig", arg=config_string)
@@ -773,14 +773,14 @@ def reload(self):
773773
"""
774774
self.client.query("Reload")
775775

776-
def supported_device_types(self) -> tuple[list[str], list[str]]:
776+
def supported_device_types(self) -> Tuple[List[str], List[str]]:
777777
"""
778778
Read what device types the running CamillaDSP process supports.
779779
Returns a tuple with two lists of device types,
780780
the first for playback and the second for capture.
781781
782782
Returns:
783-
tuple[list[str], list[str]]: A tuple containing two lists,
783+
Tuple[List[str], List[str]]: A tuple containing two lists,
784784
with the supported playback and capture device types.
785785
"""
786786
(playback, capture) = self.client.query("GetSupportedDeviceTypes")
@@ -806,29 +806,29 @@ def state_file_updated(self) -> bool:
806806
updated = self.client.query("GetStateFileUpdated")
807807
return updated
808808

809-
def list_playback_devices(self, value: str) -> list[tuple[str, str]]:
809+
def list_playback_devices(self, value: str) -> List[Tuple[str, str]]:
810810
"""
811811
List the available playback devices for a given backend.
812812
Returns a list of tuples. Returns the system name and
813813
a descriptive name for each device.
814814
For some backends, those two names are identical.
815815
816816
Returns:
817-
list[tuple[str, str]: A list containing tuples of two strings,
817+
List[Tuple[str, str]: A list containing tuples of two strings,
818818
with system device name and a descriptive name.
819819
"""
820820
devs = self.client.query("GetAvailablePlaybackDevices", arg=value)
821821
return devs
822822

823-
def list_capture_devices(self, value: str) -> list[tuple[str, str]]:
823+
def list_capture_devices(self, value: str) -> List[Tuple[str, str]]:
824824
"""
825825
List the available capture devices for a given backend.
826826
Returns a list of tuples. Returns the system name and
827827
a descriptive name for each device.
828828
For some backends, those two names are identical.
829829
830830
Returns:
831-
list[tuple[str, str]: A list containing tuples of two strings,
831+
List[Tuple[str, str]: A list containing tuples of two strings,
832832
with system device name and a descriptive name.
833833
"""
834834
devs = self.client.query("GetAvailableCaptureDevices", arg=value)
@@ -840,25 +840,26 @@ class Versions(_CommandGroup):
840840
Version info
841841
"""
842842

843-
def camilladsp(self) -> Optional[tuple[str, str, str]]:
843+
def camilladsp(self) -> Optional[Tuple[str, str, str]]:
844844
"""
845845
Read CamillaDSP version.
846846
847847
Returns:
848-
tuple[list[str], list[str]] | None: A tuple containing the CamillaDSP version,
848+
Tuple[List[str], List[str]] | None: A tuple containing the CamillaDSP version,
849849
as (major, minor, patch).
850850
"""
851851
return self.client.cdsp_version
852852

853-
def library(self) -> tuple[str, str, str]:
853+
def library(self) -> Tuple[str, str, str]:
854854
"""
855855
Read pyCamillaDSP library version.
856856
857857
Returns:
858-
tuple[list[str], list[str]] | None: A tuple containing the pyCamillaDSP version,
858+
Tuple[List[str], List[str]] | None: A tuple containing the pyCamillaDSP version,
859859
as (major, minor, patch).
860860
"""
861-
return VERSION.split(".")
861+
v = VERSION.split(".")
862+
return (v[0], v[1], v[2])
862863

863864

864865
class CamillaClient(_CamillaWS):

tests/test_camillaws.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_connect(camilla_mockws):
8989
assert camilla_mockws.is_connected()
9090
assert camilla_mockws.general.state() == camilladsp.ProcessingState.INACTIVE
9191
assert camilla_mockws.versions.camilladsp() == ('0', '3', '2')
92-
assert camilla_mockws.versions.library() == camilladsp.camilladsp.VERSION.split(".")
92+
assert camilla_mockws.versions.library() == tuple(camilladsp.camilladsp.VERSION.split("."))
9393
camilla_mockws.disconnect()
9494
assert not camilla_mockws.is_connected()
9595

0 commit comments

Comments
 (0)