Skip to content

Commit

Permalink
Add library version query
Browse files Browse the repository at this point in the history
  • Loading branch information
HEnquist committed Oct 18, 2020
1 parent 0ae0cf0 commit af848b3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ The CamillaConnection class provides the following methods:
|`disconnect()` | Close the connection to the websocket.|
|`is_connected()` | Is websocket connected? Returns True or False.|
|`get_version()` | Read CamillaDSP version, returns a tuple with 3 elements|
|`get_library_version()` | Read pyCamillaDSP version, returns a tuple with 3 elements|
|`get_state()` | Get current processing state. Returns one of "RUNNING", "PAUSED" or "INACTIVE".|
|`get_signal_range()` | Get current signal range.|
|`get_signal_range_dB()` | Get current signal range in dB.|
Expand Down
14 changes: 11 additions & 3 deletions camilladsp/camilladsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import math
from threading import Lock

standard_rates = [
VERSION = (0, 4, 1)

STANDARD_RATES = [
8000,
11025,
16000,
Expand Down Expand Up @@ -121,6 +123,10 @@ def get_version(self):
"""Read CamillaDSP version, returns a tuple of (major, minor, patch)."""
return self._version

def get_library_version(self):
"""Read pycamilladsp version, returns a tuple of (major, minor, patch)."""
return VERSION

def get_state(self):
"""
Get current processing state.
Expand Down Expand Up @@ -158,8 +164,8 @@ def get_capture_rate(self):
Get current capture rate. Returns the nearest common value.
"""
rate = self.get_capture_rate_raw()
if 0.9 * standard_rates[0] < rate < 1.1 * standard_rates[-1]:
return min(standard_rates, key=lambda val: abs(val - rate))
if 0.9 * STANDARD_RATES[0] < rate < 1.1 * STANDARD_RATES[-1]:
return min(STANDARD_RATES, key=lambda val: abs(val - rate))
else:
return None

Expand Down Expand Up @@ -340,3 +346,5 @@ def validate_config(self, config_object):
print("ValidateConfig OK:", valconf)
except CamillaError as e:
print("ValidateConfig Error:", e)

#cdsp.disconnect()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="camilladsp",
version="0.4.0",
version="0.4.1",
author="Henrik Enquist",
author_email="[email protected]",
description="A library for comminucating with CamillaDSP",
Expand Down
1 change: 1 addition & 0 deletions tests/test_camillaws.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def test_connect(camilla_mockws):
assert camilla_mockws.is_connected()
assert camilla_mockws.get_state() == "IDLE"
assert camilla_mockws.get_version() == ('0', '3', '2')
assert camilla_mockws.get_library_version() == camilladsp.camilladsp.VERSION
camilla_mockws.disconnect()
assert not camilla_mockws.is_connected()

Expand Down

0 comments on commit af848b3

Please sign in to comment.