Giter Site home page Giter Site logo

csound / ctcsound Goto Github PK

View Code? Open in Web Editor NEW
66.0 66.0 10.0 1.92 MB

Python Bindings for Csound using ctypes. Can be used from python2.x and python3.x as well.

License: GNU Lesser General Public License v2.1

Python 2.91% Jupyter Notebook 92.51% JavaScript 4.04% Csound Document 0.48% Csound 0.05% Csound Score 0.01%

ctcsound's Introduction

CSOUND

Version 7.0.0 (beta)

This is the the develop branch of the Csound main code repository. At the moment, we are developing the next main version (moving from 6.x to 7.0), and this branch reflects current work-in-progress. This is still undergoing changes and fixes until the first release, scheduled for September 2024. Anyone seeking the latest 6.x version please checkout the csound6 branch (or the master branch, containing the latest and final release of this version).

Build Status

A sound and music computing system.

Csound is copyright (c) 1991-2020 The Csound Developers, see CONTRIBUTORS

Csound is free software; you can redistribute them and/or modify them under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

Csound is distributed in the hope that they will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this software; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

GETTING STARTED

This repository contains the code for the core Csound library, the interfaces library, and the command-line interface frontend. It also contains specific code for ports to various embedded, mobile and web platforms.

For general project information, please look at http://csound.com, where all details about Csound, what it does, its history, music made with it, and many other things can be found.

The Csound Reference Manual can be found online at http://docs.csound.com.

The Csound API application programming interface reference may be found online at http://csound.github.io/docs/api/index.html.

Information on how to build Csound on various platforms is given in the BUILD.md file at the top level directory of this repository.

Information about build pipelines with Azure and Github actions is given in DockerFiles/Readme.md.

CONTRIBUTORS

Csound contains contributions from musicians, scientists, and programmers from around the world. They include (but are not limited to):

  • Allan Lee
  • Andres Cabrera
  • Anthony Kozar
  • Barry Vercoe
  • Bill Gardner
  • Bill Verplank
  • Dan Ellis
  • David Macintyre
  • Ed Costello
  • Eli Breder
  • Fabio P. Bertolotti
  • Felipe Sataler
  • François Pinot
  • Gabriel Maldonado
  • Greg Sullivan
  • Hans Mikelson
  • Henri Manson
  • Ian McCurdy
  • Istvan Varga
  • Jean Piché
  • Joachim Heintz
  • John Ramsdell
  • John ffitch
  • Marc Resibois
  • Mark Dolson
  • Matt Ingalls
  • Max Mathews
  • Michael Casey
  • Michael Clark
  • Michael Gogins
  • Mike Berry
  • Nate Whetsell
  • Paris Smaragdis
  • Perry Cook
  • Peter Neubäcker
  • Peter Nix
  • Rasmus Ekman
  • Richard Dobson
  • Richard Karpen
  • Rob Shaw
  • Robin Whittle
  • Rory Walsh
  • Sean Costello
  • Stephen Kyne
  • Steven Yi
  • Tito Latini
  • Tom Erbe
  • Victor Lazzarini
  • Ville Pulkki

ctcsound's People

Contributors

bmitc avatar fggp avatar joachimheintz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ctcsound's Issues

Can't import ctcsound

I have this code:

import ctcsound

c = ctcsound.Csound() # Create an instance of the Csound object
c.Compile('test1.csd') # Compile a pre-defined test1.csd file
c.Perform() # This call runs Csound to completion
c.Stop() # At this point, Csound is already stopped, but this call is here
# as it is something that you would generally call in real-world
# contexts

Using Python 3.5, whenever I run this code, or try to import ctcsound at all, I get this error message.

AttributeError Traceback (most recent call last)
in ()
----> 1 import ctcsound

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ctcsound.py in ()
214 libcsound.csoundGet0dBFS.restype = MYFLT
215 libcsound.csoundGet0dBFS.argtypes = [c_void_p]
--> 216 libcsound.csoundGetA4.restype = MYFLT
217 libcsound.csoundGetA4.argtypes = [c_void_p]
218 libcsound.csoundGetCurrentTimeSamples.restype = c_int64

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ctypes/init.py in getattr(self, name)
358 if name.startswith('') and name.endswith(''):
359 raise AttributeError(name)
--> 360 func = self.getitem(name)
361 setattr(self, name, func)
362 return func

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ctypes/init.py in getitem(self, name_or_ordinal)
363
364 def getitem(self, name_or_ordinal):
--> 365 func = self._FuncPtr((name_or_ordinal, self))
366 if not isinstance(name_or_ordinal, int):
367 func.name = name_or_ordinal

