Skip to content

Commit

Permalink
- fix: remove numpy warnings about denormals. This is caused when a l…
Browse files Browse the repository at this point in the history
…ibrary

  compiled with -ffast-math is loaded before numpy.
- new: check dependencies by default at every run. This solves some situations
  with lingerings installs. The only downside is that csound prints some
  messages to stderr at the end of performance and this cannot be avoided
  at the moment.
- fix: when checking csound version we also query installed opcodes, this
  reduces the number of csound processes started when checking dependencies
  to only 1
- fix: upgrade dependencies for risset. This is needed for support for
  universal builds of external csound plugins for macos.
  • Loading branch information
gesellkammer committed Apr 19, 2024
1 parent cd23587 commit a82a0ea
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 36 deletions.
12 changes: 6 additions & 6 deletions csoundengine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@
# Automate the cutoff freq. of the filter
filt.automate('kcutoff', [0, 2000, dur*0.8, 500, dur, 6000], delay=start)
"""
# sndfileio sets numpy's denormal behaviour. If it happens later numpy spits
# multiple warnings about it
import sndfileio
# This disables warning about denormals
import numpy as np
np.finfo(np.dtype("float32"))
np.finfo(np.dtype("float64"))

from .config import config, setLoggingLevel
from .dependencies import checkDependencies, installDependencies
ok = checkDependencies(force=False, fix=True)
if not ok:
_ok = checkDependencies(force=True, fix=True)
if not _ok:
raise RuntimeError("csoundengine: Depencencies not fullfilled")


from .engine import *
from .config import config, setLoggingLevel
from .session import Session
Expand Down
23 changes: 16 additions & 7 deletions csoundengine/csoundlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,23 +1042,32 @@ def opcodesList(cached=True, opcodedir: str = '') -> list[str]:


def _csoundGetInfoViaAPI(opcodedir='') -> dict:
global _cache

cs = ctcsound.Csound()
cs.setOption("-d") # supress displays
cs.setOption("-d")
cs.setOption("--nosound")
cs.setOption("--messagelevel=0")
cs.setOption("--m-amps=0")
cs.setOption("--m-range=0")

if opcodedir:
cs.setOption(f'--opcode-dir={opcodedir}')
opcodes, n = cs.newOpcodeList()
assert opcodes is not None
opcodeNames = [opc.opname.decode('utf-8') for opc in opcodes]
cs.disposeOpcodeList(opcodes)
version = cs.version()
vs = str(version)
patch = int(vs[-1])
minor = int(vs[-3:-1])
major = int(vs[:-3])
opcodes = list(set(opcodeNames))
versionTriplet = (major, minor, patch)
_cache['opcodes'] = opcodes
_cache['versionTriplet'] = versionTriplet

opcodes, n = cs.newOpcodeList()
assert opcodes is not None
opcodeNames = [opc.opname.decode('utf-8') for opc in opcodes]
cs.disposeOpcodeList(opcodes)
opcodes = list(set(opcodeNames))
_cache['opcodes'] = opcodes
cs.stop()
return {'opcodes': opcodes,
'versionTriplet': versionTriplet}

Expand Down
38 changes: 19 additions & 19 deletions csoundengine/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,8 @@ def _copyFiles(files: List[str], dest: str, verbose=False) -> None:
shutil.copy(f, dest)


def pluginsInstalled(cached: bool) -> bool:
def pluginsInstalled(cached=True) -> bool:
"""Returns True if the needed plugins are already installed"""
#opcodes = set(csoundlib.opcodesList(cached=cached,
# opcodedir=csoundlib.userPluginsFolder(apiversion=apiversion)))
opcodes = set(csoundlib.opcodesList(cached=cached))
neededOpcodes = {
"atstop", "pwrite", "pread", "initerror",
Expand Down Expand Up @@ -219,7 +217,7 @@ def _installPluginsViaRisset(majorversion: int | None = None) -> bool:
for pluginname in ['else', 'beosc', 'klib', 'poly']:
p = idx.plugins.get(pluginname)
if p is None:
logger.error(f"Plugin '{pluginname}' not found in risset's index")
logger.error(f"Plugin '{pluginname}' not in risset's index")
return False
elif idx.is_plugin_installed(p):
logger.debug(f"Plugin '{pluginname}' already installed, skipping")
Expand Down Expand Up @@ -280,26 +278,26 @@ def installPlugins(majorversion=6, risset=True) -> bool:
return True


def _checkDependencies(fix=False, updateState=True, quiet=False) -> Optional[str]:
def _checkDependencies(fix=False, quiet=False) -> Optional[str]:
"""
Either returns None or an error message
"""
if not csoundInstalled():
return "csound not installed. See https://csound.com/download.html"

version = csoundlib.getVersion(useApi=True)

if version < (6, 16, 0):
return f"Csound version ({version}) is too old, should be >= 6.16"

if version[0] >= 7:
print(f"WARNING: Csound 7 is not fully supported. Proceed at yout own risk")

binversion = csoundlib.getVersion(useApi=False)
if version[:2] != binversion[:2]:
print(f"WARNING: the csound library found reported a version {version}, different"
f" from the version reported by the csound binary {binversion}")

if not pluginsInstalled(cached=False):
# binversion = csoundlib.getVersion(useApi=False)
# if version[:2] != binversion[:2]:
# print(f"WARNING: the csound library found reported a version {version}, different"
# f" from the version reported by the csound binary {binversion}")
if not pluginsInstalled():
if fix:
print("** csoundengine: Csound external plugins are not installed or are too old."
" I will try to install them now")
Expand All @@ -310,13 +308,13 @@ def _checkDependencies(fix=False, updateState=True, quiet=False) -> Optional[str
print("** csoundengine: csound external plugins could not be installed")
return "csound external plugins could not be installed"
else:
return ("Some plugins are not installed. They can be installed via 'import csoundengine; csoundengine.installDependencies()'. "
return ("Some plugins are not installed. They can be installed via "
"'import csoundengine; csoundengine.installDependencies()'. "
"To install the plugins manually you will need risset installed. Install them via risset "
"(risset install \"*\"), or manually from "
"https://github.com/csound-plugins/csound-plugins/releases")
logger.info("Dependencies OK")
if updateState:
state['last_run'] = datetime.now().isoformat()
state['last_check'] = datetime.now().isoformat()


def installDependencies() -> bool:
Expand Down Expand Up @@ -349,16 +347,18 @@ def checkDependencies(force=False, fix=True) -> bool:
logger.debug("Called by sphinx? Skipping dependency check")
return True

timeSincelast_run = datetime.now() - datetime.fromisoformat(state['last_run'])
if force or timeSincelast_run.days > 30:
logger.warning("Checking dependencies")
okstatus = True
now = datetime.now()
timeSinceLastCheck = now - datetime.fromisoformat(state['last_check'])
if force or timeSinceLastCheck.days >= 30:
logger.info("Checking dependencies")
errormsg = _checkDependencies(fix=fix)
if errormsg:
logger.error(f"*** checkDependencies: {errormsg}")
if not fix:
logger.error("*** You can try to fix this by calling installDependencies()")
return False
return True
okstatus = False
return okstatus


def _codesignBinaries(binaries: list[str]) -> None:
Expand Down
4 changes: 1 addition & 3 deletions csoundengine/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def _isofmt(t:datetime) -> str:


_defaultState = {
'last_run': datetime(1900, 1, 1).isoformat(),
'last_check': datetime(1900, 1, 1).isoformat(),
'soundfont_last_dir': _home,
'soundfile_last_dir': _home,
'soundfile_save_last_dir': _home,
Expand Down Expand Up @@ -68,5 +68,3 @@ def openSoundfont(filter="Soundfont (*.sf2)", title="Open Soundfont", ensureSele
return out




2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def package_files(directory):
"bpf4>=1.10.1",
"numpyx>=1.3.3",
"pitchtools>=1.14.0",
"risset>=2.8.0",
"risset>=2.9.1",
"sounddevice"
],
license="BSD",
Expand Down

0 comments on commit a82a0ea

Please sign in to comment.