[Csnd] csoundengine

Hi,

As a part of an effort to make working with csound in python less painful I created csoundengine (), a python library built on top of ctcsound and offering many simplifications and less bureaucracy. Particularly if you are using python from within a jupyter notebook, csoundengine will use many of the display and interaction possibilities provided there to offer a more ergonomic experience.

An introduction and documentation can be found here:

Eduardo

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Looks great! But I could not pip install it on my Mac…

Richard

Could you post the terminal output together with os and python versions to ?

Thanks for trying it out!

Eduardo

Csound mailing list Send bugs reports to Discussions of bugs and features can be posted here

This is looking truly far out! It’s not that csound couldn’t do a lot of this anyway; but it looks to be so much easier to set up & control!

OS X 10.13.4

(base) RMA-4:~ richard$ pip install csoundengine
ERROR: Could not find a version that satisfies the requirement csoundengine (from versions: none)
ERROR: No matching distribution found for csoundengine

Python 3.10.2

Hello Eduardo,

I’m using Python 3.8.10 on Ubuntu 20.04. I get this error when importing csoundengine:

cannot import name ‘cache’ from ‘functools’

It seems that cache is a new feature of functools as of Python 3.9 only…

Regards

François

Thanks for the catch. Fixed both in git and pypi. Python 3.10 is not supported yet since some dependencies have a broken ci build for 3.10.

Csound mailing list Send bugs reports to Discussions of bugs and features can be posted here

I went back to Python 3.9.9, but I got this error:
SystemError: Cannot compile ‘Python.h’. Perhaps you need to install python-dev|python-devel.

Ok. Now I get an error about plugins. On my system, I build Csound 7 from sources and I build the plugins from the sources in https://github.com/csound/plugins as well. Does it mean that some other plugins are needed?

François

I did a brew reinstall python@3.9
But after that I got the same error with numpy.
It seems like installing python-dev requires Xcode to be installed, but I do not have that (requires too much HD space)

apt-get install python3.9-dev

Csound mailing list Send bugs reports to Discussions of bugs and features can be posted here

  1. csound 7 has not been released and is not supported

  2. can you post the error?

Csound mailing list Send bugs reports to Discussions of bugs and features can be posted here

import csoundengine as ce
Checking dependencies
end of score. overall amps: 0.0
overall samples out of range: 0
0 errors in performance
Elapsed time at end of performance: real: 0.003s, CPU: 0.003s
csound plugins are not installed or are too old. I will try to install them now
Traceback (most recent call last):
File “”, line 1, in
File “/usr/local/lib/python3.8/dist-packages/csoundengine/init.py”, line 98, in
ok = checkDependencies(force=False, tryfix=True)
File “/usr/local/lib/python3.8/dist-packages/csoundengine/dependencies.py”, line 279, in checkDependencies
errormsg = _checkDependencies(tryfix=tryfix)
File “/usr/local/lib/python3.8/dist-packages/csoundengine/dependencies.py”, line 251, in _checkDependencies
installPlugins()
File “/usr/local/lib/python3.8/dist-packages/csoundengine/dependencies.py”, line 226, in installPlugins
zipped = downloadLatestPluginForPlatform()
File “/usr/local/lib/python3.8/dist-packages/csoundengine/dependencies.py”, line 107, in downloadLatestPluginForPlatform
destFolder = _getDownloadsFolder()
File “/usr/local/lib/python3.8/dist-packages/csoundengine/dependencies.py”, line 164, in _getDownloadsFolder
assert downloads.exists()
AssertionError

On my system, plugins are here: /usr/local/lib/csound/plugins64-7.0

François

Thanks for the report. csoundengine checks that the external plugins are installed and if not attempts to install them. Here it attempted to download those plugins to your downloads folder but failed to find it

Update to latest version to see if this fixes it.

(pip install -U csoundengine)

Csound mailing list Send bugs reports to Discussions of bugs and features can be posted here

Mac has no apt-get, so I tried installing with brew, but I got:

Error: No formulae found in taps.

pip didn’t work with the -U option nor with --force-reinstall --no-cache-dir. I finally cloned your github repo and copied manually the files config.py and dependencies.py into /usr/local/lib/python3.8/dist-packages/csoundengine.

Then, when importing csoundengine from a python console, the extra plugins were downloaded into my local profile, but Csound 7 did not see them. I finally moved the plugins from my profile into /usr/local/lib/csound/plugins64-7.0/

The plugins loaded are:
libbeosc.so libjsfx.so libpathtools.so librisset.so
libelse.so libklib.so libpoly.so libsndmeta.so

And now here’s what I get:

~$ ipython
Python 3.8.10 (default, Nov 26 2021, 20:14:08)
Type ‘copyright’, ‘credits’ or ‘license’ for more information
IPython 7.27.0 – An enhanced Interactive Python. Type ‘?’ for help.

In [1]: import csoundengine as ce
csoundengine.magic extension loaded
Magics available: %csound, %%csound, %%definstr

In [2]:

Seems to work! Thank you

François

So now the command e = ce.Engine() returns an error:
CsoundError: Error compiling base ochestra, error: -1

The Csound 7 parser doesn’t read your base orchestra. I’ll wait a bit for csoundengine to work with Csound 7, as I don’t want to revert to Csound 6…

Regards

François

I don’t find any built-in midi interface… So I just import mido or something of the sort?

Regarding midi, you can have csound handle midi directly, or you can handle midi on the python side and use it to schedule/control instruments.

Regarding the first option, you can pass any options when creating an engine to configure midi as you would in csound. For example

>>> e = csoundengine.Engine(commandlineOptions=['-+rtmidi=portmidi', '-Ma'])
>>> e.compile(r'''
instr 1
  ...
endin
''')
>>> e.compile("massign 1, 1")

For the second option, you can use any python library to interface with live midi. I would recommend rtmidi2: ()

Csound mailing list Send bugs reports to Discussions of bugs and features can be posted here

Since my csound was out of date, I tried installing the latest version, got csound 7.0 running on ubuntu 20.04.

But that evidently doesn’t work for this. Suggestions?

On python 3.9, I do:

from csoundengine import Engine
and then

engine = Engine()
gets me:

error: syntax error, unexpected STRING_TOKEN, expecting T_IDENT or T_TYPED_IDENT (token “”") line 68:

<<<
Parsing failed due to invalid input!
Stopping on parser failure
Error compiling base orchestra. A copy of the orchestra has been saved to /tmp/csoundengine-jwvuyq7q.orc
001
002 sr = 48000
003 ksmps = 64
004 nchnls = 2


645 schedule “__businit”, 0, ksmps/sr
end of score. overall amps: 0.0
overall samples out of range: 0
0 errors in performance
Traceback (most recent call last):
File “”, line 1, in
File “/home/forrest/.local/lib/python3.9/site-packages/csoundengine/engine.py”, line 586, in init
self.start()
File “/home/forrest/.local/lib/python3.9/site-packages/csoundengine/engine.py”, line 847, in start
self._startCsound()
File “/home/forrest/.local/lib/python3.9/site-packages/csoundengine/engine.py”, line 766, in _startCsound
raise CsoundError(f"Error compiling base ochestra, error: {err}")
csoundengine.errors.CsoundError: Error compiling base ochestra, error: -1