AttributeError: dlsym(0x10608b0e0, csoundGetA4): symbol not found


I've moved the ctcsound.py into my modules folder. Am I doing anything wrong?

Problem executing example #2 (02-performing.ipynb)

Hi,

Thank you for building this package!

I'm trying to run a code that is almost identical to the code on 02-performing.ipynb (I have the same issue with the original code):

import ctcsound
cs = ctcsound.Csound()

csd = '''
<CsoundSynthesizer>

<CsOptions>
  -o dac -m0
</CsOptions>

<CsInstruments>
sr     = 48000
ksmps  = 100
nchnls = 2
0dbfs  = 1

instr 1
idur      =         p3
iamp      =         p4
icps      =         cpspch(p5)
irise     =         p6
idec      =         p7
ipan      =         p8
 
kenv      linen     iamp, irise, idur, idec
kenv      =         kenv*kenv
asig      poscil    kenv, icps
a1, a2    pan2      asig, ipan
          outs      a1, a2
          endin
</CsInstruments>

<CsScore>
f 0 14400    ; a 4 hours session should be enough

i 1 1 1 0.5 7.06 0.05 0.3 0.5
;e 1.5

</CsScore>
</CsoundSynthesizer>
'''


print csd
ret = cs.compileCsdText(csd)
if ret == ctcsound.CSOUND_SUCCESS:
	cs.start()
	cs.perform()
	cs.reset()

pt = ctcsound.CsoundPerformanceThread(cs.csound())
pt.play()

pt.scoreEvent(False, 'i', (1, 0, 2, 0.5, 8.06, 0.05, 0.3, 0.5))
pt.stop()
pt.join()

del cs

The problem is that I heard the 'hardcoded' note i 1 1 1 0.5 7.06 0.05 0.3 0.5, but I think that I don't get to add another scoreEvent (False, 'i', (1, 0, 2, 0.5, 8.06, 0.05, 0.3, 0.5)), and therefore, I don't hear it.

My setup is:

  • Python 2.7.12
  • Csound 6.08
  • Mac OS X 10.12.1

ct.CDLL("CsoundLib64.framework/CsoundLib64") fails

Hi I cant get csound to process a file using ctcsound.py.

I installed the latest version of Csound for mac, my csound version is: --Csound version 6.15 (double samples) Nov 20 2020

My Csound lib is installed in: /Library/Frameworks/CsoundLib64.framework/Versions/6.0/CsoundLib64

My ctcsound.py is installed in: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ctcsound.py

When I run my script

$ python3.9 -m musx_demos.musx-csound-demo,  it works upto line 47:

libcsound = ct.CDLL("CsoundLib64.framework/CsoundLib64")

and then it cant actually load the library. I have no idea how to fix this problem, any advice appreciated!

Here is Python’s stack trace:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/taube/Classes/mus499mrc/Sources/musx_demos/musx-csound-demo.py", line 19, in
import ctcsound
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ctcsound.py", line 47, in
libcsound = ct.CDLL("CsoundLib64.framework/CsoundLib64")
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/init.py", line 374, in init
self._handle = _dlopen(self._name, mode)
OSError: dlopen(CsoundLib64.framework/CsoundLib64, 6): image not found

Rick Taube


Chair, Composition/Theory
School of Music
University of Illinois Urbana-Champaign
Email: [email protected]
President, Illiac Software Inc.
https://harmonia.illiacsoftware.com/
Email: [email protected]

libcsound64.so not found

Hello everybody,

when I try to import the ctcsound module in a python3 interpreter, I got the following error message:

import ctcsound

OSError: libcsound64.so: cannot open shared object file: No such file or directory

I use Ubuntu 17.10 64 bit Version and I have a installed Csound version 6.09.1 (double samples) (installed via apt-get) on my computer.

I tried to import the ctcsound module, which I cloned from this Github repository. The shell doesn't find the libcsound64.so - file neither:

