TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/csound/csound/llms.txt
Use this file to discover all available pages before exploring further.
ctcsound module provides Python bindings to the Csound C API using Python’s ctypes library.
Module initialization
Initialize the Csound library with specific flags.Parameters:
flags(int) - Initialization flags:CSOUNDINIT_NO_SIGNAL_HANDLER = 1CSOUNDINIT_NO_ATEXIT = 2
This function is called automatically by
Csound() constructor. You rarely need to call it explicitly.Csound class
The main class for interacting with Csound.Constructor
host_data- Optional data accessible from callbacksopcode_dir- Optional override for plugin directory searchpointer_- Optional existing Csound pointer (advanced use)
Attributes and properties
Get Csound version number.
Get sample rate (audio frames per second).
Get control rate (control samples per second).
Get audio vector size in frames (sr/kr).
Get number of audio channels.Parameters:
is_input(bool) - IfTrue, returnsnchnls_i, otherwisenchnls
Get 0dBFS level of audio buffers.
Get A4 frequency reference.
Get current performance time in sample frames.
Get size of MYFLT type in bytes.
Configuration
Set Csound command-line options.Must be called before compilation. Multiple options can be in one string.Returns: Zero on success.
Get current parameters into a
CsoundParams structure.Enable or disable debug messages.
Set message level (0-231).
Performance
Compile Csound input files.Returns: Non-zero on error.
Compile orchestra code from a string.Parameters:
orc(str) - Orchestra codeasync_(bool) - IfTrue, compile asynchronously
Evaluate code and return a value.
Compile a CSD file or string.Parameters:
csd(str) - Filename or CSD textmode(int) - 0 for file, 1 for text stringasync_(bool) - IfTrue, compile asynchronously
Prepare Csound for performance.Returns: Non-zero on error.
Process one control period (ksmps samples).Returns:
False during performance, True when finished.Reset Csound for a new performance.Clears all internal memory and state.
Run a Csound utility.Call
reset() after using utilities.Audio I/O
Get audio input buffer as NumPy array.Write to this buffer before calling
perform_ksmps().Get audio output buffer as NumPy array.Read from this buffer after calling
perform_ksmps().Disable default audio I/O handling.Use
spin() and spout() buffers directly after calling this.Set the real-time audio module.
Channels
Set a control channel value.
Get a control channel value.
Set an audio channel from NumPy array.
Get an audio channel into NumPy array.
Set a string channel.
Get a string channel value.
Get a pointer to a channel.Returns a NumPy array for control/audio channels.
List all allocated channels.
Lock a channel for thread-safe access.
Events
Send a score event.
Send score event(s) as a string.
Get instrument number from name.
Tables
Get function table as NumPy array.
Get function table length.
Get GEN arguments for a table.
Messages
Display an informational message.
Create a message buffer.
Device enumeration
Get list of audio devices.
Get list of MIDI devices.
Score handling
Get current score time in seconds.
Check if score events are being performed.
Enable/disable score event performance.
Rewind score to beginning.
CsoundPerformanceThread class
Runs Csound in a separate thread.Constructor
csound_pointer- Pointer fromcs.csound()
Methods
Start or continue performance.
Pause performance.
Toggle pause state.
Stop performance (cannot be continued).
Check if thread is running.
Get performance status.
Wait for performance to finish.
Send a score event from the thread.
Send score event string.
Start recording output to file.
Stop recording.
Data structures
CsoundParams
Configuration parameters structure with fields:debug_mode(int) - Debug flagsr_override(MYFLT) - Sample rate overridekr_override(MYFLT) - Control rate overrideksmps_override(int) - ksmps overridenchnls_override(int) - Number of channels overridemessage_level(int) - Message level (0-231)number_of_threads(int) - Thread count for multicore- And many more configuration fields…
ControlChannelHints
Hints for control channel GUI display:CsoundAudioDevice
Audio device information:device_name(str) - Device namedevice_id(str) - Device IDrt_module(str) - RT module namemax_nchnls(int) - Maximum channelsisOutput(int) - 1 if output device
CsoundMidiDevice
MIDI device information:device_name(str) - Device nameinterface_name(str) - Interface namedevice_id(str) - Device IDmidi_module(str) - MIDI module nameisOutput(int) - 1 if output device
Utility functions
Convert Python string to C string.
Convert C string to Python string.
Convert Python string to C char.