find / libcsound64.so

find: ‘libcsound64.so’: No such file or directory

Do I have to install Csound differently?

Error when I import ctcsound in Python 3 on Windows 10

I get the error below when I try and import ctcsound in a python 3 interactive shell:

C:\Users\jjhes>py
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctcsound
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Csound6_x64\bin\ctcsound.py", line 41, in <module>
    libcsound = cdll.csound64
  File "C:\Users\jjhes\AppData\Local\Programs\Python\Python38\lib\ctypes\__init__.py", line 439, in __getattr__
    dll = self._dlltype(name)
  File "C:\Users\jjhes\AppData\Local\Programs\Python\Python38\lib\ctypes\__init__.py", line 369, in __init__
    self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'csound64'. Try using the full path with constructor syntax.
>>>

I'm guessing the class syntax is CDLL(object) as defined in jjhes\AppData\...\ctypes\__init__.py, and the target is Program Files\Csound6_x64\bin\csound64.dll but I'm not sure, and I haven't had any luck getting this to run.

Any suggestions? I'm not too experienced with Windows or how wrapping C libraries in Python works.

add a setup.py

It would be convenient to have a setup.py to install ctcsound as a normal package. A minimal setup.py would consist of

from setuptools import setup

classifiers = """
Topic :: Multimedia :: Sound/Audio
Programming Language :: Python :: 2
Programming Language :: Python :: 3
"""

setup(name='ctcsound',
      version='0.0.1',
      description='Python bindings to the Csound API using ctypes', 
      classifiers=filter(None, classifiers.split('\n')),
      author='Name Surname',
      py_modules=['ctcsound'],
)

Project structure: add ctsound.py?

Hi,

Very nice work! I'm glad I can use csound in python scripts and tune my algorithms. It's very useful to tune my transient shaper.

I find the install process a bit sketchy because you have to manually add ctsound.py from the csound repo. I suggest that this repo becomes "installable", and includes ctsound.py. In the end, you could just add ctsound on any python project by using pip install ctsound.

Here are the issues:

  • There is a csound external dependency that can't be installed with pip. However, I'm sure it's not a problem.
    ffmpeg-python use the same principle and works well: https://github.com/kkroening/ffmpeg-python#installing-ffmpeg
  • Each ctsound.py file is linked to a csound version. I'm not sure what's the best way to handle it.

If you find this idea interesting we could discuss it together, I would be glad to contribute! In the meantime I will create a private repo for my projects.

Julien

notebook has no attribute DEFAULT_STATIC_FILES_PATH

I had problem installing csoundmagics to my Ubuntu 22.04 system.
The lines

# Copy csound mode in codemirror
dest = os.path.join(notebook.DEFAULT_STATIC_FILES_PATH, "components", "codemirror", "mode", "csound")
if not os.path.exists(dest):
    os.mkdir(dest)
shutil.copy("csound.js", dest)

created an error because notebook has no attribute DEFAULT_STATIC_FILES_PATH

I manually found the correct location to copy csound.js which proved to be:
.../site-packages/nbclassic/static/components/codemirror/mode and create manually the directory csound in order to copy csound.js file.

In the end, I managed to install and run csoundmagics!

PerformanceThread

Hi Francois!

I'm Eugene from the mailing list. How do you plan to proceed with running Csound in the separate thread? That's currently the main thing that concerns me. Maybe Mike's idea with creating a wrapper for C++ class was good, what do you think?

Best,
Eugene

In case there's interest, I'm developing a cython csound wrapper: cycsound

Hi, In case this is useful somehow, I started work on a cython wrapper for the csound.h api a little while ago called cycsound.

It's still early stage, but so far it wraps a small subset of the api with audio output. It compiles (dynamic linking) on macOS, windows, and linux, with full static linking on macOS, which means it can currently generate a self-contained 2MB python wheel for macOS (which was my initial driver to start this project).

Reading the excellent ctcsound.py source has been enormously helpful and I've been using it as a development guide.

I'll keep chipping away... it helps me to learn csound, but any feedback would be welcome (-:

How to sync audio playback start with my GUI step sequencer

I'm writing a simple music tracker in Python 3 that uses Csound as its audio engine, and interacts with it through ctcsound.

My main sequencer class is SongSequencer. It has a toggle_playing method that converts the program's phrase and instrument data structures into a string in .csd format. Then I use a CsoundPerformanceThread to play the audio for that in a seperate thread. My problem is that there is delay of a second or two before Csound starts actually playing the audio back, which prevents me from syncing the current step indicator in my GUI to where the audio is in the score. Are there any callback methods I can use to sync my GUI and the audio playback?

I tried using the setRtPlayCallback method but couldn't get it to do anything.

The abbreviated code of my program looks like this:

class SongSequencer:
    def __init__(self):
        #...
        self.cs = ctcsound.Csound()
        self.pt = ctcsound.CsoundPerformanceThread( self.cs.csound() )

    def toggle_playing(self, cursor_step=0):
        if self.pt.status() != 0:
            self.pt.stop()
            self.pt.join()
            self.cs.reset()
            self.pt = ctcsound.CsoundPerformanceThread( self.cs.csound() )
            self.pt.setProcessCB(self.audio_start_cb)

        channels_phrases = [[], [], [], []]
        # Add contiguous filled phrase sequences in current channel, starting at current
        # cursor step. When I find an empty phrase sequence, exit loop
        for ch_i in range(0,4):
            for psq in self.sequence[ch_i][cursor_step:]:
                if not psq:
                    break
                channels_phrases[ch_i].append(psq.phrase.steps)

        csd = phrases_to_csd(self.instruments, channels_phrases)
        ret = self.cs.compileCsdText(csd)
        if ret == ctcsound.CSOUND_SUCCESS:
            self.cs.start()
            self.cs.setPlayOpenCallback(self.audio_start_cb)
            self.pt.play()


    def audio_start_cb(self):
        print('AUDIO PLAYING NOW')
        print('AUDIO PLAYING NOW')
        print('AUDIO PLAYING NOW')

ctcsound.py packaged with v6.16.2 exceptions on import under OSX

  • The latest download from https://csound.com/download.html is v6.16.2
  • ctcsound.py packaged with v6.16.2 imports without exception on Windows 10, and appears stable
  • On multiple OSX machines ctcsound.py packaged with v6.16.2 exceptions on import.
    Here's an example:

Python 3.8.8 (default, Apr 13 2021, 12:59:45)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
import ctcsound
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/CsoundLib64.framework/Resources/Python/Current/ctcsound.py", line 2705, in
libcspt.NewCsoundPT.restype = ct.c_void_p
File "/opt/anaconda3/lib/python3.8/ctypes/init.py", line 394, in getattr
func = self.getitem(name)
File "/opt/anaconda3/lib/python3.8/ctypes/init.py", line 399, in getitem
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(RTLD_DEFAULT, NewCsoundPT): symbol not found

  • Replacing "/Library/Frameworks/CsoundLib64.framework/Resources/Python/Current/ctcsound.py"
    with the version released as 6.16.1 as referenced at:
    https://csound.com/site/news/2021/07/11/Csound-6.16
    which refers to version is 6.16.1
    does not exception on import on all the OSX machines.

import ctcsound fails

When I try to import ctcsound, I get the following error:

Traceback (most recent call last):
  File "c:\Users\USER\Documents\CSound\send_code.py", line 1, in <module>
    import ctcsound
  File "C:\Users\USER\Documents\CSound\osc_test\Lib\site-packages\ctcsound.py", line 2699, in <module>      
    libcspt = ct.CDLL(ctypes.util.find_library("csnd6"))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\ctypes\__init__.py", line 366, in __init__
    if '/' in name or '\\' in name:
       ^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not iterable

I am using a venv with nothing but ctcsound.py, python-osc and numpy.

Where is ctcsound.py installed in csound directory?

Hi, I'm trying to use ctcsound on a raspberry pi, where I installed csound via apt-get. I have checked that my csound version is recent enough (6.08). When I try to run a basic ctcsound test I get the following error:

Traceback (most recent call last):
File "ctctest.py", line 2, in
import ctcsound
ImportError: No module named ctcsound

I realize this is because the path to ctcsound is not in my module paths. I could fix this easily, but I don't know where ctcsound.py got installed. Can someone answer that for me? Looking around directories is a bit of a wild goose chase. This information might be worth including in the readme.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.